From a668da05a179851b2a1117ef2d6aa9cef48d4964 Mon Sep 17 00:00:00 2001 From: David Welch Date: Wed, 25 Nov 2020 19:38:18 +0000 Subject: [PATCH] Increase the maximum number of URLs queued. The number of URLs queued is restricted to ~60 because the queue is stored as a single item and is therefore is restricted to 8k. Instead store each URLs as a separate item with a name 'qi'+number and gather them into a single array when loading/storing. --- source/utilities/settings.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/source/utilities/settings.ts b/source/utilities/settings.ts index 0f2f17f..665d4c9 100644 --- a/source/utilities/settings.ts +++ b/source/utilities/settings.ts @@ -24,9 +24,17 @@ const defaultSettings: Settings = { * Returns the user's settings. */ export async function getSettings(): Promise { - const syncSettings: any = await browser.storage.sync.get(defaultSettings); + const syncSettings: any = await browser.storage.sync.get(); - const queue: QItem[] = syncSettings.queue; + // Append properties with a name matching 'qi'x to queue. + const queue: QItem[] = []; + if (syncSettings !== undefined) { + for (const prop in syncSettings) { + if (prop.startsWith('qi')) { + queue.push(syncSettings[prop]); + } + } + } // Initialize all the non-JSON values, as they are stringified when saved. for (const item of queue) { @@ -34,9 +42,10 @@ export async function getSettings(): Promise { } const settings: Settings = { - latestVersion: syncSettings.latestVersion, + latestVersion: syncSettings.latestVersion ?? defaultSettings.latestVersion, queue, - versionGotUpdated: syncSettings.versionGotUpdated + versionGotUpdated: + syncSettings.versionGotUpdated ?? defaultSettings.versionGotUpdated }; return settings; @@ -47,7 +56,15 @@ export async function getSettings(): Promise { * @param settings The settings to save. */ export async function saveSettings(settings: Settings): Promise { - await browser.storage.sync.set(settings); + const syncSettings: any = { + latestVersion: settings.latestVersion, + versionGotUpdated: settings.versionGotUpdated + }; + for (const item of settings.queue) { + syncSettings['qi' + item.id.toString()] = item; + } + + await browser.storage.sync.set(syncSettings); return settings; } @@ -84,7 +101,8 @@ export async function removeQItem( } settings.queue.splice(index, 1); - return saveSettings(settings); + await browser.storage.sync.remove('qi' + id.toString()); + return settings; } /**