UI: can set default crop, stretch. (TODO: actually get and use those values)

This commit is contained in:
Tamius Han 2021-11-23 01:32:42 +01:00
parent ee8ac1d9ee
commit 30835e94c0
5 changed files with 239 additions and 35 deletions

View File

@ -172,6 +172,10 @@ interface SettingsInterface {
restrictions?: RestrictionsSettings; restrictions?: RestrictionsSettings;
crop: {
default: any;
},
zoom: { zoom: {
minLogZoom: number, minLogZoom: number,
maxLogZoom: number, maxLogZoom: number,
@ -186,6 +190,7 @@ interface SettingsInterface {
defaultAr?: any defaultAr?: any
}, },
stretch: { stretch: {
default: any;
conditionalDifferencePercent: number // black bars less than this wide will trigger stretch conditionalDifferencePercent: number // black bars less than this wide will trigger stretch
// if mode is set to '1'. 1.0=100% // if mode is set to '1'. 1.0=100%
}, },
@ -283,10 +288,15 @@ interface SettingsInterface {
// //
sites: { sites: {
[x: string]: { [x: string]: {
mode?: ExtensionMode, defaultCrop?: any, // v6 new
autoar?: ExtensionMode, defaultStretch?: any, // v6 new
autoarFallback?: ExtensionMode,
stretch?: StretchType, // everything 'superseded by' needs to be implemented
// as well as ported from the old settings
mode?: ExtensionMode, // v6 — superseded by defaultCrop
autoar?: ExtensionMode, // v6 — superseded by defaultCrop
autoarFallback?: ExtensionMode, // v6 — deprecated, no replacement
stretch?: StretchType, // v6 — superseded by defaultStretch
videoAlignment?: VideoAlignmentType, videoAlignment?: VideoAlignmentType,
keyboardShortcutsEnabled?: ExtensionMode, keyboardShortcutsEnabled?: ExtensionMode,
type?: string, type?: string,

View File

@ -1,5 +1,8 @@
<template> <template>
<div class="flex flex-row flex-wrap" style="padding-bottom: 20px"> <div class="flex flex-row flex-wrap" style="padding-bottom: 20px">
<!-- CROP OPTIONS -->
<div v-if="settings" class="sub-panel"> <div v-if="settings" class="sub-panel">
<div class="flex flex-row"> <div class="flex flex-row">
<mdicon name="crop" :size="32" /> <mdicon name="crop" :size="32" />
@ -15,7 +18,45 @@
> >
</ShortcutButton> </ShortcutButton>
</div> </div>
<div class="flex flex-row">
<div class="label">Default for this site</div>
<div class="select">
<select
:value="siteDefaultCrop"
@click="setDefaultCrop($event, 'site')"
>
<option
v-for="(command, index) of settings?.active.commands.crop"
:key="index"
:value="JSON.stringify(command.arguments)"
>
{{command.label}}
</option>
</select>
</div> </div>
</div>
<div class="flex flex-row">
<div class="label">Extension default</div>
<div class="select">
<select
:value="extensionDefaultCrop"
@click="setDefaultCrop($event, 'global')"
>
<option
v-for="(command, index) of settings?.active.commands.crop"
:key="index"
:value="JSON.stringify(command.arguments)"
>
{{command.label}}
</option>
</select>
</div>
</div>
</div>
<!-- STRETCH OPTIONS -->
<div v-if="settings" class="sub-panel"> <div v-if="settings" class="sub-panel">
<div class="flex flex-row"> <div class="flex flex-row">
<mdicon name="stretch-to-page-outline" :size="32" /> <mdicon name="stretch-to-page-outline" :size="32" />
@ -31,7 +72,45 @@
> >
</ShortcutButton> </ShortcutButton>
</div> </div>
<div class="flex flex-row">
<div class="label">Default for this site</div>
<div class="select">
<select
v-model="siteDefaultStretchMode"
@click="setDefaultStretchingMode($event, 'site')"
>
<option
v-for="(command, index) of settings?.active.commands.stretch"
:key="index"
:value="JSON.stringify(command.arguments)"
>
{{command.label}}
</option>
</select>
</div> </div>
</div>
<div class="flex flex-row">
<div class="label">Extension default</div>
<div class="select">
<select
v-model="extensionDefaultStretchMode"
@click="setDefaultStretchingMode($event, 'global')"
>
<option
v-for="(command, index) of settings?.active.commands.stretch"
:key="index"
:value="JSON.stringify(command.arguments)"
>
{{command.label}}
</option>
</select>
</div>
</div>
</div>
<!-- ZOOM OPTIONS -->
<div class="sub-panel"> <div class="sub-panel">
<div class="flex flex-row"> <div class="flex flex-row">
<mdicon name="magnify-plus-outline" :size="32" /> <mdicon name="magnify-plus-outline" :size="32" />
@ -146,6 +225,7 @@ import ComputeActionsMixin from '../../common/mixins/ComputeActionsMixin';
import ExecAction from '../ui-libs/ExecAction'; import ExecAction from '../ui-libs/ExecAction';
import BrowserDetect from '../../ext/conf/BrowserDetect'; import BrowserDetect from '../../ext/conf/BrowserDetect';
import AspectRatioType from '../../common/enums/AspectRatioType.enum'; import AspectRatioType from '../../common/enums/AspectRatioType.enum';
import StretchType from '../../common/enums/StretchType.enum';
import CropModePersistence from '../../common/enums/CropModePersistence.enum'; import CropModePersistence from '../../common/enums/CropModePersistence.enum';
import AlignmentOptionsControlComponent from './AlignmentOptionsControlComponent.vue'; import AlignmentOptionsControlComponent from './AlignmentOptionsControlComponent.vue';
@ -155,6 +235,8 @@ export default {
exec: null, exec: null,
scope: 'page', scope: 'page',
CropModePersistence: CropModePersistence, CropModePersistence: CropModePersistence,
StretchType: StretchType,
AspectRatioType: AspectRatioType,
zoomAspectRatioLocked: true, zoomAspectRatioLocked: true,
zoom: { zoom: {
x: 0, x: 0,
@ -163,7 +245,7 @@ export default {
} }
}, },
mixins: [ mixins: [
ComputeActionsMixin ComputeActionsMixin,
], ],
props: [ props: [
'settings', 'settings',
@ -189,6 +271,29 @@ export default {
AlignmentOptionsControlComponent AlignmentOptionsControlComponent
}, },
computed: { computed: {
// because this is passed to a <select>, all the values must be
// passed as strings.
extensionDefaultCrop() {
return JSON.stringify(
this.settings?.active.crop?.default ?? {type: AspectRatioType.Automatic}
);
},
siteDefaultCrop() {
console.log('default crop for site:', JSON.parse(JSON.stringify(this.settings)), this.settings?.active.sites[window.location.hostname], this.settings?.active.sites[window.location.hostname].defaultCrop)
return JSON.stringify(
this.settings?.getDefaultCrop() ?? {type: AspectRatioType.Automatic}
);
},
extensionDefaultStretchMode () {
return JSON.stringify(
this.settings?.active.stretch.default ?? {type: StretchType.NoStretch}
);
},
siteDefaultStretchMode () {
return JSON.stringify(
this.settings?.getDefaultStretchMode() ?? {type: StretchType.NoStretch}
);
}
}, },
methods: { methods: {
getZoomForDisplay(axis) { getZoomForDisplay(axis) {
@ -236,6 +341,50 @@ export default {
newZoom = Math.pow(2, newZoom); newZoom = Math.pow(2, newZoom);
this.eventBus.send('set-zoom', {zoom: newZoom, axis: axis, noAnnounce: true}); this.eventBus.send('set-zoom', {zoom: newZoom, axis: axis, noAnnounce: true});
}, },
/**
* Sets default crop, for either site or global
*/
setDefaultCrop($event, globalOrSite) {
const commandArguments = JSON.parse($event.target.value);
if (globalOrSite === 'site') {
if (!this.settings.active.sites[window.location.hostname]) {
this.settings.active.sites[window.location.hostname] = this.settings.getDefaultSiteConfiguration();
}
this.settings.active.sites[window.location.hostname].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) {
console.log('active settings crop not present. Well add');
this.settings.active['crop'] = {
default: commandArguments
}
} else {
console.log('default crop settings are present:', JSON.parse(JSON.stringify(this.settings.active.crop)))
this.settings.active.crop.default = commandArguments;
}
}
this.settings.saveWithoutReload();
},
/**
* Sets default stretching mode, for either site or global
*/
setDefaultStretchingMode($event, globalOrSite) {
const commandArguments = JSON.parse($event.target.value);
if (globalOrSite === 'site') {
if (!this.settings.active.sites[window.location.hostname]) {
this.setting.active.sites[window.location.hostname] = this.settings.getDefaultSiteConfiguration();
}
this.setting.active.sites[window.location.hostname].defaultStretch = commandArguments;
} else {
this.settings.active.stretch.default = commandArguments;
}
this.settings.saveWithoutReload();
}
} }
} }
</script> </script>

View File

@ -140,6 +140,11 @@ const ExtensionConf: SettingsInterface = {
testRowOffset: 0.02 // we test this % of height from detected edge testRowOffset: 0.02 // we test this % of height from detected edge
} }
}, },
crop: {
default: {
type: AspectRatioType.Automatic,
}
},
zoom: { zoom: {
minLogZoom: -1, minLogZoom: -1,
maxLogZoom: 3, maxLogZoom: 3,
@ -152,6 +157,9 @@ const ExtensionConf: SettingsInterface = {
mousePanReverseMouse: false, mousePanReverseMouse: false,
}, },
stretch: { stretch: {
default: {
type: StretchType.NoStretch
},
conditionalDifferencePercent: 0.05 // black bars less than this wide will trigger stretch conditionalDifferencePercent: 0.05 // black bars less than this wide will trigger stretch
// if mode is set to '1'. 1.0=100% // if mode is set to '1'. 1.0=100%
}, },
@ -1360,9 +1368,9 @@ const ExtensionConf: SettingsInterface = {
// stretch? <stretch mode> // automatically stretch video on this site in this manner // stretch? <stretch mode> // automatically stretch video on this site in this manner
// videoAlignment? <left|center|right> // videoAlignment? <left|center|right>
// //
// type: <official|community|user> // 'official' — blessed by Tam. // type: <official|community|user-added> // 'official' — blessed by Tam.
// // 'community' — blessed by reddit. // // 'community' — blessed by people sending me messages.
// // 'user' — user-defined (not here) // // 'user-added' — user-defined (not here)
// override: <true|false> // override user settings for this site on update // override: <true|false> // override user settings for this site on update
// } // }
// //

View File

@ -11,6 +11,7 @@ import BrowserDetect from '../conf/BrowserDetect';
import Logger from './Logger'; import Logger from './Logger';
import SettingsInterface from '../../common/interfaces/SettingsInterface'; import SettingsInterface from '../../common/interfaces/SettingsInterface';
import { browser } from 'webextension-polyfill-ts'; import { browser } from 'webextension-polyfill-ts';
import AspectRatioType from '../../common/enums/AspectRatioType.enum';
if(process.env.CHANNEL !== 'stable'){ if(process.env.CHANNEL !== 'stable'){
console.info("Loading Settings"); console.info("Loading Settings");
@ -561,7 +562,7 @@ class Settings {
return this.active.miscSettings.defaultAr; return this.active.miscSettings.defaultAr;
} }
getDefaultStretchMode(site) { getDefaultStretchMode_legacy(site) {
if (site && (this.active.sites[site]?.stretch ?? StretchType.Default) !== StretchType.Default) { if (site && (this.active.sites[site]?.stretch ?? StretchType.Default) !== StretchType.Default) {
return this.active.sites[site].stretch; return this.active.sites[site].stretch;
} }
@ -585,6 +586,42 @@ class Settings {
return this.active.sites['@global'].videoAlignment; return this.active.sites['@global'].videoAlignment;
} }
/**
* Gets default site configuration. Only returns essential settings.
* @returns
*/
getDefaultSiteConfiguration() {
return {
type: 'user-added',
defaultCrop: {
type: AspectRatioType.Automatic, // AARD is enabled by default
},
defaultStretch: {
type: StretchType.NoStretch, // because we aren't uncultured savages
},
}
}
/**
* Gets default cropping mode for extension.
* Returns site default if defined, otherwise it returns extension default.
* If extension default is not defined because extension updated but the
* settings didn't port over, we return automatic.
*/
getDefaultCrop(site?: string) {
return this.active.sites[site ?? window.location.hostname]?.defaultCrop ?? this.active.crop?.default ?? {type: AspectRatioType.Automatic};
}
/**
* Gets default stretching mode for extension.
* Returns site default if defined, otherwise it returns extension default.
* If extension default is not defined because extension updated but the
* settings didn't port over, we return automatic.
*/
getDefaultStretchMode(site?: string) {
return this.active.sites[site ?? window.location.hostname]?.defaultStretch ?? this.active.stretch.default ?? {type: StretchType.NoStretch};
}
} }
export default Settings; export default Settings;

View File

@ -31,13 +31,13 @@ class Stretcher {
this.conf = videoData; this.conf = videoData;
this.logger = videoData.logger; this.logger = videoData.logger;
this.settings = videoData.settings; this.settings = videoData.settings;
this.mode = this.settings.getDefaultStretchMode(window.location.hostname); this.mode = this.settings.getDefaultStretchMode_legacy(window.location.hostname);
this.fixedStretchRatio = undefined; this.fixedStretchRatio = undefined;
} }
setStretchMode(stretchMode, fixedStretchRatio?) { setStretchMode(stretchMode, fixedStretchRatio?) {
if (stretchMode === StretchType.Default) { if (stretchMode === StretchType.Default) {
this.mode = this.settings.getDefaultStretchMode(window.location.hostname); this.mode = this.settings.getDefaultStretchMode_legacy(window.location.hostname);
} else { } else {
if (stretchMode === StretchType.Fixed || stretchMode == StretchType.FixedSource) { if (stretchMode === StretchType.Fixed || stretchMode == StretchType.FixedSource) {
this.fixedStretchRatio = fixedStretchRatio; this.fixedStretchRatio = fixedStretchRatio;