fix: handle localStorage being undefined

This commit is contained in:
Derrick Hammer 2023-08-10 02:11:50 -04:00
parent 842383a5db
commit 0ab6cf0ff0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 2 deletions

View File

@ -120,11 +120,17 @@ export function savePortals() {
url: item.portalUrl, url: item.portalUrl,
} as Portal; } as Portal;
}); });
window.localStorage.setItem("portals", JSON.stringify(portals)); if (typeof globalThis.localStorage !== "undefined") {
globalThis.localStorage.setItem("portals", JSON.stringify(portals));
}
} }
export function loadSavedPortals(): Portal[] | null { export function loadSavedPortals(): Portal[] | null {
let portals = window.localStorage.getItem("portals"); let portals: string | null = null;
if (typeof globalThis.localStorage !== "undefined") {
portals = globalThis.localStorage.getItem("portals");
}
if (!portals) { if (!portals) {
return null; return null;