From dbc35ccbd176e0ed3f31b9f27d993189f594f584 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 2 Nov 2019 01:05:36 +0100 Subject: [PATCH] Patching for v4.4.0 --- src/ext/conf/ExtConfPatches.js | 125 ++++++++++++++++++++++++++ src/ext/conf/ExtensionConf.js | 4 +- src/ext/lib/Settings.js | 28 ++++-- src/options/SuperAdvancedSettings.vue | 2 +- 4 files changed, 151 insertions(+), 8 deletions(-) diff --git a/src/ext/conf/ExtConfPatches.js b/src/ext/conf/ExtConfPatches.js index 6400829..4c2ff52 100644 --- a/src/ext/conf/ExtConfPatches.js +++ b/src/ext/conf/ExtConfPatches.js @@ -117,7 +117,132 @@ const ExtensionConfPatch = [ } } } + }, { + forVersion: '4.4.0', + updateFn: (userOptions, defaultOptions) => { + // remove 'press P to toggle panning mode' thing + const togglePan = userOptions.actions.find(x => x.cmd && x.cmd.length === 1 && x.cmd[0].action === 'toggle-pan'); + if (togglePan) { + togglePan.scopes = {}; + } + + // add new actions + userOptions.actions.push({ + name: 'Don\'t persist crop', + label: 'Never persist', + cmd: [{ + action: 'set-ar-persistence', + arg: 0, + }], + scopes: { + site: { + show: true, + }, + global: { + show: true, + } + }, + playerUi: { + show: true, + } + }, { + name: 'Persist crop while on page', + label: 'Until page load', + cmd: [{ + action: 'set-ar-persistence', + arg: 1, + }], + scopes: { + site: { + show: true, + }, + global: { + show: true, + } + }, + playerUi: { + show: true, + } + }, { + name: 'Persist crop for current session', + label: 'Current session', + cmd: [{ + action: 'set-ar-persistence', + arg: 2, + }], + scopes: { + site: { + show: true, + }, + global: { + show: true, + } + }, + playerUi: { + show: true, + } + }, { + name: 'Persist until manually reset', + label: 'Always persist', + cmd: [{ + action: 'set-ar-persistence', + arg: 3, + }], + scopes: { + site: { + show: true, + }, + global: { + show: true, + } + }, + playerUi: { + show: true, + } + }, { + name: 'Default crop persistence', + label: 'Default', + cmd: [{ + action: 'set-ar-persistence', + arg: -1, + }], + scopes: { + site: { + show: true, + }, + }, + playerUi: { + show: true, + } + }); + + // patch shortcuts for non-latin layouts, but only if the user hasn't changed default keys + for (const action of userOptions.actions) { + if (!action.cmd || action.cmd.length !== 1) { + continue; + } + try { + // if this fails, then action doesn't have keyboard shortcut associated with it, so we skip it + + const actionDefaults = defaultOptions.actions.find(x => x.cmd && x.cmd.length === 1 // (redundant, default actions have exactly 1 cmd in array) + && x.cmd[0].action === action.cmd[0].action + && x.scopes.page + && x.scopes.page.shortcut + && x.scopes.page.shortcut.length === 1 + && x.scopes.page.shortcut[0].key === action.scopes.page.shortcut[0].key // this can throw exception, and it's okay + ); + if (actionDefaults === undefined) { + continue; + } + // update 'code' property for shortcut + action.scopes.page.shortcut[0]['code'] = actionDefaults.scopes.page.shortcut[0].code; + } catch (e) { + continue; + } + } + } } ]; + export default ExtensionConfPatch; \ No newline at end of file diff --git a/src/ext/conf/ExtensionConf.js b/src/ext/conf/ExtensionConf.js index b0c3f97..f014e23 100644 --- a/src/ext/conf/ExtensionConf.js +++ b/src/ext/conf/ExtensionConf.js @@ -385,7 +385,7 @@ var ExtensionConf = { } }, { name: 'Persist crop while on page', - label: 'While on page', + label: 'Until page load', cmd: [{ action: 'set-ar-persistence', arg: CropModePersistence.UntilPageReload, @@ -438,7 +438,7 @@ var ExtensionConf = { show: true, } }, { - name: 'Default persistence', + name: 'Default crop persistence', label: 'Default', cmd: [{ action: 'set-ar-persistence', diff --git a/src/ext/lib/Settings.js b/src/ext/lib/Settings.js index 4cd3e1c..9c4478b 100644 --- a/src/ext/lib/Settings.js +++ b/src/ext/lib/Settings.js @@ -144,13 +144,29 @@ class Settings { // apply all remaining patches this.logger.log('info', 'settings', `[Settings::applySettingsPatches] There are ${patches.length - index} settings patches to apply`); while (index < patches.length) { + const updateFn = patches[index].updateFn; delete patches[index].forVersion; - ObjectCopy.overwrite(this.active, patches[index]); + delete patches[index].updateFn; + + if (Object.keys(patches[index]).length > 0) { + ObjectCopy.overwrite(this.active, patches[index]); + } + if (updateFn) { + + try { + updateFn(this.active, this.getDefaultSettings()); + } catch (e) { + console.log("!!!!", e) + this.logger.log('error', 'settings', '[Settings::applySettingsPatches] Failed to execute update function. Keeping settings object as-is. Error:', e); + } + } + index++; } } async init() { + console.log("settngs init") const settings = await this.get(); this.version = this.getExtensionVersion(); @@ -267,8 +283,10 @@ class Settings { } } - async set(extensionConf) { - extensionConf.version = this.version; + async set(extensionConf, options) { + if (!options || !options.forcePreserveVersion) { + extensionConf.version = this.version; + } this.logger.log('info', 'settings', "[Settings::set] setting new settings:", extensionConf) @@ -287,12 +305,12 @@ class Settings { this.active[prop] = value; } - async save() { + async save(options) { if (Debug.debug && Debug.storage) { console.log("[Settings::save] Saving active settings:", this.active); } this.active.preventReload = undefined; - await this.set(this.active); + await this.set(this.active, options); } diff --git a/src/options/SuperAdvancedSettings.vue b/src/options/SuperAdvancedSettings.vue index 5b4c3ba..111631f 100644 --- a/src/options/SuperAdvancedSettings.vue +++ b/src/options/SuperAdvancedSettings.vue @@ -70,7 +70,7 @@ export default { if (this.hasError) { return; } - this.settings.save(); + this.settings.save({forcePreserveVersion: true}); // this.parsedSettings = JSON.stringify(this.settings.active, null, 2); // this.lastSettings = JSON.parse(JSON.stringify(this.settings.active)); const ths = this;