Files
Quick-Ling/app/composables/useSettings.ts
T

50 lines
983 B
TypeScript

import { ref, onMounted } from "vue";
const STORAGE_KEY = "quick-ling-settings";
const DEFAULT_MODEL = "translategemma:4b";
interface Settings {
model: string;
}
const model = ref(DEFAULT_MODEL);
function loadSettings(): void {
if (typeof localStorage !== "undefined") {
try {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored) {
const parsed: Settings = JSON.parse(stored);
if (parsed.model) {
model.value = parsed.model;
}
}
} catch {
// ignore parse errors
}
}
}
function saveSettings(): void {
if (typeof localStorage !== "undefined") {
const settings: Settings = { model: model.value };
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
}
}
export function useSettings() {
function setModel(newModel: string): void {
model.value = newModel;
saveSettings();
}
onMounted(() => {
loadSettings();
});
return {
model,
setModel,
};
}