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;
logger: Logger;
eventBus: EventBus;
isIframe: boolean = false;
commsHandlers: {
[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(){
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);

View File

@ -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);

View File

@ -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'){

View File

@ -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

View File

@ -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}`;

View File

@ -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