detect whether extension is enabled on dimension changes. Trigger dimension check on fullscreen change

This commit is contained in:
Tamius Han 2023-04-16 02:43:50 +02:00
parent 085bd4aab9
commit be4bf9e2a3

View File

@ -96,6 +96,9 @@ class PlayerData {
if (this.isFullscreen) { if (this.isFullscreen) {
return window.innerWidth / window.innerHeight; return window.innerWidth / window.innerHeight;
} }
if (!this.dimensions) {
this.trackDimensionChanges();
}
return this.dimensions.width / this.dimensions.height; return this.dimensions.width / this.dimensions.height;
} catch (e) { } catch (e) {
@ -140,9 +143,10 @@ class PlayerData {
return; return;
} }
this.trackDimensionChanges(); this.trackDimensionChanges();
this.startChangeDetection(); this.startChangeDetection();
document.addEventListener('fullscreenchange', this.trackDimensionChanges);
} catch (e) { } catch (e) {
console.error('[Ultrawidify::PlayerData::ctor] There was an error setting up player data. You should be never seeing this message. Error:', e); console.error('[Ultrawidify::PlayerData::ctor] There was an error setting up player data. You should be never seeing this message. Error:', e);
this.invalid = true; this.invalid = true;
@ -158,6 +162,7 @@ class PlayerData {
} }
destroy() { destroy() {
document.removeEventListener('fullscreenchange', this.trackDimensionChanges);
this.stopChangeDetection(); this.stopChangeDetection();
this.destroyOverlay(); this.destroyOverlay();
this.notificationService?.destroy(); this.notificationService?.destroy();
@ -218,6 +223,7 @@ class PlayerData {
trackDimensionChanges() { trackDimensionChanges() {
// get player dimensions _once_ // get player dimensions _once_
let currentPlayerDimensions; let currentPlayerDimensions;
this.isFullscreen = !!document.fullscreenElement;
if (this.isFullscreen) { if (this.isFullscreen) {
currentPlayerDimensions = { currentPlayerDimensions = {
@ -255,11 +261,27 @@ class PlayerData {
/** /**
* Handles size restrictions (if any) * Checks if extension is allowed to run in current environment.
* @param currentPlayerDimensions * @param currentPlayerDimensions
*/ */
private handleSizeConstraints(currentPlayerDimensions: PlayerDimensions) { private handleSizeConstraints(currentPlayerDimensions: PlayerDimensions) {
// Check if extension is allowed to run in current combination of theater + full screen
const canEnable = this.siteSettings.isEnabledForEnvironment(this.isFullscreen, this.isTheaterMode);
// Enable/disable
if (!this.enabled && canEnable) {
this.enable();
} else if (this.enabled && !canEnable) {
this.disable();
return;
}
// Check if autodetection is allowed to run in current combination of theater + full screen
// if (this.siteSettings.isAardEnabledForEnvironment(this.isFullscreen, this.isTheaterMode)) {
// this.eventBus.send('disable-aard');
// }
// never disable ultrawidify in full screen // never disable ultrawidify in full screen
// if (this.isFullscreen) { // if (this.isFullscreen) {
// this.enable(); // this.enable();
@ -310,8 +332,6 @@ class PlayerData {
} }
} }
onPlayerDimensionsChanged(mutationList?, observer?) { onPlayerDimensionsChanged(mutationList?, observer?) {
this.trackDimensionChanges(); this.trackDimensionChanges();
} }