various fixes

This commit is contained in:
Tamius Han 2023-03-29 22:07:50 +02:00
parent e9bd3154a5
commit 65da515854
6 changed files with 45 additions and 56 deletions

View File

@ -18,40 +18,15 @@ export default class UWContent {
keyboardHandler: KeyboardHandler; keyboardHandler: KeyboardHandler;
logger: Logger; logger: Logger;
eventBus: EventBus; eventBus: EventBus;
isIframe: boolean = false;
commsHandlers: { commsHandlers: {
[x: string]: ((a: any, b?: any) => void | Promise<void>)[] [x: string]: ((a: any, b?: any) => void | Promise<void>)[]
} = { } = {
// 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(){ constructor(){
this.isIframe = window.self !== window.top
} }
reloadSettings() { reloadSettings() {
@ -102,6 +77,12 @@ export default class UWContent {
function: () => this.initPhase2() function: () => this.initPhase2()
} }
); );
this.eventBus.subscribe(
'uw-show-ui',
{
function: () => {}
}
);
this.comms = new CommsClient('content-main-port', this.logger, this.eventBus); this.comms = new CommsClient('content-main-port', this.logger, this.eventBus);
this.eventBus.setComms(this.comms); this.eventBus.setComms(this.comms);

View File

@ -18,7 +18,6 @@ export type IframeData = {
} }
export type IframeManagerConfiguration = { export type IframeManagerConfiguration = {
isIframe: boolean
eventBus: EventBus, eventBus: EventBus,
} }
@ -33,7 +32,7 @@ export default class IframeManager {
constructor(config: IframeManagerConfiguration) { constructor(config: IframeManagerConfiguration) {
this.eventBus = config.eventBus; this.eventBus = config.eventBus;
this.isIframe = config.isIframe; this.isIframe = window.self !== window.top;
if (this.isIframe) { if (this.isIframe) {
window.addEventListener('beforeunload', this.destroy); window.addEventListener('beforeunload', this.destroy);

View File

@ -9,6 +9,7 @@ import ExtensionMode from '../../../common/enums/ExtensionMode.enum';
import CommsClient from '../comms/CommsClient'; import CommsClient from '../comms/CommsClient';
import EventBus from '../EventBus'; import EventBus from '../EventBus';
import { SiteSettings } from '../settings/SiteSettings'; import { SiteSettings } from '../settings/SiteSettings';
import IframeManager from './IframeManager';
if (process.env.CHANNEL !== 'stable'){ if (process.env.CHANNEL !== 'stable'){
console.info("Loading PageInfo"); console.info("Loading PageInfo");
@ -57,6 +58,7 @@ class PageInfo {
comms: CommsClient; comms: CommsClient;
eventBus: EventBus; eventBus: EventBus;
videos: {videoData: VideoData, element: HTMLVideoElement}[] = []; videos: {videoData: VideoData, element: HTMLVideoElement}[] = [];
iframeManager: IframeManager;
//#endregion //#endregion
//#region misc stuff //#region misc stuff
@ -78,6 +80,7 @@ class PageInfo {
this.readOnly = readOnly; this.readOnly = readOnly;
this.isFullscreen = !!document.fullscreenElement; this.isFullscreen = !!document.fullscreenElement;
this.iframeManager = new IframeManager({eventBus});
if (eventBus){ if (eventBus){
this.eventBus = 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. * Runs when browser enters full screen.
*/ */
@ -148,6 +138,19 @@ class PageInfo {
this.eventBus.send('page-fs-exit', {}); this.eventBus.send('page-fs-exit', {});
} }
/**
* Handler for fullscreenchanged event.
*/
fullscreenHandler() {
this.isFullscreen = !!document.fullscreenElement;
if (this.isFullscreen) {
this.enterFullscreen();
} else {
this.exitFullscreen();
}
}
reset() { reset() {
for(let video of this.videos) { for(let video of this.videos) {
video.videoData.destroy(); 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") this.logger.log('info', 'videoRescan', "[PageInfo::rescan] found new video candidate:", videoElement, "NOTE:: Video initialization starts here:\n--------------------------------\n")
try { 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}); this.videos.push({videoData: newVideo, element: videoElement});
} catch (e) { } catch (e) {
this.logger.log('error', 'debug', "rescan error: failed to initialize videoData. Skipping this video.",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); this.siteSettings.updatePersistentOption('crop', ar);
} }
} }
if (process.env.CHANNEL !== 'stable'){ if (process.env.CHANNEL !== 'stable'){

View File

@ -109,7 +109,6 @@ class PlayerData {
this.video = videoData.video; this.video = videoData.video;
this.siteSettings = videoData.siteSettings; this.siteSettings = videoData.siteSettings;
this.eventBus = videoData.eventBus; this.eventBus = videoData.eventBus;
this.extensionMode = videoData.extensionMode;
this.invalid = false; this.invalid = false;
this.element = this.getPlayer(); this.element = this.getPlayer();
this.initEventBus(); this.initEventBus();
@ -134,9 +133,8 @@ class PlayerData {
return; return;
} }
if (this.extensionMode === ExtensionMode.Enabled) {
this.trackDimensionChanges(); this.trackDimensionChanges();
}
this.startChangeDetection(); this.startChangeDetection();
} catch (e) { } catch (e) {
@ -200,9 +198,8 @@ class PlayerData {
// if dimensions of the player box are the same as the last known // if dimensions of the player box are the same as the last known
// dimensions, we don't have to do anything // dimensions, we don't have to do anything
if ( if (
this.dimensions this.dimensions?.width == currentPlayerDimensions.width
&& this.dimensions.width == currentPlayerDimensions.width && this.dimensions?.height == currentPlayerDimensions.height
&& this.dimensions.height == currentPlayerDimensions.height
) { ) {
this.dimensions = currentPlayerDimensions; this.dimensions = currentPlayerDimensions;
return; return;
@ -321,7 +318,7 @@ class PlayerData {
if (BrowserDetect.firefox) { if (BrowserDetect.firefox) {
this.observer = new ResizeObserver( this.observer = new ResizeObserver(
_.debounce( // don't do this too much: _.debounce( // don't do this too much:
this.onPlayerDimensionsChanged, () => this.onPlayerDimensionsChanged,
250, // do it once per this many ms 250, // do it once per this many ms
{ {
leading: true, // do it when we call this fallback first leading: true, // do it when we call this fallback first

View File

@ -46,7 +46,6 @@ class VideoData {
attributeFilter: ['class', 'style'], attributeFilter: ['class', 'style'],
attributeOldValue: true, attributeOldValue: true,
}; };
extensionMode: any;
userCssClassName: string; userCssClassName: string;
validationId: number; validationId: number;
dimensions: any; dimensions: any;
@ -55,6 +54,7 @@ class VideoData {
//#region helper objects //#region helper objects
logger: Logger; logger: Logger;
settings: Settings; // AARD needs it
siteSettings: SiteSettings; siteSettings: SiteSettings;
pageInfo: PageInfo; pageInfo: PageInfo;
player: PlayerData; 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.logger = pageInfo.logger;
this.arSetupComplete = false; this.arSetupComplete = false;
this.video = video; this.video = video;
this.destroyed = false; this.destroyed = false;
this.settings = settings;
this.siteSettings = siteSettings; this.siteSettings = siteSettings;
this.pageInfo = pageInfo; this.pageInfo = pageInfo;
this.extensionMode = pageInfo.extensionMode;
this.videoStatusOk = false; this.videoStatusOk = false;
this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`; this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`;

View File

@ -225,10 +225,10 @@ class Resizer {
// handle autodetection stuff // handle autodetection stuff
if (ar.type === AspectRatioType.Automatic) { if (ar.type === AspectRatioType.Automatic) {
this.conf.arDetector.start(); this.conf.arDetector?.start();
return; return;
} else if (ar.type !== AspectRatioType.AutomaticUpdate) { } 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 // unless we're trying to reset aspect ratio, we need to tell VideoData that this would