mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
config.ts: Add config updater from version 0.0 to 1.0
This commit is contained in:
parent
d26e44d06b
commit
77cf277ab0
1 changed files with 22 additions and 21 deletions
|
@ -284,14 +284,25 @@ export async function save(storage: "local" | "sync" = get("storageloc")){
|
|||
}
|
||||
|
||||
/** Updates the config to the latest version. */
|
||||
export function update() {
|
||||
export async function update() {
|
||||
let updaters = {
|
||||
"0.0": async () => {
|
||||
try {
|
||||
// Before we had a config system, we had nmaps, and we put them in the
|
||||
// root namespace because we were young and bold.
|
||||
let legacy_nmaps = await browser.storage.sync.get("nmaps")
|
||||
if (legacy_nmaps) {
|
||||
USERCONFIG["nmaps"] = Object.assign(legacy_nmaps["nmaps"], USERCONFIG["nmaps"])
|
||||
}
|
||||
} finally {
|
||||
set("version", "1.0")
|
||||
}
|
||||
},
|
||||
}
|
||||
if (!get("version"))
|
||||
set("version", "0.0")
|
||||
while (updaters[get("version")] instanceof Function) {
|
||||
updaters[get("version")]()
|
||||
await updaters[get("version")]()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,25 +311,15 @@ export function update() {
|
|||
asynchronous calls generated by getAsync.
|
||||
*/
|
||||
async function init() {
|
||||
try {
|
||||
let syncConfig = await browser.storage.sync.get(CONFIGNAME)
|
||||
schlepp(syncConfig[CONFIGNAME])
|
||||
// Local storage overrides sync
|
||||
let localConfig = await browser.storage.local.get(CONFIGNAME)
|
||||
schlepp(localConfig[CONFIGNAME])
|
||||
|
||||
// Before we had a config system, we had nmaps, and we put them in the
|
||||
// root namespace because we were young and bold.
|
||||
let legacy_nmaps = await browser.storage.sync.get("nmaps")
|
||||
if (legacy_nmaps) {
|
||||
USERCONFIG["nmaps"] = Object.assign(legacy_nmaps["nmaps"], USERCONFIG["nmaps"])
|
||||
}
|
||||
} finally {
|
||||
update()
|
||||
INITIALISED = true
|
||||
for (let waiter of WAITERS) {
|
||||
waiter()
|
||||
}
|
||||
let syncConfig = await browser.storage.sync.get(CONFIGNAME)
|
||||
schlepp(syncConfig[CONFIGNAME])
|
||||
// Local storage overrides sync
|
||||
let localConfig = await browser.storage.local.get(CONFIGNAME)
|
||||
schlepp(localConfig[CONFIGNAME])
|
||||
await update()
|
||||
INITIALISED = true
|
||||
for (let waiter of WAITERS) {
|
||||
waiter()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue