mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
Merge pull request #100 from DeepDoge/master
Browser's uri dialog was causing confusion sometimes
This commit is contained in:
commit
4a23670e4d
1 changed files with 31 additions and 20 deletions
|
@ -51,26 +51,6 @@ function updateButton(mountPoint: HTMLDivElement, target: Target | null): void {
|
||||||
render(<WatchOnLbryButton targetPlatform={target.platfrom} lbryPathname={target.lbryPathname} time={target.time ?? undefined} />, mountPoint)
|
render(<WatchOnLbryButton targetPlatform={target.platfrom} lbryPathname={target.lbryPathname} time={target.time ?? undefined} />, mountPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function redirectTo({ lbryPathname, platfrom, time }: Target) {
|
|
||||||
const url = new URL(`${platfrom.domainPrefix}${lbryPathname}`)
|
|
||||||
|
|
||||||
if (time) url.searchParams.set('t', time.toFixed(0))
|
|
||||||
|
|
||||||
findVideoElement().then((videoElement) => {
|
|
||||||
videoElement.addEventListener('play', () => videoElement.pause(), { once: true })
|
|
||||||
videoElement.pause()
|
|
||||||
})
|
|
||||||
|
|
||||||
if (platfrom === targetPlatformSettings.app) {
|
|
||||||
if (document.hidden) await new Promise((resolve) => document.addEventListener('visibilitychange', resolve, { once: true }))
|
|
||||||
open(url, '_blank')
|
|
||||||
if (window.history.length === 1) window.close()
|
|
||||||
else window.history.back()
|
|
||||||
}
|
|
||||||
else
|
|
||||||
location.replace(url.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns a mount point for the button */
|
/** Returns a mount point for the button */
|
||||||
async function findButtonMountPoint(): Promise<HTMLDivElement> {
|
async function findButtonMountPoint(): Promise<HTMLDivElement> {
|
||||||
const id = 'watch-on-lbry-button-container'
|
const id = 'watch-on-lbry-button-container'
|
||||||
|
@ -134,6 +114,37 @@ async function requestLbryPathname(videoId: string) {
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function redirectTo({ lbryPathname, platfrom, time }: Target) {
|
||||||
|
const url = new URL(`${platfrom.domainPrefix}${lbryPathname}`)
|
||||||
|
|
||||||
|
if (time) url.searchParams.set('t', time.toFixed(0))
|
||||||
|
|
||||||
|
findVideoElement().then((videoElement) => {
|
||||||
|
videoElement.addEventListener('play', () => videoElement.pause(), { once: true })
|
||||||
|
videoElement.pause()
|
||||||
|
})
|
||||||
|
|
||||||
|
if (platfrom === targetPlatformSettings.app) {
|
||||||
|
if (document.hidden) await new Promise((resolve) => document.addEventListener('visibilitychange', resolve, { once: true }))
|
||||||
|
|
||||||
|
// On redirect with app, people might choose to cancel browser's dialog
|
||||||
|
// So we dont destroy the current window automatically for them
|
||||||
|
// And also we are keeping the same window for less distiraction
|
||||||
|
if (settings.redirect)
|
||||||
|
{
|
||||||
|
location.replace(url.toString())
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
open(url.toString(), '_blank')
|
||||||
|
if (window.history.length === 1) window.close()
|
||||||
|
else window.history.back()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
location.replace(url.toString())
|
||||||
|
}
|
||||||
|
|
||||||
let removeVideoTimeUpdateListener: (() => void) | null = null
|
let removeVideoTimeUpdateListener: (() => void) | null = null
|
||||||
async function onModeChange() {
|
async function onModeChange() {
|
||||||
let target: Target | null = null
|
let target: Target | null = null
|
||||||
|
|
Loading…
Add table
Reference in a new issue