frontend: change storage value naming scheme

This commit is contained in:
hippoz 2022-05-05 21:30:21 +03:00
parent 144877e682
commit 06e081d785
No known key found for this signature in database
GPG key ID: 7C52899193467641
6 changed files with 15 additions and 14 deletions

View file

@ -2,11 +2,11 @@ import { fade, fly } from "svelte/transition";
import { getItem } from "./storage"; import { getItem } from "./storage";
export function maybeFly(...e) { export function maybeFly(...e) {
if (getItem("doAnimations")) if (getItem("app:behavior:doAnimations"))
return fly(...e); return fly(...e);
} }
export function maybeFade(...e) { export function maybeFade(...e) {
if (getItem("doAnimations")) if (getItem("app:behavior:doAnimations"))
return fade(...e); return fade(...e);
} }

View file

@ -15,12 +15,12 @@ export function useAuthHandlers() {
export function authWithToken(token, shouldUpdate=false) { export function authWithToken(token, shouldUpdate=false) {
if (shouldUpdate) if (shouldUpdate)
setItem("token", token); setItem("auth:token", token);
gateway.init(token); gateway.init(token);
} }
export function logOut() { export function logOut() {
removeItem("token"); removeItem("auth:token");
gateway.close(); gateway.close();
gateway.dispatch(GatewayEventType.BadAuth, -1); gateway.dispatch(GatewayEventType.BadAuth, -1);
} }

View file

@ -54,8 +54,8 @@ export default {
this.dispatch(GatewayEventType.BadAuth, 0); this.dispatch(GatewayEventType.BadAuth, 0);
return false; return false;
} }
log(`connecting to gateway - gatewayBase: ${getItem("gatewayBase")}`); log(`connecting to gateway - gatewayBase: ${getItem("server:gatewayBase")}`);
this.ws = new WebSocket(getItem("gatewayBase")); this.ws = new WebSocket(getItem("server:gatewayBase"));
this.ws.onopen = () => { this.ws.onopen = () => {
if (this.reconnectTimeout) { if (this.reconnectTimeout) {
clearTimeout(this.reconnectTimeout); clearTimeout(this.reconnectTimeout);

View file

@ -11,7 +11,7 @@ window.__waffle = {
init(); init();
initResponsiveHandlers(); initResponsiveHandlers();
useAuthHandlers(); useAuthHandlers();
authWithToken(getItem("token")); authWithToken(getItem("auth:token"));
// Remove loading screen // Remove loading screen
const loadingElement = document.getElementById("pre--loading-screen"); const loadingElement = document.getElementById("pre--loading-screen");

View file

@ -14,7 +14,7 @@ export default async function(method, endpoint, auth=true, body=null) {
} }
if (auth) { if (auth) {
const token = getItem("token"); const token = getItem("auth:token");
if (token) { if (token) {
options.headers = { options.headers = {
...options.headers || {}, ...options.headers || {},

View file

@ -1,8 +1,8 @@
const defaults = { const defaults = {
apiBase: `${window.location.origin}/api/v1`, "server:apiBase": `${window.location.origin}/api/v1`,
gatewayBase: `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`, "server:gatewayBase": `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`,
doAnimations: true, "auth:token": "",
token: "", "app:behavior:doAnimations": true,
"loggingSink:Gateway": false, "loggingSink:Gateway": false,
"loggingSink:Store": false "loggingSink:Store": false
}; };
@ -37,12 +37,13 @@ export function init() {
try { try {
store.set(key, typeof defaultValue === "string" ? override : JSON.parse(override)); store.set(key, typeof defaultValue === "string" ? override : JSON.parse(override));
} catch (o_O) { } catch (o_O) {
console.warn("[Storage]", `init(): An exception was thrown while parsing the value of key "${key}" from _persistentProvider`, o_O); console.warn("[Storage]", `init(): An exception was thrown while parsing the value of key "${key}" from persistentProvider. The key "${key}" will be removed from persistentProvider.`, o_O);
persistentProvider.removeItem(key);
} }
} }
}); });
} }
export function apiRoute(fragment) { export function apiRoute(fragment) {
return `${getItem("apiBase")}/${fragment}` return `${getItem("server:apiBase")}/${fragment}`
} }