feat(settings): add global autoplay mode preference (backend)
- Create PlaybackPreferences config module with SQLite persistence - Add AutoplayMode enum (ContinueWithinSource | PlayTrackOnly) - Register Tauri commands: get_playback_preferences, set_autoplay_mode - Create playbackPreferencesStore for frontend state management - Add loadPlaybackPreferences to SettingsView - Default: Continue within source (creates context on track click) - Settings UI pending (next commit) cp
This commit is contained in:
1 parent
515632913d
commit
dbdd664415
5 files changed
+276
No files matched your search
@@ -43,6 +43,11 @@
|
||||
type OfflineSettings
|
||||
} from '$lib/stores/offlineStore';
|
||||
import { showToast } from '$lib/stores/toastStore';
|
||||
import {
|
||||
getPlaybackPreferences,
|
||||
setAutoplayMode,
|
||||
type AutoplayMode
|
||||
} from '$lib/stores/playbackPreferencesStore';
|
||||
|
||||
interface Props {
|
||||
onBack?: () => void;
|
||||
@@ -310,6 +315,7 @@
|
||||
);
|
||||
|
||||
// Playback settings
|
||||
let autoplayMode = $state<AutoplayMode>('continue');
|
||||
let gaplessPlayback = $state(true);
|
||||
let crossfade = $state(0);
|
||||
let normalizeVolume = $state(false);
|
||||
@@ -417,6 +423,9 @@
|
||||
loadSystemNotificationsPreference();
|
||||
systemNotificationsEnabled = getSystemNotificationsEnabled();
|
||||
|
||||
// Load playback preferences
|
||||
loadPlaybackPreferences();
|
||||
|
||||
// Check for legacy downloads
|
||||
checkLegacyDownloads();
|
||||
|
||||
@@ -1101,6 +1110,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPlaybackPreferences() {
|
||||
try {
|
||||
const prefs = await getPlaybackPreferences();
|
||||
autoplayMode = prefs.autoplay_mode;
|
||||
} catch (err) {
|
||||
console.error('Failed to load playback preferences:', err);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAutoplayModeChange(mode: AutoplayMode) {
|
||||
try {
|
||||
await setAutoplayMode(mode);
|
||||
autoplayMode = mode;
|
||||
} catch (err) {
|
||||
console.error('Failed to set autoplay mode:', err);
|
||||
showToast('Failed to save autoplay preference', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function checkLegacyDownloads() {
|
||||
try {
|
||||
const result = await invoke<{has_legacy_files: boolean, total_tracks: number}>('detect_legacy_downloads');
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Playback Preferences Store
|
||||
*
|
||||
* Manages global playback behavior preferences (autoplay mode, etc.)
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
// ============ Types ============
|
||||
|
||||
export type AutoplayMode = 'continue' | 'track_only';
|
||||
|
||||
export interface PlaybackPreferences {
|
||||
autoplay_mode: AutoplayMode;
|
||||
}
|
||||
|
||||
// ============ State ============
|
||||
|
||||
let preferences: PlaybackPreferences = {
|
||||
autoplay_mode: 'continue'
|
||||
};
|
||||
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function notifyListeners(): void {
|
||||
for (const listener of listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Public API ============
|
||||
|
||||
/**
|
||||
* Get current playback preferences
|
||||
*/
|
||||
export async function getPlaybackPreferences(): Promise<PlaybackPreferences> {
|
||||
const prefs = await invoke<PlaybackPreferences>('get_playback_preferences');
|
||||
preferences = prefs;
|
||||
notifyListeners();
|
||||
return prefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set autoplay mode
|
||||
*/
|
||||
export async function setAutoplayMode(mode: AutoplayMode): Promise<void> {
|
||||
await invoke('set_autoplay_mode', { mode });
|
||||
preferences.autoplay_mode = mode;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached preferences (no backend call)
|
||||
*/
|
||||
export function getCachedPreferences(): PlaybackPreferences {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if autoplay is enabled (continue within source)
|
||||
*/
|
||||
export function isAutoplayEnabled(): boolean {
|
||||
return preferences.autoplay_mode === 'continue';
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to preference changes
|
||||
*/
|
||||
export function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize preferences store (call on app startup)
|
||||
*/
|
||||
export async function initPlaybackPreferences(): Promise<void> {
|
||||
await getPlaybackPreferences();
|
||||
}
|
||||
Reference in new issue
Block a user