diff --git a/src/common/mixins/ComputeActionsMixin.js b/src/common/mixins/ComputeActionsMixin.js index 11689ee..6fd6e5d 100644 --- a/src/common/mixins/ComputeActionsMixin.js +++ b/src/common/mixins/ComputeActionsMixin.js @@ -12,6 +12,9 @@ export default { aspectRatioActions: function(){ return this.scopeActions.filter(x => x.cmd.length === 1 && x.cmd[0].action === 'set-ar') || []; }, + cropModePersistenceActions: function() { + return this.scopeActions.filter(x => x.cmd.length === 1 && x.cmd[0].action === 'set-ar-persistence') || []; + }, stretchActions: function(){ return this.scopeActions.filter(x => x.cmd.length === 1 && x.cmd[0].action === 'set-stretch') || []; }, diff --git a/src/ext/lib/video-data/PageInfo.js b/src/ext/lib/video-data/PageInfo.js index 35d2db9..b23ecbe 100644 --- a/src/ext/lib/video-data/PageInfo.js +++ b/src/ext/lib/video-data/PageInfo.js @@ -574,6 +574,22 @@ class PageInfo { this.actionHandler.setKeybordLocal(state); } + setArPersistence(persistenceMode) { + if (persistenceMode === CropModePersistence.CurrentSession) { + sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(this.currentCrop)); + } else if (persistenceMode === CropModePersistence.Forever) { + if (this.settings.active.sites[window.location.host]) { + // | key may be missing, so we do this + this.settings.active.sites[window.location.host]['defaultAr'] = this.currentCrop; + } else { + this.settings.active.sites[window.location.host] = this.settings.getDefaultOption(); + this.settings.active.sites[window.location.host]['defaultAr'] = this.currentCrop; + } + + this.settings.saveWithoutReload(); + } + } + setDefaultCrop(ar) { this.currentCrop = ar; // This means crop persistance is disabled. If crop persistance is enabled, then settings for current @@ -594,10 +610,8 @@ class PageInfo { // | key may be missing, so we do this this.settings.active.sites[window.location.host]['defaultAr'] = ar; } else { - // add options for new site if they're missing! - this.settings.active.sites[window.location.host] = { - defaultAr: ar, - } + this.settings.active.sites[window.location.host] = this.settings.getDefaultOption(); + this.settings.active.sites[window.location.host]['defaultAr'] = ar; } this.settings.saveWithoutReload(); diff --git a/src/popup/js/ExecAction.js b/src/popup/js/ExecAction.js index 422cb7c..130a3fe 100644 --- a/src/popup/js/ExecAction.js +++ b/src/popup/js/ExecAction.js @@ -13,7 +13,7 @@ class ExecAction { this.site = site; } - exec(action, scope, frame) { + async exec(action, scope, frame) { for (var cmd of action.cmd) { if (scope === 'page') { const message = { @@ -27,6 +27,32 @@ class ExecAction { 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 === 'set-ar-persistence') { + let message; + if (scope === 'site') { + message = { + forwardToContentScript: true, + targetFrame: frame, + frame: frame, + cmd: cmd.action, + arg: cmd.arg, + } + } else { + message = { + forwardToAll: 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 + await Comms.sendMessage(message); + } + let site = this.site; if (scope === 'global') { site = '@global'; diff --git a/src/popup/panels/DefaultSettingsPanel.vue b/src/popup/panels/DefaultSettingsPanel.vue index a4e57d9..4754e8f 100644 --- a/src/popup/panels/DefaultSettingsPanel.vue +++ b/src/popup/panels/DefaultSettingsPanel.vue @@ -31,7 +31,7 @@
+ +
+
Persists crop mode :
+
+ + +
+
+
-
Default stretching mode:
+
Default stretching mode:
Cropping mode:
+
+ Cropping mode will persist + + + + This can be changed in the 'site settings' or 'extension settings' tab. +
+ >
@@ -117,11 +124,13 @@ import ExecAction from '../js/ExecAction'; import KeyboardShortcutParser from '../../common/js/KeyboardShortcutParser'; import ShortcutButton from '../../common/components/ShortcutButton'; import ComputeActionsMixin from '../../common/mixins/ComputeActionsMixin'; +import CropModePersistence from '../../common/enums/crop-mode-persistence.enum'; export default { data() { return { scope: 'page', + CropModePersistence: CropModePersistence, } }, mixins: [ @@ -131,7 +140,8 @@ export default { 'settings', 'frame', 'zoom', - 'someSitesDisabledWarning' + 'someSitesDisabledWarning', + 'cropModePersistence', ], created() { this.exec = new ExecAction(this.settings);