use storage api

This commit is contained in:
Thomas Rupprecht 2022-12-25 02:56:18 +01:00
parent fc2ad7afad
commit 6b69d7cd6a
3 changed files with 9 additions and 7 deletions

View File

@ -45,7 +45,7 @@ async function fetchNewData() {
await browser.browserAction.setBadgeText({text: badgeText});
await browser.browserAction.setBadgeBackgroundColor({color: badgeBgColor});
const spaceApi = JSON.parse(localStorage.getItem('spaceApi'));
const {spaceApi} = await browser.storage.local.get('spaceApi');
if (spaceApi && spaceApi.state.open !== spaceApiJson.state.open) {
const state = browser.i18n.getMessage(spaceApiJson.state.open ? 'open' : 'closed');
await browser.notifications.create('status-change', {
@ -57,8 +57,10 @@ async function fetchNewData() {
}
}
localStorage.setItem('calendar', JSON.stringify(calendarJson));
localStorage.setItem('spaceApi', JSON.stringify(spaceApiJson));
await browser.storage.local.set({
calendar: calendarJson,
spaceApi: spaceApiJson,
});
} catch (error) {
console.error(error);
}

View File

@ -20,8 +20,9 @@
"default_locale": "de",
"permissions": [
"https://www.usrspace.at/*",
"webRequest",
"notifications"
"notifications",
"storage",
"webRequest"
],
"author": "Thomas Rupprecht",
"homepage_url": "https://gitea.usrspace.at/XimeX/usrspace-browser-addon",

View File

@ -49,8 +49,7 @@ async function init() {
linkElement.addEventListener('click', linkElementClickListener);
});
const calendar = JSON.parse(localStorage.getItem('calendar'));
const spaceApi = JSON.parse(localStorage.getItem('spaceApi'));
const {calendar, spaceApi} = await browser.storage.local.get(['calendar', 'spaceApi']);
if (calendar) {
updateNextEvent(calendar);