Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ browser.commands.onCommand.addListener(async (command) => {
}
});

SLStorage.convertFromSyncToLocal(SLStorage.SETTINGS.API_URL);
SLStorage.convertFromSyncToLocal(SLStorage.SETTINGS.API_KEY);
APIService.initService();
Onboarding.initService();
33 changes: 29 additions & 4 deletions src/popup/SLStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class SLStorage {
SL_BUTTON_POSITION: "SLButtonPosition",
};

static TYPES = {
apiUrl: "local",
apiKey: "local",
notAskingRate: "sync",
showSLButton: "sync",
SLButtonPosition: "sync",
};

static DEFAULT_SETTINGS = {
[SLStorage.SETTINGS.API_URL]: devConfig
? devConfig.DEFAULT_API_URL
Expand All @@ -22,12 +30,18 @@ class SLStorage {
[SLStorage.SETTINGS.SL_BUTTON_POSITION]: "right-inside",
};

static getType(key) {
return this.TYPES[key] || "local";
}

static set(key, value) {
return browser.storage.sync.set({ [key]: value });
const type = this.getType(key);
return browser.storage[type].set({ [key]: value });
}

static async get(key) {
const data = await browser.storage.sync.get(key);
const type = this.getType(key);
const data = await browser.storage[type].get(key);

if (data[key] === undefined || data[key] === null) {
return SLStorage.DEFAULT_SETTINGS[key] || "";
Expand All @@ -37,10 +51,12 @@ class SLStorage {
}

static remove(key) {
return browser.storage.sync.remove(key);
const type = this.getType(key);
return browser.storage[type].remove(key);
}

static clear() {
static async clear() {
await browser.storage.local.clear();
return browser.storage.sync.clear();
}

Expand All @@ -51,6 +67,15 @@ class SLStorage {
static getTemporary(key) {
return TEMP[key];
}

static async convertFromSyncToLocal(key) {
const data = await browser.storage.sync.get(key);
if (data[key]) {
await browser.storage.local
.set({ [key]: data[key] })
.then((_) => browser.storage.sync.remove(key));
}
}
}

export default SLStorage;