feat: more dynamic settings system

This commit is contained in:
not-nullptr 2025-02-08 22:17:46 +00:00
parent 64ab1288f4
commit 35e98a5971
5 changed files with 22 additions and 14 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -7,24 +7,32 @@
import { RefreshCwIcon, SaveAllIcon } from "lucide-svelte"; import { RefreshCwIcon, SaveAllIcon } from "lucide-svelte";
import { onMount } from "svelte"; import { onMount } from "svelte";
let filenameFormat = "VERT_%name%"; // let filenameFormat = "VERT_%name%";
let settings = $state({
filenameFormat: "VERT_%name%",
});
function save() { function save() {
log(["settings"], "Saving settings"); log(["settings"], "saving settings");
if (!browser) return; if (!browser) return;
try { try {
localStorage.setItem("filenameFormat", filenameFormat); localStorage.setItem("settings", JSON.stringify(settings));
log(["settings"], `Saving filename format: ${filenameFormat}`); addToast("success", "settings saved!");
addToast("success", "Settings saved!");
} catch (error) { } catch (error) {
log(["settings", "error"], `Failed to save settings: ${error}`); log(["settings", "error"], `failed to save settings: ${error}`);
addToast("error", "Failed to save settings!"); addToast("error", "Failed to save settings!");
} }
} }
onMount(() => { onMount(() => {
const format = localStorage.getItem("filenameFormat"); const savedSettings = localStorage.getItem("settings");
if (format) filenameFormat = format; if (savedSettings) {
const parsedSettings = JSON.parse(savedSettings);
settings = {
...settings,
...parsedSettings,
};
}
}); });
</script> </script>
@ -59,7 +67,7 @@
</div> </div>
<FancyTextInput <FancyTextInput
placeholder="VERT_%name%" placeholder="VERT_%name%"
bind:value={filenameFormat} bind:value={settings.filenameFormat}
extension=".ext" extension=".ext"
type="text" type="text"
/> />

View File

@ -186,8 +186,8 @@ class Files {
const blob = await downloadZip(dlFiles, "converted.zip").blob(); const blob = await downloadZip(dlFiles, "converted.zip").blob();
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const filenameFormat = const settings = JSON.parse(localStorage.getItem("settings") ?? "{}");
localStorage.getItem("filenameFormat") ?? "VERT_%name%"; const filenameFormat = settings.filenameFormat ?? "VERT_%name%";
const format = (name: string) => { const format = (name: string) => {
const date = new Date().toISOString(); const date = new Date().toISOString();

View File

@ -57,8 +57,8 @@ export class VertFile {
public async download() { public async download() {
if (!this.result) throw new Error("No result found"); if (!this.result) throw new Error("No result found");
const filenameFormat = const settings = JSON.parse(localStorage.getItem("settings") ?? "{}");
localStorage.getItem("filenameFormat") ?? "VERT_%name%"; const filenameFormat = settings.filenameFormat ?? "VERT_%name%";
const format = (name: string) => { const format = (name: string) => {
const date = new Date().toISOString(); const date = new Date().toISOString();

View File

@ -52,7 +52,7 @@
const cachedContribs = sessionStorage.getItem("ghContribs"); const cachedContribs = sessionStorage.getItem("ghContribs");
if (cachedContribs) { if (cachedContribs) {
ghContribs = JSON.parse(cachedContribs); ghContribs = JSON.parse(cachedContribs);
log(["about"], "Loaded GitHub contributors from cache"); log(["about"], "loaded GitHub contributors from cache");
return; return;
} }