diff --git a/src/config.ts b/src/config.ts index f528def2..2903c0fb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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() } }