From f9ca1bd25ea95f1427496febc1b4c265db6f951b Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 16 Jan 2026 03:15:02 -0600 Subject: [PATCH] Add manual offline mode settings and disable import in offline mode - Disable import playlists button when offline (shows disabled state) - Add Cast, immediate scrobbling, and accumulated scrobbling toggles - These settings only appear when manual offline mode is enabled - Add time limit note for accumulated scrobbling (Last.fm 2 week limit) - Persist new settings in SQLite with proper migrations - Add i18n strings for all new settings (en/es) --- src-tauri/src/lib.rs | 3 + src-tauri/src/offline/mod.rs | 87 +++++++++++++++++++- src/lib/components/Sidebar.svelte | 17 +++- src/lib/components/views/SettingsView.svelte | 80 +++++++++++++++++- src/lib/i18n/locales/en.json | 9 +- src/lib/i18n/locales/es.json | 9 +- src/lib/stores/offlineStore.ts | 48 +++++++++++ 7 files changed, 245 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f2e30012e..3a2032cf7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -513,6 +513,9 @@ pub fn run() { offline::commands::get_offline_settings, offline::commands::set_manual_offline, offline::commands::set_show_partial_playlists, + offline::commands::set_allow_cast_while_offline, + offline::commands::set_allow_immediate_scrobbling, + offline::commands::set_allow_accumulated_scrobbling, offline::commands::check_network, // Offline playlist sync queue commands offline::commands::create_pending_playlist, diff --git a/src-tauri/src/offline/mod.rs b/src-tauri/src/offline/mod.rs index c2d8b04bf..a135c4aea 100644 --- a/src-tauri/src/offline/mod.rs +++ b/src-tauri/src/offline/mod.rs @@ -37,6 +37,12 @@ pub struct OfflineStatus { pub struct OfflineSettings { pub manual_offline_mode: bool, pub show_partial_playlists: bool, + /// Allow Chromecast while in manual offline mode + pub allow_cast_while_offline: bool, + /// Allow immediate scrobbling to Last.fm in manual offline mode + pub allow_immediate_scrobbling: bool, + /// Queue scrobbles for later submission when back online + pub allow_accumulated_scrobbling: bool, } /// A playlist created offline, pending sync to Qobuz @@ -88,10 +94,13 @@ impl OfflineStore { "CREATE TABLE IF NOT EXISTS offline_settings ( id INTEGER PRIMARY KEY CHECK (id = 1), manual_offline_mode INTEGER NOT NULL DEFAULT 0, - show_partial_playlists INTEGER NOT NULL DEFAULT 1 + show_partial_playlists INTEGER NOT NULL DEFAULT 1, + allow_cast_while_offline INTEGER NOT NULL DEFAULT 0, + allow_immediate_scrobbling INTEGER NOT NULL DEFAULT 0, + allow_accumulated_scrobbling INTEGER NOT NULL DEFAULT 1 ); - INSERT OR IGNORE INTO offline_settings (id, manual_offline_mode, show_partial_playlists) - VALUES (1, 0, 1); + INSERT OR IGNORE INTO offline_settings (id, manual_offline_mode, show_partial_playlists, allow_cast_while_offline, allow_immediate_scrobbling, allow_accumulated_scrobbling) + VALUES (1, 0, 1, 0, 0, 1); CREATE TABLE IF NOT EXISTS pending_playlist_sync ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -117,18 +126,28 @@ impl OfflineStore { CREATE INDEX IF NOT EXISTS idx_scrobble_queue_sent ON scrobble_queue(sent);" ).map_err(|e| format!("Failed to create offline settings table: {}", e))?; + // Migration: Add new columns if they don't exist (for existing databases) + let _ = conn.execute_batch( + "ALTER TABLE offline_settings ADD COLUMN allow_cast_while_offline INTEGER NOT NULL DEFAULT 0; + ALTER TABLE offline_settings ADD COLUMN allow_immediate_scrobbling INTEGER NOT NULL DEFAULT 0; + ALTER TABLE offline_settings ADD COLUMN allow_accumulated_scrobbling INTEGER NOT NULL DEFAULT 1;" + ); + Ok(Self { conn }) } pub fn get_settings(&self) -> Result { self.conn .query_row( - "SELECT manual_offline_mode, show_partial_playlists FROM offline_settings WHERE id = 1", + "SELECT manual_offline_mode, show_partial_playlists, allow_cast_while_offline, allow_immediate_scrobbling, allow_accumulated_scrobbling FROM offline_settings WHERE id = 1", [], |row| { Ok(OfflineSettings { manual_offline_mode: row.get::<_, i64>(0)? != 0, show_partial_playlists: row.get::<_, i64>(1)? != 0, + allow_cast_while_offline: row.get::<_, i64>(2)? != 0, + allow_immediate_scrobbling: row.get::<_, i64>(3)? != 0, + allow_accumulated_scrobbling: row.get::<_, i64>(4)? != 0, }) }, ) @@ -155,6 +174,36 @@ impl OfflineStore { Ok(()) } + pub fn set_allow_cast_while_offline(&self, enabled: bool) -> Result<(), String> { + self.conn + .execute( + "UPDATE offline_settings SET allow_cast_while_offline = ?1 WHERE id = 1", + params![enabled as i64], + ) + .map_err(|e| format!("Failed to set allow cast while offline: {}", e))?; + Ok(()) + } + + pub fn set_allow_immediate_scrobbling(&self, enabled: bool) -> Result<(), String> { + self.conn + .execute( + "UPDATE offline_settings SET allow_immediate_scrobbling = ?1 WHERE id = 1", + params![enabled as i64], + ) + .map_err(|e| format!("Failed to set allow immediate scrobbling: {}", e))?; + Ok(()) + } + + pub fn set_allow_accumulated_scrobbling(&self, enabled: bool) -> Result<(), String> { + self.conn + .execute( + "UPDATE offline_settings SET allow_accumulated_scrobbling = ?1 WHERE id = 1", + params![enabled as i64], + ) + .map_err(|e| format!("Failed to set allow accumulated scrobbling: {}", e))?; + Ok(()) + } + // === Pending Playlist Sync Methods === /// Create a new pending playlist (created while offline) @@ -473,6 +522,36 @@ pub mod commands { store.set_show_partial_playlists(enabled) } + /// Set whether to allow Chromecast while in manual offline mode + #[tauri::command] + pub fn set_allow_cast_while_offline( + enabled: bool, + state: State<'_, OfflineState>, + ) -> Result<(), String> { + let store = state.store.lock().map_err(|e| format!("Lock error: {}", e))?; + store.set_allow_cast_while_offline(enabled) + } + + /// Set whether to allow immediate scrobbling to Last.fm in manual offline mode + #[tauri::command] + pub fn set_allow_immediate_scrobbling( + enabled: bool, + state: State<'_, OfflineState>, + ) -> Result<(), String> { + let store = state.store.lock().map_err(|e| format!("Lock error: {}", e))?; + store.set_allow_immediate_scrobbling(enabled) + } + + /// Set whether to queue scrobbles for later submission when back online + #[tauri::command] + pub fn set_allow_accumulated_scrobbling( + enabled: bool, + state: State<'_, OfflineState>, + ) -> Result<(), String> { + let store = state.store.lock().map_err(|e| format!("Lock error: {}", e))?; + store.set_allow_accumulated_scrobbling(enabled) + } + /// Check if network connectivity is available #[tauri::command] pub async fn check_network() -> bool { diff --git a/src/lib/components/Sidebar.svelte b/src/lib/components/Sidebar.svelte index 1f03c01b1..364e8ac35 100644 --- a/src/lib/components/Sidebar.svelte +++ b/src/lib/components/Sidebar.svelte @@ -511,7 +511,12 @@ {$t('actions.refresh')} - @@ -794,6 +799,16 @@ color: var(--accent-primary); } + .menu-item.disabled { + opacity: 0.4; + cursor: not-allowed; + } + + .menu-item.disabled:hover { + background: none; + color: var(--text-secondary); + } + .menu-item.has-submenu { position: relative; } diff --git a/src/lib/components/views/SettingsView.svelte b/src/lib/components/views/SettingsView.svelte index 234d8e45b..847d62a43 100644 --- a/src/lib/components/views/SettingsView.svelte +++ b/src/lib/components/views/SettingsView.svelte @@ -34,6 +34,9 @@ getSettings as getOfflineSettings, setManualOffline, setShowPartialPlaylists, + setAllowCastWhileOffline, + setAllowImmediateScrobbling, + setAllowAccumulatedScrobbling, checkNetwork, type OfflineStatus, type OfflineSettings @@ -695,6 +698,30 @@ } } + async function handleAllowCastChange(enabled: boolean) { + try { + await setAllowCastWhileOffline(enabled); + } catch (error) { + console.error('Failed to set allow cast while offline:', error); + } + } + + async function handleAllowImmediateScrobblingChange(enabled: boolean) { + try { + await setAllowImmediateScrobbling(enabled); + } catch (error) { + console.error('Failed to set allow immediate scrobbling:', error); + } + } + + async function handleAllowAccumulatedScrobblingChange(enabled: boolean) { + try { + await setAllowAccumulatedScrobbling(enabled); + } catch (error) { + console.error('Failed to set allow accumulated scrobbling:', error); + } + } + async function handleLanguageChange(lang: string) { language = lang; const localeCode = languageToLocale[lang]; @@ -1136,13 +1163,39 @@ -
+
{$t('offline.showPartialPlaylists')} {$t('offline.showPartialPlaylistsDesc')}
+ + + {#if offlineSettings.manualOfflineMode} +
+
+ {$t('offline.allowCast')} + {$t('offline.allowCastDesc')} +
+ +
+
+
+ {$t('offline.allowImmediateScrobbling')} + {$t('offline.allowImmediateScrobblingDesc')} +
+ +
+
+
+ {$t('offline.allowAccumulatedScrobbling')} + {$t('offline.allowAccumulatedScrobblingDesc')} + {$t('offline.scrobbleTimeLimit')} +
+ +
+ {/if} @@ -1768,6 +1821,31 @@ color: var(--text-muted); } + .setting-info { + display: flex; + flex-direction: column; + gap: 2px; + flex: 1; + } + + .setting-desc { + font-size: 12px; + color: var(--text-muted); + } + + .setting-note { + font-size: 11px; + color: var(--text-muted); + opacity: 0.8; + margin-top: 4px; + } + + .setting-row:has(.setting-note) { + height: auto; + min-height: 48px; + padding: 12px 0; + } + .setting-value { font-size: 14px; color: var(--text-muted); diff --git a/src/lib/i18n/locales/en.json b/src/lib/i18n/locales/en.json index 151d655c3..6b3564d77 100644 --- a/src/lib/i18n/locales/en.json +++ b/src/lib/i18n/locales/en.json @@ -450,7 +450,14 @@ "available": "Available Offline", "partiallyAvailable": "Partially Available", "notAvailableOffline": "Not Available Offline", - "viewOnly": "View Only (Offline)" + "viewOnly": "View Only (Offline)", + "allowCast": "Allow Chromecast", + "allowCastDesc": "Enable Chromecast streaming while in manual offline mode", + "allowImmediateScrobbling": "Immediate Scrobbling", + "allowImmediateScrobblingDesc": "Send scrobbles to Last.fm immediately while in manual offline mode", + "allowAccumulatedScrobbling": "Accumulated Scrobbling", + "allowAccumulatedScrobblingDesc": "Queue scrobbles for later when back online", + "scrobbleTimeLimit": "Last.fm accepts scrobbles up to 2 weeks old" }, "filter": { "all": "All" diff --git a/src/lib/i18n/locales/es.json b/src/lib/i18n/locales/es.json index 4040a7409..326a4de12 100644 --- a/src/lib/i18n/locales/es.json +++ b/src/lib/i18n/locales/es.json @@ -450,7 +450,14 @@ "available": "Disponible Offline", "partiallyAvailable": "Parcialmente Disponible", "notAvailableOffline": "No Disponible Offline", - "viewOnly": "Solo Ver (Offline)" + "viewOnly": "Solo Ver (Offline)", + "allowCast": "Permitir Chromecast", + "allowCastDesc": "Habilitar streaming por Chromecast en modo offline manual", + "allowImmediateScrobbling": "Scrobbling Inmediato", + "allowImmediateScrobblingDesc": "Enviar scrobbles a Last.fm inmediatamente en modo offline manual", + "allowAccumulatedScrobbling": "Scrobbling Acumulado", + "allowAccumulatedScrobblingDesc": "Almacenar scrobbles para enviar cuando vuelvas a estar en linea", + "scrobbleTimeLimit": "Last.fm acepta scrobbles de hasta 2 semanas de antiguedad" }, "filter": { "all": "Todos" diff --git a/src/lib/stores/offlineStore.ts b/src/lib/stores/offlineStore.ts index d3aa87ce0..f8eaaae6d 100644 --- a/src/lib/stores/offlineStore.ts +++ b/src/lib/stores/offlineStore.ts @@ -33,6 +33,9 @@ export interface OfflineStatus { export interface OfflineSettings { manualOfflineMode: boolean; showPartialPlaylists: boolean; + allowCastWhileOffline: boolean; + allowImmediateScrobbling: boolean; + allowAccumulatedScrobbling: boolean; } // Store state @@ -45,6 +48,9 @@ let status: OfflineStatus = { let settings: OfflineSettings = { manualOfflineMode: false, showPartialPlaylists: true, + allowCastWhileOffline: false, + allowImmediateScrobbling: false, + allowAccumulatedScrobbling: true, }; let initialized = false; @@ -188,6 +194,48 @@ export async function setShowPartialPlaylists(enabled: boolean): Promise { } } +/** + * Set whether to allow Chromecast while in manual offline mode + */ +export async function setAllowCastWhileOffline(enabled: boolean): Promise { + try { + await invoke('set_allow_cast_while_offline', { enabled }); + settings.allowCastWhileOffline = enabled; + notifyListeners(); + } catch (error) { + console.error('Failed to set allow cast while offline:', error); + throw error; + } +} + +/** + * Set whether to allow immediate scrobbling to Last.fm in manual offline mode + */ +export async function setAllowImmediateScrobbling(enabled: boolean): Promise { + try { + await invoke('set_allow_immediate_scrobbling', { enabled }); + settings.allowImmediateScrobbling = enabled; + notifyListeners(); + } catch (error) { + console.error('Failed to set allow immediate scrobbling:', error); + throw error; + } +} + +/** + * Set whether to queue scrobbles for later submission when back online + */ +export async function setAllowAccumulatedScrobbling(enabled: boolean): Promise { + try { + await invoke('set_allow_accumulated_scrobbling', { enabled }); + settings.allowAccumulatedScrobbling = enabled; + notifyListeners(); + } catch (error) { + console.error('Failed to set allow accumulated scrobbling:', error); + throw error; + } +} + /** * Force refresh of offline status */