cummulative patching of settings
This commit is contained in:
parent
7ef8c21e63
commit
2de8d64b29
@ -1,8 +1,9 @@
|
|||||||
// How to use:
|
// How to use:
|
||||||
// version: {ExtensionConf object, but only properties that get overwritten}
|
// version: {ExtensionConf object, but only properties that get overwritten}
|
||||||
|
|
||||||
const ExtensionConfPatch = {
|
const ExtensionConfPatch = [
|
||||||
'4.2.0': {
|
{
|
||||||
|
forVersion: '4.2.0',
|
||||||
sites: {
|
sites: {
|
||||||
"old.reddit.com" : {
|
"old.reddit.com" : {
|
||||||
type: 'testing',
|
type: 'testing',
|
||||||
@ -38,7 +39,70 @@ const ExtensionConfPatch = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
}, {
|
||||||
}
|
forVersion: '4.2.3.1',
|
||||||
|
sites: {
|
||||||
|
"old.reddit.com" : {
|
||||||
|
type: 'testing',
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
querySelectors: '.media-preview-content, .reddit-video-player-root'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: '',
|
||||||
|
},
|
||||||
|
"www.reddit.com" : {
|
||||||
|
type: 'testing',
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
querySelectors: '.media-preview-content, .reddit-video-player-root'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: '',
|
||||||
|
},
|
||||||
|
"www.youtube.com" : {
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
querySelectors: "#movie_player, #player",
|
||||||
|
additionalCss: "",
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
playerNodeCss: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
forVersion: '4.3.0',
|
||||||
|
sites: {
|
||||||
|
"old.reddit.com" : {
|
||||||
|
type: 'testing',
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
querySelectors: '.reddit-video-player-root'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: '',
|
||||||
|
},
|
||||||
|
"www.reddit.com" : {
|
||||||
|
type: 'testing',
|
||||||
|
DOM: {
|
||||||
|
player: {
|
||||||
|
manual: true,
|
||||||
|
useRelativeAncestor: false,
|
||||||
|
querySelectors: '.reddit-video-player-root'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: '',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
export default ExtensionConfPatch;
|
export default ExtensionConfPatch;
|
@ -11,13 +11,18 @@ import ExtensionConfPatch from '../conf/ExtConfPatches';
|
|||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
|
|
||||||
constructor(activeSettings, updateCallback) {
|
constructor(options) {
|
||||||
|
// Options: activeSettings, updateCallback, logger
|
||||||
|
const activeSettings = options.activeSettings;
|
||||||
|
const updateCallback = options.updateCallback;
|
||||||
|
|
||||||
this.active = activeSettings ? activeSettings : undefined;
|
this.active = activeSettings ? activeSettings : undefined;
|
||||||
this.default = ExtensionConf;
|
this.default = ExtensionConf;
|
||||||
this.default['version'] = this.getExtensionVersion();
|
this.default['version'] = this.getExtensionVersion();
|
||||||
this.useSync = false;
|
this.useSync = false;
|
||||||
this.version = undefined;
|
this.version = undefined;
|
||||||
this.updateCallback = updateCallback;
|
this.updateCallback = updateCallback;
|
||||||
|
this.logger = options.logger;
|
||||||
|
|
||||||
const ths = this;
|
const ths = this;
|
||||||
|
|
||||||
@ -74,6 +79,50 @@ class Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compareExtensionVersions(a, b) {
|
||||||
|
aa = a.forVersion.split['.'];
|
||||||
|
bb = b.forVersion.split['.'];
|
||||||
|
|
||||||
|
if (+aa[0] !== +bb[0]) {
|
||||||
|
// difference on first digit
|
||||||
|
return ++aa[0] - ++bb[0];
|
||||||
|
} if (+aa[1] !== +bb[1]) {
|
||||||
|
// first digit same, difference on second digit
|
||||||
|
return ++aa[1] - ++bb[1];
|
||||||
|
} if (+aa[2] !== +bb[2]) {
|
||||||
|
return ++aa[2] - ++bb[2];
|
||||||
|
// first two digits the same, let's check the third digit
|
||||||
|
} else {
|
||||||
|
// fourth digit is optional. When not specified, 0 is implied
|
||||||
|
// btw, ++(aa[3] || 0) - ++(bb[3] || 0) doesn't work
|
||||||
|
return (aa[3] ? ++aa[3] : 0) - (bb[3] ? ++bb[3] : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sortConfPatches(patchesIn) {
|
||||||
|
return patchesIn.sort( (a, b) => this.compareExtensionVersions(a, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
findFirstNecessaryPatch(version, extconfPatches) {
|
||||||
|
const sorted = this.sortConfPatches(extconfPatches);
|
||||||
|
return sorted.findIndexOf(x => this.compareExtensionVersions(x.forVersion, version) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
applySettingsPatches(oldVersion, patches) {
|
||||||
|
let index = this.findFirstNecessaryPatch(oldVersion, patches);
|
||||||
|
if (index === -1) {
|
||||||
|
// this.logger.log('info','settings','[Settings::applySettingsPatches] There are no pending conf patches.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply all remaining patches
|
||||||
|
// this.logger.log('info', 'settings', `[Settings::applySettingsPatches] There are ${patches.length - index} settings patches to apply`);
|
||||||
|
while (index --< patches.length) {
|
||||||
|
delete patches[index].forVersion;
|
||||||
|
ObjectCopy.overwrite(this.active, patches[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
const settings = await this.get();
|
const settings = await this.get();
|
||||||
|
|
||||||
@ -146,9 +195,9 @@ class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in case settings in previous version contained a fucky wucky, we overwrite existing settings with a patch
|
// in case settings in previous version contained a fucky wucky, we overwrite existing settings with a patch
|
||||||
ObjectCopy.overwrite(this.active, ExtensionConfPatch['4.2.0']);
|
this.applySettingsPatches(oldVersion, ExtensionConfPatch);
|
||||||
|
|
||||||
// set 'whatsNewChecked' flag to false when updating
|
// set 'whatsNewChecked' flag to false when updating, always
|
||||||
this.active.whatsNewChecked = false;
|
this.active.whatsNewChecked = false;
|
||||||
// update settings version to current
|
// update settings version to current
|
||||||
this.active.version = currentVersion;
|
this.active.version = currentVersion;
|
||||||
|
Loading…
Reference in New Issue
Block a user