mirror of
https://gitlab.com/ryzen-controller-team/ryzen-controller.git
synced 2024-12-22 10:03:28 +07:00
fix: Ensure storage upgrade path from any version to above.
This commit is contained in:
parent
13bcd78473
commit
2388d4b974
@ -11,9 +11,7 @@ function storageHaveCurrentVersion() {
|
|||||||
|
|
||||||
function getAllAvailableVersion() {
|
function getAllAvailableVersion() {
|
||||||
var keys = Object.keys(electronSettings.getAll());
|
var keys = Object.keys(electronSettings.getAll());
|
||||||
var versionAsRegex = isDev
|
var versionAsRegex = isDev ? /^\d*_\d*_\d*(-dev)$/ : /^\d*_\d*_\d*$/;
|
||||||
? /^\d*_\d*_\d*(-dev)$/
|
|
||||||
: /^\d*_\d*_\d*$/;
|
|
||||||
var validKeys = keys.filter((val, index) => {
|
var validKeys = keys.filter((val, index) => {
|
||||||
return versionAsRegex.test(val);
|
return versionAsRegex.test(val);
|
||||||
});
|
});
|
||||||
@ -32,42 +30,43 @@ function storageHasPreviousVersion() {
|
|||||||
function getPreviousVersion() {
|
function getPreviousVersion() {
|
||||||
var validKeys = getAllAvailableVersion();
|
var validKeys = getAllAvailableVersion();
|
||||||
const index = validKeys.indexOf(app_version_as_string);
|
const index = validKeys.indexOf(app_version_as_string);
|
||||||
return validKeys[index-1];
|
return validKeys[index - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade from any version to above.
|
||||||
|
*
|
||||||
|
* Just a copy from the previous version to the new one.
|
||||||
|
* Not executed if the previous version is a special case, see upgradeFromPreviousVersion() below.
|
||||||
|
*/
|
||||||
|
function from_any_copyStorage(previousVersion) {
|
||||||
|
electronSettings.set(`${app_version_as_string}`, electronSettings.get(previousVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade from 2.0.0 to above.
|
||||||
|
*
|
||||||
|
* Some of the storage was not under the version scope,
|
||||||
|
* We move those so the storage is more secure and consistent from version to version.
|
||||||
|
*/
|
||||||
function from_2_0_0_MoveAppContext(previousVersion) {
|
function from_2_0_0_MoveAppContext(previousVersion) {
|
||||||
electronSettings.set(
|
electronSettings.set(`${app_version_as_string}.appContext`, electronSettings.get(previousVersion));
|
||||||
`${app_version_as_string}.appContext`,
|
|
||||||
electronSettings.get(previousVersion)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function from_2_0_0_MoveLightMode() {
|
function from_2_0_0_MoveLightMode() {
|
||||||
electronSettings.set(
|
electronSettings.set(`${app_version_as_string}.lightMode`, electronSettings.get("lightMode"));
|
||||||
`${app_version_as_string}.lightMode`,
|
|
||||||
electronSettings.get("lightMode")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function from_2_0_0_MoveLocale() {
|
function from_2_0_0_MoveLocale() {
|
||||||
electronSettings.set(
|
electronSettings.set(`${app_version_as_string}.locale`, electronSettings.get("locale"));
|
||||||
`${app_version_as_string}.locale`,
|
|
||||||
electronSettings.get("locale")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function from_2_0_0_MoveReApplyPeriodically() {
|
function from_2_0_0_MoveReApplyPeriodically() {
|
||||||
electronSettings.set(
|
electronSettings.set(`${app_version_as_string}.reApplyPeriodically`, electronSettings.get("reApplyPeriodically"));
|
||||||
`${app_version_as_string}.reApplyPeriodically`,
|
|
||||||
electronSettings.get("reApplyPeriodically")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function from_2_0_0_MoveVotedPresets() {
|
function from_2_0_0_MoveVotedPresets() {
|
||||||
electronSettings.set(
|
electronSettings.set(`${app_version_as_string}.votedPresets`, electronSettings.get("votedPresets"));
|
||||||
`${app_version_as_string}.votedPresets`,
|
|
||||||
electronSettings.get("votedPresets")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgradeFromPreviousVersion() {
|
function upgradeFromPreviousVersion() {
|
||||||
isDev && console.log('Upgrading storage...');
|
if (isDev) console.log("Upgrading storage...");
|
||||||
const previousVersion = getPreviousVersion();
|
const previousVersion = getPreviousVersion();
|
||||||
switch (previousVersion) {
|
switch (previousVersion) {
|
||||||
case "2_0_0":
|
case "2_0_0":
|
||||||
@ -77,13 +76,13 @@ function upgradeFromPreviousVersion() {
|
|||||||
from_2_0_0_MoveLocale(previousVersion);
|
from_2_0_0_MoveLocale(previousVersion);
|
||||||
from_2_0_0_MoveReApplyPeriodically(previousVersion);
|
from_2_0_0_MoveReApplyPeriodically(previousVersion);
|
||||||
from_2_0_0_MoveVotedPresets(previousVersion);
|
from_2_0_0_MoveVotedPresets(previousVersion);
|
||||||
isDev && console.log('... from 2.0.0');
|
if (isDev) console.log("... from 2.0.0");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
from_any_copyStorage(previousVersion);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const upgrader = () => {
|
const upgrader = () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user