Files
radicle-explorer/src/lib/appearance.ts
T
Rūdolfs Ošiņš b3e212ff5b Load theme in top-level App.svelte
Previously the theme was only loaded when the <ThemeSettings> component
was loaded in the footer. This stopped working since we removed the
layout around the loading spinner.
2024-01-02 14:25:59 +00:00

51 lines
1.2 KiB
TypeScript

import { writable } from "svelte/store";
export type Theme = "dark" | "light";
export const theme = writable<Theme>(loadTheme());
export type CodeFont = "jetbrains" | "system";
export const codeFont = writable<CodeFont>(loadCodeFont());
export const codeFonts: {
storedName: CodeFont;
fontFamily: string;
displayName: string;
}[] = [
{
storedName: "jetbrains",
fontFamily: "JetBrains Mono",
displayName: "JetBrains Mono",
},
{ storedName: "system", fontFamily: "monospace", displayName: "System" },
];
function loadCodeFont(): CodeFont {
const storedCodeFont = window.localStorage.getItem("codefont");
if (storedCodeFont === null) {
return "jetbrains";
} else {
return storedCodeFont as CodeFont;
}
}
function loadTheme(): Theme {
const storedTheme = window.localStorage.getItem("theme");
if (storedTheme === null) {
return "dark";
} else {
return storedTheme as Theme;
}
}
export function storeTheme(newTheme: Theme): void {
theme.set(newTheme);
window.localStorage.setItem("theme", newTheme);
}
export function storeCodeFont(newCodeFont: CodeFont): void {
codeFont.set(newCodeFont);
window.localStorage.setItem("codefont", newCodeFont);
}