diff --git a/src/common/interfaces/ArInterface.ts b/src/common/interfaces/ArInterface.ts new file mode 100644 index 0000000..d9e25ed --- /dev/null +++ b/src/common/interfaces/ArInterface.ts @@ -0,0 +1,6 @@ +import AspectRatioType from '../enums/AspectRatioType.enum'; + +export interface Ar { + type: AspectRatioType, + ratio?: number +} diff --git a/src/common/interfaces/SettingsInterface.ts b/src/common/interfaces/SettingsInterface.ts index 8e6bedd..804cd94 100644 --- a/src/common/interfaces/SettingsInterface.ts +++ b/src/common/interfaces/SettingsInterface.ts @@ -366,7 +366,7 @@ export interface SiteSettingsInterface { defaults?: { // must be defined in @global and @empty crop?: {type: AspectRatioType, [x: string]: any}, stretch?: StretchType, - alignment?: any, + alignment?: {x: VideoAlignmentType, y: VideoAlignmentType}, } cropModePersistence?: CropModePersistence; diff --git a/src/csui/PlayerOverlay.vue b/src/csui/PlayerOverlay.vue index d852757..efcab38 100644 --- a/src/csui/PlayerOverlay.vue +++ b/src/csui/PlayerOverlay.vue @@ -39,11 +39,9 @@ import DebugPanel from './src/PlayerUiPanels/DebugPanel.vue' import VideoSettings from './src/PlayerUiPanels/VideoSettings.vue' import AutodetectionSettingsPanel from './src/PlayerUiPanels/AutodetectionSettingsPanel.vue' import PlayerDetectionPanel from './src/PlayerUiPanels/PlayerDetectionPanel.vue' -import { mapState } from 'vuex'; // import Icon from '../common/components/Icon'; import ResizerDebugPanel from './src/PlayerUiPanels/ResizerDebugPanelComponent'; import BrowserDetect from '../ext/conf/BrowserDetect'; -import ExecAction from './src/ui-libs/ExecAction'; import Logger from '../ext/lib/Logger'; import Settings from '../ext/lib/Settings'; import EventBus from '../ext/lib/EventBus'; @@ -85,7 +83,6 @@ export default { settings: {}, BrowserDetect: BrowserDetect, settingsInitialized: false, - execAction: new ExecAction(), eventBus: new EventBus(), logger: null, diff --git a/src/csui/src/PlayerUIWindow.vue b/src/csui/src/PlayerUIWindow.vue index ad5ddec..7870783 100644 --- a/src/csui/src/PlayerUIWindow.vue +++ b/src/csui/src/PlayerUIWindow.vue @@ -154,6 +154,7 @@ export default { selectedTab: 'videoSettings', BrowserDetect: BrowserDetect, preventClose: false, + siteSettings: null, } }, props: [ @@ -168,9 +169,12 @@ export default { // IS SUPER HARAM // THINGS WILL NOT WORK IF YOU USE ARROWS siteSupportLevel() { - return (this.site && this.settings?.active) ? this.settings.active.sites[this.site]?.type || 'no-support' : 'waiting'; + return (this.site && this.siteSettings) ? this.siteSettings.data.type || 'no-support' : 'waiting'; } }, + created() { + this.siteSettings = this.settings.getSiteSettings(this.site); + }, methods: { /** * Gets URL of the browser settings page (i think?) diff --git a/src/csui/src/PlayerUiPanels/AutodetectionSettingsPanel.vue b/src/csui/src/PlayerUiPanels/AutodetectionSettingsPanel.vue index 94964d1..6cfedaf 100644 --- a/src/csui/src/PlayerUiPanels/AutodetectionSettingsPanel.vue +++ b/src/csui/src/PlayerUiPanels/AutodetectionSettingsPanel.vue @@ -262,7 +262,6 @@ import Button from '../../../common/components/Button.vue' import KeyboardShortcutParser from '../../../common/js/KeyboardShortcutParser'; import ShortcutButton from '../../../common/components/ShortcutButton'; import EditShortcutButton from '../../../common/components/EditShortcutButton'; -import ExecAction from '../ui-libs/ExecAction'; import BrowserDetect from '../../../ext/conf/BrowserDetect'; import AspectRatioType from '../../../common/enums/AspectRatioType.enum'; import StretchType from '../../../common/enums/StretchType.enum'; @@ -286,7 +285,6 @@ export default { 'site' ], created() { - this.exec = new ExecAction(this.settings, window.location.hostname); this.eventBus.subscribe('uw-config-broadcast', {function: (config) => this.handleConfigBroadcast(config)}); }, mounted() { diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue b/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue index 71fdf2f..d32ed02 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue @@ -191,26 +191,7 @@ export default { commandArguments = $event.target.value; } - if (!this.settings.active.sites[this.site]) { - this.settings.active.sites[this.site] = this.settings.getDefaultSiteConfiguration(); - } - - const optionPath = option.split('.'); - if (optionPath.length < 2) { - this.settings.active.sites[this.site][option] = commandArguments; - } else { - let currentOptionObject = this.settings.active.sites[this.site][optionPath[0]]; - let i; - for (i = 1; i < optionPath.length - 1; i++) { - if (currentOptionObject[optionPath[i]] === undefined) { - currentOptionObject[optionPath[i]] = {}; - } - currentOptionObject = currentOptionObject[optionPath[i]]; - } - currentOptionObject[optionPath[optionPath.length - 1]] = commandArguments; - } - - this.settings.saveWithoutReload(); + this.siteSettings.set(option, commandArguments); } } diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue index 86672f0..9100ed9 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue @@ -132,23 +132,6 @@ -
-
Extension default
-
- -
-
@@ -220,23 +203,7 @@ export default { setDefaultCrop($event, scope) { const commandArguments = JSON.parse($event.target.value); - if (scope === 'site') { - if (!this.settings.active.sites[this.site]) { - this.settings.active.sites[this.site] = this.settings.getDefaultSiteConfiguration(); - } - this.settings.active.sites[this.site].defaultCrop = commandArguments; - } else { - // eventually, this 'if' will be safe to remove (and we'll be able to only - // get away with the 'else' section) Maybe in 6 months or so. - if (!this.settings.active.crop) { - this.settings.active['crop'] = { - default: commandArguments - } - } else { - this.settings.active.crop.default = commandArguments; - } - } - + this.siteSettings.set('defaults.crop', commandArguments); this.settings.saveWithoutReload(); }, diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue index b1db6cc..128a0dc 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue @@ -235,16 +235,7 @@ export default { */ setDefaultStretchingMode($event, globalOrSite) { const commandArguments = JSON.parse($event.target.value); - - if (globalOrSite === 'site') { - if (!this.settings.active.sites[this.site]) { - this.settings.active.sites[this.site] = this.settings.getDefaultSiteConfiguration(); - } - this.settings.active.sites[this.site].defaultStretch = commandArguments; - } else { - this.settings.active.stretch.default = commandArguments; - } - this.settings.saveWithoutReload(); + this.siteSettings.set('defaults.stretch', commandArguments); }, /** diff --git a/src/csui/src/PlayerUiPanels/VideoSettings.vue b/src/csui/src/PlayerUiPanels/VideoSettings.vue index 2eafeab..36066e9 100644 --- a/src/csui/src/PlayerUiPanels/VideoSettings.vue +++ b/src/csui/src/PlayerUiPanels/VideoSettings.vue @@ -117,7 +117,6 @@ import Button from '../../../common/components/Button.vue' import ShortcutButton from '../../../common/components/ShortcutButton'; import EditShortcutButton from '../../../common/components/EditShortcutButton'; import ComputeActionsMixin from '../../../common/mixins/ComputeActionsMixin'; -import ExecAction from '../ui-libs/ExecAction'; import BrowserDetect from '../../../ext/conf/BrowserDetect'; import AlignmentOptionsControlComponent from './AlignmentOptionsControlComponent.vue'; import CommsMixin from '../utils/CommsMixin'; @@ -149,7 +148,6 @@ export default { 'site' ], created() { - this.exec = new ExecAction(this.settings, window.location.hostname); this.eventBus.subscribe('uw-config-broadcast', {function: (config) => this.handleConfigBroadcast(config)}); }, mounted() { diff --git a/src/csui/src/ui-libs/ExecAction.js b/src/csui/src/ui-libs/ExecAction.js deleted file mode 100644 index c73980b..0000000 --- a/src/csui/src/ui-libs/ExecAction.js +++ /dev/null @@ -1,94 +0,0 @@ -import Comms from '../../../ext/lib/comms/Comms'; - -class ExecAction { - constructor(settings, site) { - this.settings = settings; - this.site = site; - } - - setSettings(settings) { - this.settings = settings; - } - setSite(site) { - this.site = site; - } - - - async exec(action, scope, frame, useBus) { - for (var cmd of action.cmd) { - if (!scope || scope === 'page') { - const message = { - forwardToContentScript: true, - targetFrame: frame, - frame: frame, - cmd: cmd.action, - arg: cmd.arg, - customArg: cmd.customArg - } - if (useBus) { - // todo: postMessage out of the iframe! - // window.ultrawidify.bus.sendMessage(message.cmd, message); - window.parent.sendMessage(message.cmd, message); - } else { - Comms.sendMessage(message); - } - } else { - - // set-ar-persistence sends stuff to content scripts as well (!) - // it's important to do that BEFORE the save step - if (cmd.action === 'set-ar-persistence') { - // even when setting global defaults, we only send message to the current tab in - // order to avoid problems related to - const message = { - forwardToActive: true, - targetFrame: frame, - frame: frame, - cmd: cmd.action, - arg: cmd.arg, - } - // this hopefully delays settings.save() until current crops are saved on the site - // and thus avoid any fucky-wuckies - if (useBus) { - // todo: postMessage out of the iframe! - // window.ultrawidify.bus.sendMessage(message.cmd, message); - window.parent.sendMessage(message.cmd, message); - } else { - await Comms.sendMessage(message); - } - } - - let site = this.site; - if (scope === 'global') { - site = '@global'; - } else if (!this.site) { - site = window.location.hostname; - } - - if (scope === 'site' && !this.settings.active.sites[site]) { - this.settings.active.sites[site] = this.settings.getDefaultOption(); - } - - if (cmd.action === "set-stretch") { - this.settings.active.sites[site].stretch = cmd.arg; - } else if (cmd.action === "set-alignment") { - this.settings.active.sites[site].videoAlignment = cmd.arg; - } else if (cmd.action === "set-extension-mode") { - this.settings.active.sites[site].mode = cmd.arg; - } else if (cmd.action === "set-autoar-mode") { - this.settings.active.sites[site].autoar = cmd.arg; - } else if (cmd.action === 'set-keyboard') { - this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg; - } else if (cmd.action === 'set-ar-persistence') { - this.settings.active.sites[site]['cropModePersistence'] = cmd.arg; - this.settings.saveWithoutReload(); - } - - if (cmd.action !== 'set-ar-persistence') { - this.settings.save(); - } - } - } - } -} - -export default ExecAction; diff --git a/src/ext/UWContent.ts b/src/ext/UWContent.ts index 1b976f3..ec5153e 100644 --- a/src/ext/UWContent.ts +++ b/src/ext/UWContent.ts @@ -8,11 +8,13 @@ import Logger, { baseLoggingOptions } from './lib/Logger'; import UWGlobals from './lib/UWGlobals'; import EventBus from './lib/EventBus'; import KeyboardHandler from './lib/kbm/KeyboardHandler'; +import { SiteSettings } from './lib/settings/SiteSettings'; export default class UWContent { pageInfo: PageInfo; comms: CommsClient; settings: Settings; + siteSettings: SiteSettings; keyboardHandler: KeyboardHandler; logger: Logger; eventBus: EventBus; @@ -90,6 +92,7 @@ export default class UWContent { logger: this.logger }); await this.settings.init(); + this.siteSettings = this.settings.getSiteSettings(); } this.eventBus = new EventBus(); @@ -109,42 +112,25 @@ export default class UWContent { } } + // we always initialize extension, even if it's disabled. initPhase2() { - // If extension is soft-disabled, don't do shit - var extensionMode = this.settings.getExtensionMode(); - - this.logger.log('info', 'debug', "[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full')); - - const isSiteDisabled = extensionMode === ExtensionMode.Disabled - - if (isSiteDisabled) { - this.destroy(); - if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) { - this.logger.log('info', 'debug', "[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED") - return; - } - } - try { if (this.pageInfo) { this.logger.log('info', 'debug', '[uw.js::setup] An instance of pageInfo already exists and will be destroyed.'); this.pageInfo.destroy(); } - this.pageInfo = new PageInfo(this.eventBus, this.settings, this.logger, extensionMode, isSiteDisabled); + this.pageInfo = new PageInfo(this.eventBus, this.siteSettings, this.settings, this.logger); this.logger.log('info', 'debug', "[uw.js::setup] pageInfo initialized."); this.logger.log('info', 'debug', "[uw.js::setup] will try to initate KeyboardHandler."); - // start action handler only if extension is enabled for this site - if (!isSiteDisabled) { - if (this.keyboardHandler) { - this.keyboardHandler.destroy(); - } - this.keyboardHandler = new KeyboardHandler(this.eventBus, this.settings, this.logger); - this.keyboardHandler.init(); - - this.logger.log('info', 'debug', "[uw.js::setup] KeyboardHandler initiated."); + if (this.keyboardHandler) { + this.keyboardHandler.destroy(); } + this.keyboardHandler = new KeyboardHandler(this.eventBus, this.siteSettings, this.settings, this.logger); + this.keyboardHandler.init(); + + this.logger.log('info', 'debug', "[uw.js::setup] KeyboardHandler initiated."); } catch (e) { console.error('Ultrawidify: failed to start extension. Error:', e) diff --git a/src/ext/lib/Settings.ts b/src/ext/lib/Settings.ts index 29b1665..f3590f2 100644 --- a/src/ext/lib/Settings.ts +++ b/src/ext/lib/Settings.ts @@ -12,6 +12,7 @@ import Logger from './Logger'; import SettingsInterface from '../../common/interfaces/SettingsInterface'; import { browser } from 'webextension-polyfill-ts'; import AspectRatioType from '../../common/enums/AspectRatioType.enum'; +import { SiteSettings } from './settings/SiteSettings'; if(process.env.CHANNEL !== 'stable'){ console.info("Loading Settings"); @@ -348,189 +349,6 @@ class Settings { return JSON.parse(JSON.stringify(this.default)); } - // ----------------------------------------- - // Config for a given page: - // - // : { - // status: