import { LazyStore } from '@tauri-apps/plugin-store'; import { writable, type Writable } from 'svelte/store'; // Device sync settings interface export type OverwriteMode = 'skip' | 'different' | 'always'; export interface DeviceSyncSettings { musicPath: string | null; playlistsPath: string | null; overwriteMode: OverwriteMode; } // Initialize the store with device-sync.json const store = new LazyStore('device-sync.json'); // Default settings const defaultSettings: DeviceSyncSettings = { musicPath: null, playlistsPath: null, overwriteMode: 'different' }; // Create a writable store for reactive UI updates export const deviceSyncSettings: Writable = writable(defaultSettings); // Load settings from store export async function loadDeviceSyncSettings(): Promise { const musicPath = await store.get('musicPath'); const playlistsPath = await store.get('playlistsPath'); const overwriteMode = await store.get('overwriteMode'); deviceSyncSettings.set({ musicPath: musicPath ?? null, playlistsPath: playlistsPath ?? null, overwriteMode: overwriteMode ?? 'different' }); } // Save device music path setting export async function setMusicPath(path: string | null): Promise { if (path) { await store.set('musicPath', path); } else { await store.delete('musicPath'); } await store.save(); deviceSyncSettings.update(s => ({ ...s, musicPath: path })); } // Save device playlists path setting export async function setPlaylistsPath(path: string | null): Promise { if (path) { await store.set('playlistsPath', path); } else { await store.delete('playlistsPath'); } await store.save(); deviceSyncSettings.update(s => ({ ...s, playlistsPath: path })); } // Save overwrite mode setting export async function setOverwriteMode(mode: OverwriteMode): Promise { await store.set('overwriteMode', mode); await store.save(); deviceSyncSettings.update(s => ({ ...s, overwriteMode: mode })); } // Initialize settings on import loadDeviceSyncSettings();