mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 19:51:01 +00:00
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:
74
src/lib/stores/settings.ts
Normal file
74
src/lib/stores/settings.ts
Normal 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();
|
||||
Reference in New Issue
Block a user