From 65da51585478d1b4efde5a1e5028900fbff7a301 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Wed, 29 Mar 2023 22:07:50 +0200 Subject: [PATCH] various fixes --- src/ext/UWContent.ts | 35 ++++++------------------- src/ext/lib/video-data/IframeManager.ts | 3 +-- src/ext/lib/video-data/PageInfo.ts | 33 +++++++++++++---------- src/ext/lib/video-data/PlayerData.ts | 13 ++++----- src/ext/lib/video-data/VideoData.ts | 13 ++++++--- src/ext/lib/video-transform/Resizer.ts | 4 +-- 6 files changed, 45 insertions(+), 56 deletions(-) diff --git a/src/ext/UWContent.ts b/src/ext/UWContent.ts index ec5153e..ff10a1e 100644 --- a/src/ext/UWContent.ts +++ b/src/ext/UWContent.ts @@ -18,40 +18,15 @@ export default class UWContent { keyboardHandler: KeyboardHandler; logger: Logger; eventBus: EventBus; + isIframe: boolean = false; commsHandlers: { [x: string]: ((a: any, b?: any) => void | Promise)[] } = { - // THIS SHOULD BE MIGRATED TO EVENT BUS - // 'get-current-zoom': [() => this.pageInfo.requestCurrentZoom()], - // 'set-ar': [(message) => this.pageInfo.setAr({type: message.arg, ratio: message.customArg}, message.playing)], - // 'set-alignment': [(message) => { - // this.pageInfo.setVideoAlignment(message.arg, message.playing); - // this.pageInfo.restoreAr(); - // }], - // 'set-stretch': [(message) => this.pageInfo.setStretchMode(message.arg, message.playing, message.customArg)], - // 'set-keyboard': [(message) => this.pageInfo.setKeyboardShortcutsEnabled(message.arg)], - // DEPRECATED — should be set with resizer.setAr() - // 'autoar-start': [(message) => { - // if (message.enabled !== false) { - // this.pageInfo.initArDetection(message.playing); - // this.pageInfo.startArDetection(message.playing); - // } else { - // this.pageInfo.stopArDetection(message.playing); - // } - // }], - // 'pause-processing': [(message) => this.pageInfo.pauseProcessing(message.playing)], - // 'resume-processing': [(message) => this.pageInfo.resumeProcessing(message.autoArStatus, message.playing)], - // 'set-zoom': [(message) => this.pageInfo.setZoom(message.arg, true, message.playing)], - // 'change-zoom': [(message) => this.pageInfo.zoomStep(message.arg, message.playing)], - // 'mark-player': [(message) => this.pageInfo.markPlayer(message.name, message.color)], - // 'unmark-player': [() => this.pageInfo.unmarkPlayer()], - // 'autoar-set-manual-tick': [(message) => this.pageInfo.setManualTick(message.arg)], - // 'autoar-tick': [() => this.pageInfo.tick()], - // 'set-ar-persistence': [(message) => this.pageInfo.setArPersistence(message.arg)], } constructor(){ + this.isIframe = window.self !== window.top } reloadSettings() { @@ -102,6 +77,12 @@ export default class UWContent { function: () => this.initPhase2() } ); + this.eventBus.subscribe( + 'uw-show-ui', + { + function: () => {} + } + ); this.comms = new CommsClient('content-main-port', this.logger, this.eventBus); this.eventBus.setComms(this.comms); diff --git a/src/ext/lib/video-data/IframeManager.ts b/src/ext/lib/video-data/IframeManager.ts index ff4b45c..11d96dc 100644 --- a/src/ext/lib/video-data/IframeManager.ts +++ b/src/ext/lib/video-data/IframeManager.ts @@ -18,7 +18,6 @@ export type IframeData = { } export type IframeManagerConfiguration = { - isIframe: boolean eventBus: EventBus, } @@ -33,7 +32,7 @@ export default class IframeManager { constructor(config: IframeManagerConfiguration) { this.eventBus = config.eventBus; - this.isIframe = config.isIframe; + this.isIframe = window.self !== window.top; if (this.isIframe) { window.addEventListener('beforeunload', this.destroy); diff --git a/src/ext/lib/video-data/PageInfo.ts b/src/ext/lib/video-data/PageInfo.ts index 6bb10bd..ba83dfb 100644 --- a/src/ext/lib/video-data/PageInfo.ts +++ b/src/ext/lib/video-data/PageInfo.ts @@ -9,6 +9,7 @@ import ExtensionMode from '../../../common/enums/ExtensionMode.enum'; import CommsClient from '../comms/CommsClient'; import EventBus from '../EventBus'; import { SiteSettings } from '../settings/SiteSettings'; +import IframeManager from './IframeManager'; if (process.env.CHANNEL !== 'stable'){ console.info("Loading PageInfo"); @@ -57,6 +58,7 @@ class PageInfo { comms: CommsClient; eventBus: EventBus; videos: {videoData: VideoData, element: HTMLVideoElement}[] = []; + iframeManager: IframeManager; //#endregion //#region misc stuff @@ -78,6 +80,7 @@ class PageInfo { this.readOnly = readOnly; this.isFullscreen = !!document.fullscreenElement; + this.iframeManager = new IframeManager({eventBus}); if (eventBus){ this.eventBus = eventBus; @@ -121,19 +124,6 @@ class PageInfo { } } - /** - * Handler for fullscreenchanged event. - */ - fullscreenHandler() { - this.isFullscreen = !!document.fullscreenElement; - - if (this.isFullscreen) { - this.enterFullscreen(); - } else { - this.exitFullscreen(); - } - } - /** * Runs when browser enters full screen. */ @@ -148,6 +138,19 @@ class PageInfo { this.eventBus.send('page-fs-exit', {}); } + /** + * Handler for fullscreenchanged event. + */ + fullscreenHandler() { + this.isFullscreen = !!document.fullscreenElement; + + if (this.isFullscreen) { + this.enterFullscreen(); + } else { + this.exitFullscreen(); + } + } + reset() { for(let video of this.videos) { video.videoData.destroy(); @@ -247,7 +250,7 @@ class PageInfo { this.logger.log('info', 'videoRescan', "[PageInfo::rescan] found new video candidate:", videoElement, "NOTE:: Video initialization starts here:\n--------------------------------\n") try { - const newVideo = new VideoData(videoElement, this.siteSettings, this); + const newVideo = new VideoData(videoElement, this.settings, this.siteSettings, this); this.videos.push({videoData: newVideo, element: videoElement}); } catch (e) { this.logger.log('error', 'debug', "rescan error: failed to initialize videoData. Skipping this video.",e); @@ -376,6 +379,8 @@ class PageInfo { this.siteSettings.updatePersistentOption('crop', ar); } + + } if (process.env.CHANNEL !== 'stable'){ diff --git a/src/ext/lib/video-data/PlayerData.ts b/src/ext/lib/video-data/PlayerData.ts index 1d6815a..514dbd9 100644 --- a/src/ext/lib/video-data/PlayerData.ts +++ b/src/ext/lib/video-data/PlayerData.ts @@ -109,7 +109,6 @@ class PlayerData { this.video = videoData.video; this.siteSettings = videoData.siteSettings; this.eventBus = videoData.eventBus; - this.extensionMode = videoData.extensionMode; this.invalid = false; this.element = this.getPlayer(); this.initEventBus(); @@ -134,9 +133,8 @@ class PlayerData { return; } - if (this.extensionMode === ExtensionMode.Enabled) { - this.trackDimensionChanges(); - } + + this.trackDimensionChanges(); this.startChangeDetection(); } catch (e) { @@ -200,9 +198,8 @@ class PlayerData { // if dimensions of the player box are the same as the last known // dimensions, we don't have to do anything if ( - this.dimensions - && this.dimensions.width == currentPlayerDimensions.width - && this.dimensions.height == currentPlayerDimensions.height + this.dimensions?.width == currentPlayerDimensions.width + && this.dimensions?.height == currentPlayerDimensions.height ) { this.dimensions = currentPlayerDimensions; return; @@ -321,7 +318,7 @@ class PlayerData { if (BrowserDetect.firefox) { this.observer = new ResizeObserver( _.debounce( // don't do this too much: - this.onPlayerDimensionsChanged, + () => this.onPlayerDimensionsChanged, 250, // do it once per this many ms { leading: true, // do it when we call this fallback first diff --git a/src/ext/lib/video-data/VideoData.ts b/src/ext/lib/video-data/VideoData.ts index d051963..ef0783c 100644 --- a/src/ext/lib/video-data/VideoData.ts +++ b/src/ext/lib/video-data/VideoData.ts @@ -46,7 +46,6 @@ class VideoData { attributeFilter: ['class', 'style'], attributeOldValue: true, }; - extensionMode: any; userCssClassName: string; validationId: number; dimensions: any; @@ -55,6 +54,7 @@ class VideoData { //#region helper objects logger: Logger; + settings: Settings; // AARD needs it siteSettings: SiteSettings; pageInfo: PageInfo; player: PlayerData; @@ -73,14 +73,21 @@ class VideoData { } } - constructor(video, siteSettings: SiteSettings, pageInfo){ + /** + * Creates new VideoData object + * @param video + * @param settings NEEDED FOR AARD + * @param siteSettings + * @param pageInfo + */ + constructor(video, settings: Settings, siteSettings: SiteSettings, pageInfo: PageInfo){ this.logger = pageInfo.logger; this.arSetupComplete = false; this.video = video; this.destroyed = false; + this.settings = settings; this.siteSettings = siteSettings; this.pageInfo = pageInfo; - this.extensionMode = pageInfo.extensionMode; this.videoStatusOk = false; this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`; diff --git a/src/ext/lib/video-transform/Resizer.ts b/src/ext/lib/video-transform/Resizer.ts index 76eff8c..e54931c 100644 --- a/src/ext/lib/video-transform/Resizer.ts +++ b/src/ext/lib/video-transform/Resizer.ts @@ -225,10 +225,10 @@ class Resizer { // handle autodetection stuff if (ar.type === AspectRatioType.Automatic) { - this.conf.arDetector.start(); + this.conf.arDetector?.start(); return; } else if (ar.type !== AspectRatioType.AutomaticUpdate) { - this.conf.arDetector.stop(); + this.conf.arDetector?.stop(); } // unless we're trying to reset aspect ratio, we need to tell VideoData that this would