mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 11:41:02 +00:00
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
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<DeviceSyncSettings> = writable(defaultSettings);
|
|
|
|
// Load settings from store
|
|
export async function loadDeviceSyncSettings(): Promise<void> {
|
|
const musicPath = await store.get<string>('musicPath');
|
|
const playlistsPath = await store.get<string>('playlistsPath');
|
|
const overwriteMode = await store.get<OverwriteMode>('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<void> {
|
|
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<void> {
|
|
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<void> {
|
|
await store.set('overwriteMode', mode);
|
|
await store.save();
|
|
|
|
deviceSyncSettings.update(s => ({
|
|
...s,
|
|
overwriteMode: mode
|
|
}));
|
|
}
|
|
|
|
// Initialize settings on import
|
|
loadDeviceSyncSettings();
|