-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #28; frontend, backend: await ws connection
- Loading branch information
Showing
16 changed files
with
252 additions
and
123 deletions.
There are no files selected for viewing
File renamed without changes.
21 changes: 18 additions & 3 deletions
21
packages/frontend/.vscode/settings.json → packages/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
class VisibleError { | ||
overlay = $state<"" | "hidden">(""); | ||
readonly error = writable<false | { icon: string; text: string }>(false); | ||
|
||
solved = () => { | ||
this.error.set(false); | ||
this.overlay = "hidden"; | ||
}; | ||
|
||
offline = () => { | ||
this.error.set({ | ||
icon: "cloud_off", | ||
text: "Offline, please connect to the internet.", | ||
}); | ||
this.overlay = ""; | ||
}; | ||
|
||
unauthorized = () => { | ||
this.error.set({ | ||
icon: "warning", | ||
text: "Unauthorized, forwarding to setup.", | ||
}); | ||
this.overlay = ""; | ||
|
||
setTimeout(() => (location.href = "/setup"), 2000); | ||
}; | ||
} | ||
|
||
export const error = new VisibleError(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { openDB, type DBSchema, type IDBPDatabase } from "idb"; | ||
|
||
interface SettingsDB extends DBSchema { | ||
settings: { | ||
value: string; | ||
key: string; | ||
}; | ||
} | ||
|
||
class Settings { | ||
private database: () => IDBPDatabase<SettingsDB>; | ||
settings = $state<{ [index: string]: string | undefined }>({}); | ||
ready = $state(false); | ||
|
||
constructor() { | ||
this.database = () => { | ||
throw new Error("Database not initialized"); | ||
}; | ||
} | ||
|
||
init = async () => { | ||
const db = await this.openDatabase(); | ||
this.database = () => db; | ||
|
||
await this.getAll(); | ||
this.ready = true; | ||
}; | ||
|
||
private openDatabase = () => | ||
openDB<SettingsDB>("settings-store", 1, { | ||
upgrade(db) { | ||
db.createObjectStore("settings"); | ||
}, | ||
}); | ||
|
||
private get = async (key: string) => this.database().get("settings", key); | ||
|
||
set = async (key: string, val: string) => { | ||
await this.database().put("settings", val, key); | ||
this.settings[key] = val; | ||
}; | ||
|
||
clear = async () => this.database().clear("settings"); | ||
|
||
private keys = async () => this.database().getAllKeys("settings"); | ||
|
||
private getAll = async () => { | ||
const keys = await this.keys(); | ||
|
||
for (const key of keys) { | ||
const val = await this.get(key); | ||
if (val !== undefined) this.settings[key] = val; | ||
} | ||
}; | ||
} | ||
|
||
export const settings = new Settings(); |
Oops, something went wrong.