Changes to how crop mode persistence works, extra persistence options
This commit is contained in:
parent
d5a6e8d707
commit
d0058cedb9
@ -1,7 +1,9 @@
|
||||
var CropModePersistence = Object.freeze({
|
||||
Default: -1,
|
||||
Disabled: 0,
|
||||
UntilPageReload: 1,
|
||||
Forever: 2,
|
||||
CurrentSession: 2,
|
||||
Forever: 3,
|
||||
});
|
||||
|
||||
export default CropModePersistence;
|
@ -2,6 +2,7 @@ import VideoAlignment from '../../common/enums/video-alignment.enum';
|
||||
import Stretch from '../../common/enums/stretch.enum';
|
||||
import ExtensionMode from '../../common/enums/extension-mode.enum';
|
||||
import AspectRatio from '../../common/enums/aspect-ratio.enum';
|
||||
import CropModePersistence from '../../common/enums/crop-mode-persistence.enum';
|
||||
|
||||
var ActionList = {
|
||||
'set-ar': {
|
||||
@ -30,6 +31,33 @@ var ActionList = {
|
||||
page: true,
|
||||
}
|
||||
},
|
||||
'set-ar-persistence': {
|
||||
name: 'Set crop mode persistence',
|
||||
args: [{
|
||||
name: 'Never persist',
|
||||
arg: CropModePersistence.Disabled,
|
||||
},{
|
||||
name: 'While on page',
|
||||
arg: CropModePersistence.UntilPageReload,
|
||||
},{
|
||||
name: 'Current session',
|
||||
arg: CropModePersistence.CurrentSession,
|
||||
},{
|
||||
name: 'Always persist',
|
||||
arg: CropModePersistence.Forever,
|
||||
}, {
|
||||
name: 'Default',
|
||||
arg: CropModePersistence.Default,
|
||||
scopes: {
|
||||
site: true,
|
||||
}
|
||||
}],
|
||||
scopes: {
|
||||
global: true,
|
||||
site: true,
|
||||
page: false,
|
||||
}
|
||||
},
|
||||
'set-stretch': {
|
||||
name: 'Set stretch',
|
||||
args: [{
|
||||
|
@ -5,6 +5,7 @@ import Stretch from '../../common/enums/stretch.enum';
|
||||
import ExtensionMode from '../../common/enums/extension-mode.enum';
|
||||
import AntiGradientMode from '../../common/enums/anti-gradient-mode.enum';
|
||||
import AspectRatio from '../../common/enums/aspect-ratio.enum';
|
||||
import CropModePersistence from '../../common/enums/crop-mode-persistence.enum';
|
||||
|
||||
if(Debug.debug)
|
||||
console.log("Loading: ExtensionConf.js");
|
||||
@ -364,6 +365,93 @@ var ExtensionConf = {
|
||||
show: true,
|
||||
path: 'crop',
|
||||
}
|
||||
}, {
|
||||
name: 'Don\'t persist crop',
|
||||
label: 'Never persist',
|
||||
cmd: [{
|
||||
action: 'set-ar-persistence',
|
||||
arg: CropModePersistence.Never,
|
||||
}],
|
||||
scopes: {
|
||||
site: {
|
||||
show: true,
|
||||
},
|
||||
global: {
|
||||
show: true,
|
||||
}
|
||||
},
|
||||
playerUi: {
|
||||
show: true,
|
||||
}
|
||||
}, {
|
||||
name: 'Persist crop while on page',
|
||||
label: 'While on page',
|
||||
cmd: [{
|
||||
action: 'set-ar-persistence',
|
||||
arg: CropModePersistence.UntilPageReload,
|
||||
}],
|
||||
scopes: {
|
||||
site: {
|
||||
show: true,
|
||||
},
|
||||
global: {
|
||||
show: true,
|
||||
}
|
||||
},
|
||||
playerUi: {
|
||||
show: true,
|
||||
}
|
||||
}, {
|
||||
name: 'Persist crop for current session',
|
||||
label: 'Always persist',
|
||||
cmd: [{
|
||||
action: 'set-ar-persistence',
|
||||
arg: CropModePersistence.CurrentSession,
|
||||
}],
|
||||
scopes: {
|
||||
site: {
|
||||
show: true,
|
||||
},
|
||||
global: {
|
||||
show: true,
|
||||
}
|
||||
},
|
||||
playerUi: {
|
||||
show: true,
|
||||
}
|
||||
}, {
|
||||
name: 'Persist until manually reset',
|
||||
label: 'Always persist',
|
||||
cmd: [{
|
||||
action: 'set-ar-persistence',
|
||||
arg: CropModePersistence.Forever,
|
||||
}],
|
||||
scopes: {
|
||||
site: {
|
||||
show: true,
|
||||
},
|
||||
global: {
|
||||
show: true,
|
||||
}
|
||||
},
|
||||
playerUi: {
|
||||
show: true,
|
||||
}
|
||||
}, {
|
||||
name: 'Default persistence',
|
||||
label: 'Default',
|
||||
cmd: [{
|
||||
action: 'set-ar-persistence',
|
||||
arg: CropModePersistence.Default,
|
||||
}],
|
||||
scopes: {
|
||||
site: {
|
||||
show: true,
|
||||
},
|
||||
},
|
||||
playerUi: {
|
||||
show: true,
|
||||
}
|
||||
}, {
|
||||
name: 'Zoom in',
|
||||
label: 'Zoom',
|
||||
|
@ -6,6 +6,7 @@ import ObjectCopy from '../lib/ObjectCopy';
|
||||
import Stretch from '../../common/enums/stretch.enum';
|
||||
import VideoAlignment from '../../common/enums/video-alignment.enum';
|
||||
import ExtensionConfPatch from '../conf/ExtConfPatches';
|
||||
import CropModePersistence from '../../common/enums/crop-mode-persistence.enum';
|
||||
|
||||
|
||||
|
||||
@ -515,6 +516,15 @@ class Settings {
|
||||
return this.active.sites['@global'].stretch;
|
||||
}
|
||||
|
||||
getDefaultCropPersistenceMode(site) {
|
||||
if (site && this.active.sites[site] && this.active.sites[site].cropModePersistence !== Stretch.Default) {
|
||||
return this.active.sites[site].cropModePersistence;
|
||||
}
|
||||
|
||||
// persistence mode thing is missing from settings by default
|
||||
return this.active.sites['@global'].cropModePersistence || CropModePersistence.Disabled;
|
||||
}
|
||||
|
||||
getDefaultVideoAlignment(site) {
|
||||
if (site && this.active.sites[site] && this.active.sites[site].videoAlignment !== VideoAlignment.Default) {
|
||||
return this.active.sites[site].videoAlignment;
|
||||
|
@ -22,6 +22,7 @@ class PageInfo {
|
||||
this.extensionMode = extensionMode;
|
||||
this.readOnly = readOnly;
|
||||
this.defaultCrop = undefined;
|
||||
this.currentCrop = undefined;
|
||||
|
||||
if (comms){
|
||||
this.comms = comms;
|
||||
@ -34,14 +35,23 @@ class PageInfo {
|
||||
cmd: 'inject-css',
|
||||
cssString: playerStyleString
|
||||
});
|
||||
} catch (e) {
|
||||
// do nothing. It's ok if there's no special settings for the player element or crop persistence
|
||||
}
|
||||
|
||||
// try getting default crop immediately.
|
||||
if (this.settings.active.sites[window.location.host].cropPersistence === CropModePersistence.Forever) {
|
||||
// try getting default crop immediately.
|
||||
const cropModePersistence = this.settings.active.getDefaultCropPersistenceMode(window.location.host);
|
||||
|
||||
try {
|
||||
if (cropModePersistence === CropModePersistence.Forever) {
|
||||
this.defaultCrop = this.settings.active.sites[window.location.host].defaultCrop;
|
||||
} else if (cropModePersistence === CropModePersistence.CurrentSession) {
|
||||
this.defaultCrop = JSON.parse(sessionStorage.getItem('uw-crop-mode-session-persistence'));
|
||||
}
|
||||
} catch (e) {
|
||||
// do nothing. It's ok if there's no special settings for the player element or crop persistence
|
||||
}
|
||||
this.currentCrop = this.defaultCrop;
|
||||
|
||||
this.rescan(RescanReason.PERIODIC);
|
||||
this.scheduleUrlCheck();
|
||||
@ -565,17 +575,31 @@ class PageInfo {
|
||||
}
|
||||
|
||||
setDefaultCrop(ar) {
|
||||
this.currentCrop = ar;
|
||||
// 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)
|
||||
if (!this.settings.active.sites[window.location.host] ||
|
||||
this.settings.active.sites[window.location.host].cropPersistence === CropModePersistence.Disabled) {
|
||||
|
||||
const cropModePersistence = this.settings.active.getDefaultCropPersistenceMode(window.location.host);
|
||||
|
||||
if (cropModePersistence === CropModePersistence.Disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.defaultCrop = ar;
|
||||
|
||||
if (this.settings.active.sites[window.location.host].cropPersistence === CropModePersistence.Forever) {
|
||||
this.settings.active.sites[window.location.host].defaultAr = ar;
|
||||
if (cropModePersistence === CropModePersistence.CurrentSession) {
|
||||
sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(ar));
|
||||
} else if (cropModePersistence === 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'] = ar;
|
||||
} else {
|
||||
// add options for new site if they're missing!
|
||||
this.settings.active.sites[window.location.host] = {
|
||||
defaultAr: ar,
|
||||
}
|
||||
}
|
||||
|
||||
this.settings.saveWithoutReload();
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class Resizer {
|
||||
|
||||
// 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
|
||||
if (siteSettings && siteSettings.cropModePersistance > CropModePersistance.Disabled) {
|
||||
if (this.settings.getDefaultCropPersistenceMode(window.location.host) > CropModePersistance.Disabled) {
|
||||
if (ar.type === AspectRatio.Automatic ||
|
||||
ar.type === AspectRatio.Reset ||
|
||||
ar.type === AspectRatio.Initial ) {
|
||||
|
Loading…
Reference in New Issue
Block a user