feat: add settings persistence via localStorage
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
|||||||
|
import {
|
||||||
|
serverUrl, quality, clips, spread, shortSide, portraitRatio,
|
||||||
|
format, hwEncode, profile, subprofiles
|
||||||
|
} from "./stores";
|
||||||
|
import { setServer } from "./api";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
|
const KEY = "8cut-settings";
|
||||||
|
|
||||||
|
interface Settings {
|
||||||
|
serverUrl: string;
|
||||||
|
quality: string;
|
||||||
|
clips: number;
|
||||||
|
spread: number;
|
||||||
|
shortSide: number | null;
|
||||||
|
portraitRatio: string | null;
|
||||||
|
format: string;
|
||||||
|
hwEncode: boolean;
|
||||||
|
profile: string;
|
||||||
|
subprofiles: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveSettings() {
|
||||||
|
const data: Settings = {
|
||||||
|
serverUrl: get(serverUrl),
|
||||||
|
quality: get(quality),
|
||||||
|
clips: get(clips),
|
||||||
|
spread: get(spread),
|
||||||
|
shortSide: get(shortSide),
|
||||||
|
portraitRatio: get(portraitRatio),
|
||||||
|
format: get(format),
|
||||||
|
hwEncode: get(hwEncode),
|
||||||
|
profile: get(profile),
|
||||||
|
subprofiles: get(subprofiles),
|
||||||
|
};
|
||||||
|
localStorage.setItem(KEY, JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadSettings() {
|
||||||
|
const raw = localStorage.getItem(KEY);
|
||||||
|
if (!raw) return;
|
||||||
|
try {
|
||||||
|
const data: Settings = JSON.parse(raw);
|
||||||
|
if (data.serverUrl) {
|
||||||
|
serverUrl.set(data.serverUrl);
|
||||||
|
setServer(data.serverUrl);
|
||||||
|
}
|
||||||
|
if (data.quality) quality.set(data.quality);
|
||||||
|
if (data.clips) clips.set(data.clips);
|
||||||
|
if (data.spread) spread.set(data.spread);
|
||||||
|
if (data.shortSide !== undefined) shortSide.set(data.shortSide);
|
||||||
|
if (data.portraitRatio !== undefined) portraitRatio.set(data.portraitRatio);
|
||||||
|
if (data.format) format.set(data.format);
|
||||||
|
if (data.hwEncode !== undefined) hwEncode.set(data.hwEncode);
|
||||||
|
if (data.profile) profile.set(data.profile);
|
||||||
|
if (data.subprofiles) subprofiles.set(data.subprofiles);
|
||||||
|
} catch { /* ignore corrupt settings */ }
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
import { mpvStart, mpvLoad, mpvSeek, mpvPause, mpvResume, mpvSetLoop, mpvClearLoop, mpvTimePos, mpvDuration } from "$lib/mpv";
|
import { mpvStart, mpvLoad, mpvSeek, mpvPause, mpvResume, mpvSetLoop, mpvClearLoop, mpvTimePos, mpvDuration } from "$lib/mpv";
|
||||||
import { streamUrl, audioUrl, deleteExport, getMarkers } from "$lib/api";
|
import { streamUrl, audioUrl, deleteExport, getMarkers } from "$lib/api";
|
||||||
import { connectExportWs } from "$lib/ws";
|
import { connectExportWs } from "$lib/ws";
|
||||||
|
import { loadSettings, saveSettings } from "$lib/settings";
|
||||||
import {
|
import {
|
||||||
currentFile, cursor, duration, playPos, playing, quality,
|
currentFile, cursor, duration, playPos, playing, quality,
|
||||||
clips, spread, locked, markers, profile, clipSpan, subprofiles
|
clips, spread, locked, markers, profile, clipSpan, subprofiles
|
||||||
@@ -16,6 +17,8 @@
|
|||||||
let exportPanelRef: ExportPanel;
|
let exportPanelRef: ExportPanel;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
await mpvStart();
|
await mpvStart();
|
||||||
connectExportWs();
|
connectExportWs();
|
||||||
|
|
||||||
@@ -27,6 +30,16 @@
|
|||||||
} catch { /* mpv not ready */ }
|
} catch { /* mpv not ready */ }
|
||||||
}
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
|
// Auto-save settings on changes
|
||||||
|
const unsubs = [
|
||||||
|
quality.subscribe(() => saveSettings()),
|
||||||
|
clips.subscribe(() => saveSettings()),
|
||||||
|
spread.subscribe(() => saveSettings()),
|
||||||
|
profile.subscribe(() => saveSettings()),
|
||||||
|
subprofiles.subscribe(() => saveSettings()),
|
||||||
|
];
|
||||||
|
return () => unsubs.forEach(u => u());
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user