diff --git a/src/lib/components/views/SettingsView.svelte b/src/lib/components/views/SettingsView.svelte index 0fadde0f8..b0699bb74 100644 --- a/src/lib/components/views/SettingsView.svelte +++ b/src/lib/components/views/SettingsView.svelte @@ -169,6 +169,7 @@ // Library settings let fetchQobuzArtistImages = $state(true); let showQobuzDownloadsInLibrary = $state(false); + let downloadRoot = $state(''); // Last.fm integration state let lastfmConnected = $state(false); @@ -673,11 +674,67 @@ try { const settings = await invoke<{download_root: string, show_in_library: boolean}>('get_download_settings'); showQobuzDownloadsInLibrary = settings.show_in_library; + downloadRoot = settings.download_root; } catch (err) { console.error('Failed to load download settings:', err); } } + async function handleChangeDownloadFolder() { + try { + const { open } = await import('@tauri-apps/plugin-dialog'); + + const result = await open({ + title: 'Select Downloads Folder', + directory: true, + defaultPath: downloadRoot || undefined + }); + + if (result) { + // Validate the path + const valid = await invoke('validate_download_path', { path: result }); + if (!valid) { + alert('Invalid path or insufficient permissions. Please select a different folder.'); + return; + } + + // Ask if user wants to move existing downloads + const hasDownloads = downloadStats && downloadStats.readyTracks > 0; + let moveFiles = false; + + if (hasDownloads) { + moveFiles = confirm( + `You have ${downloadStats!.readyTracks} downloaded tracks.\n\n` + + 'Would you like to move them to the new location?\n\n' + + 'Click OK to move files, or Cancel to keep them in the old location.' + ); + } + + // Update download root + const moveResult = await invoke<{moved: number, failed: string[]}>('set_download_root', { + path: result, + moveExisting: moveFiles + }); + + downloadRoot = result; + + if (moveFiles && moveResult.moved > 0) { + alert(`Successfully moved ${moveResult.moved} tracks to the new location.`); + } + + if (moveResult.failed.length > 0) { + console.error('Failed to move files:', moveResult.failed); + } + + // Reload download stats + await loadDownloadStats(); + } + } catch (err) { + console.error('Failed to change download folder:', err); + alert(`Failed to change download folder: ${err}`); + } + } + async function handleClearDownloads() { if (isClearingDownloads) return; isClearingDownloads = true; @@ -893,10 +950,32 @@ + +
+

Downloads

+
+
+ Download Folder + {downloadRoot || 'Default location'} +
+ +
+
+
+ Show in Local Library + Display downloaded Qobuz tracks in your Local Library +
+ +
+
+

{$t('settings.library.title')}

-
+
{$t('settings.library.fetchArtistImages')} {$t('settings.library.fetchArtistImagesDesc')} @@ -906,13 +985,6 @@ localStorage.setItem('qbz-fetch-artist-images', String(v)); }} />
-
-
- Show Qobuz Downloads in Local Library - Display downloaded Qobuz tracks in your Local Library -
- -