Pass set-ar-persistence between CommsClient and pageInfo

This commit is contained in:
Tamius Han 2019-10-26 02:38:47 +02:00
parent cda5d87735
commit 854bc05d14
4 changed files with 24 additions and 28 deletions

View File

@ -92,6 +92,8 @@ class CommsClient {
this.pageInfo.setManualTick(message.arg); this.pageInfo.setManualTick(message.arg);
} else if (message.cmd === 'autoar-tick') { } else if (message.cmd === 'autoar-tick') {
this.pageInfo.tick(); this.pageInfo.tick();
} else if (message.cmd === 'set-ar-persistence') {
this.pageInfo.setArPersistence(message.arg);
} }
} }

View File

@ -575,6 +575,9 @@ class PageInfo {
} }
setArPersistence(persistenceMode) { setArPersistence(persistenceMode) {
// name of this function is mildly misleading — we don't really _set_ ar persistence. (Ar persistence
// mode is set and saved via popup or keyboard shortcuts, if user defined them) We just save the current
// aspect ratio whenever aspect ratio persistence mode changes.
if (persistenceMode === CropModePersistence.CurrentSession) { if (persistenceMode === CropModePersistence.CurrentSession) {
sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(this.currentCrop)); sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(this.currentCrop));
} else if (persistenceMode === CropModePersistence.Forever) { } else if (persistenceMode === CropModePersistence.Forever) {
@ -590,7 +593,7 @@ class PageInfo {
} }
} }
setDefaultCrop(ar) { updateCurrentCrop(ar) {
this.currentCrop = ar; this.currentCrop = ar;
// This means crop persistance is disabled. If crop persistance is enabled, then settings for current // This means crop persistance is disabled. If crop persistance is enabled, then settings for current
// site MUST exist (crop persistence mode is disabled by default) // site MUST exist (crop persistence mode is disabled by default)

View File

@ -134,16 +134,16 @@ class Resizer {
const siteSettings = this.settings.active.sites[window.location.host]; const siteSettings = this.settings.active.sites[window.location.host];
// most everything that could go wrong went wrong by this stage, and returns can happen afterwards // most everything that could go wrong went wrong by this stage, and returns can happen afterwards
// this means here's the optimal place to set or forget aspect ratio // this means here's the optimal place to set or forget aspect ratio. Saving of current crop ratio
if (this.settings.getDefaultCropPersistenceMode(window.location.host) > CropModePersistance.Disabled) { // is handled in pageInfo.updateCurrentCrop(), which also makes sure to persist aspect ratio if ar
if (ar.type === AspectRatio.Automatic || // is set to persist between videos / through current session / until manual reset.
ar.type === AspectRatio.Reset || if (ar.type === AspectRatio.Automatic ||
ar.type === AspectRatio.Initial ) { ar.type === AspectRatio.Reset ||
// reset/undo default ar.type === AspectRatio.Initial ) {
this.conf.pageInfo.setDefaultCrop(undefined); // reset/undo default
} else { this.conf.pageInfo.updateCurrentCrop(undefined);
this.conf.pageInfo.setDefaultCrop(ar); } else {
} this.conf.pageInfo.updateCurrentCrop(ar);
} }
if (ar.type === AspectRatio.Automatic || if (ar.type === AspectRatio.Automatic ||

View File

@ -30,23 +30,14 @@ class ExecAction {
// set-ar-persistence sends stuff to content scripts as well (!) // set-ar-persistence sends stuff to content scripts as well (!)
// it's important to do that BEFORE the save step // it's important to do that BEFORE the save step
if (cmd === 'set-ar-persistence') { if (cmd === 'set-ar-persistence') {
let message; // even when setting global defaults, we only send message to the current tab in
if (scope === 'site') { // order to avoid problems related to
message = { const message = {
forwardToContentScript: true, forwardToContentScript: true,
targetFrame: frame, targetFrame: frame,
frame: frame, frame: frame,
cmd: cmd.action, cmd: cmd.action,
arg: cmd.arg, 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 // this hopefully delays settings.save() until current crops are saved on the site
// and thus avoid any fucky-wuckies // and thus avoid any fucky-wuckies