feat(settings): add folder selection for music and playlists

Add UI and logic to select music and playlists folders in settings using
tauri dialog plugin. Integrate @tauri-apps/plugin-dialog, plugin-fs, and
plugin-store in both frontend and backend. Update capabilities and
dependencies to support new plugins. Improve settings page with folder
selectors and info note for better user experience.
This commit is contained in:
2025-09-30 18:58:52 -04:00
parent 792e81a6cf
commit a8f8e4602a
9 changed files with 476 additions and 4 deletions

View File

@@ -0,0 +1,74 @@
import { LazyStore } from '@tauri-apps/plugin-store';
import { writable, type Writable } from 'svelte/store';
// Settings interface
export interface AppSettings {
musicFolder: string | null;
playlistsFolder: string | null;
}
// Initialize the store with settings.json
const store = new LazyStore('settings.json');
// Default settings
const defaultSettings: AppSettings = {
musicFolder: null,
playlistsFolder: null
};
// Create a writable store for reactive UI updates
export const settings: Writable<AppSettings> = writable(defaultSettings);
// Load settings from store
export async function loadSettings(): Promise<void> {
const musicFolder = await store.get<string>('musicFolder');
const playlistsFolder = await store.get<string>('playlistsFolder');
settings.set({
musicFolder: musicFolder ?? null,
playlistsFolder: playlistsFolder ?? null
});
}
// Save music folder setting
export async function setMusicFolder(path: string | null): Promise<void> {
if (path) {
await store.set('musicFolder', path);
} else {
await store.delete('musicFolder');
}
await store.save();
settings.update(s => ({
...s,
musicFolder: path
}));
}
// Save playlists folder setting
export async function setPlaylistsFolder(path: string | null): Promise<void> {
if (path) {
await store.set('playlistsFolder', path);
} else {
await store.delete('playlistsFolder');
}
await store.save();
settings.update(s => ({
...s,
playlistsFolder: path
}));
}
// Get music folder setting
export async function getMusicFolder(): Promise<string | null> {
return await store.get<string>('musicFolder');
}
// Get playlists folder setting
export async function getPlaylistsFolder(): Promise<string | null> {
return await store.get<string>('playlistsFolder');
}
// Initialize settings on app start
loadSettings();