This commit is contained in:
Lyz Coote
2026-02-02 18:41:13 +01:00
commit d6a5cb8a67
161 changed files with 8630 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
import { browser } from "$app/environment";
import type { EMLy_GUI_Settings } from "$lib/types";
import { getFromLocalStorage, saveToLocalStorage } from "$lib/utils/localStorageHelper";
const STORAGE_KEY = "emly_gui_settings";
const defaults: EMLy_GUI_Settings = {
selectedLanguage: "en",
useBuiltinPreview: true,
previewFileSupportedTypes: ["jpg", "jpeg", "png"],
};
class SettingsStore {
settings = $state<EMLy_GUI_Settings>({ ...defaults });
hasHydrated = $state(false);
constructor() {
if (browser) {
this.load();
}
}
load() {
const stored = getFromLocalStorage(STORAGE_KEY);
if (stored) {
try {
this.settings = { ...this.settings, ...JSON.parse(stored) };
} catch (e) {
console.error("Failed to load settings", e);
}
}
this.hasHydrated = true;
}
save() {
if (!browser) return;
saveToLocalStorage(STORAGE_KEY, JSON.stringify(this.settings));
}
update(newSettings: Partial<EMLy_GUI_Settings>) {
this.settings = { ...this.settings, ...newSettings };
this.save();
}
reset() {
this.settings = { ...defaults };
this.save();
}
}
export const settingsStore = new SettingsStore();