feat: enhance locations and download categorization

- Fix system proxy fetching logic in download queue
- Expand recognized file formats across Windows, Mac, and Linux
- Automatically assign matching category folder for new downloads
- Add backend command to instantly create category directories on bulk base path selection
This commit is contained in:
NimBold
2026-06-15 18:21:44 +03:30
parent d15e537916
commit 12761caf10
7 changed files with 82 additions and 24 deletions
+7
View File
@@ -415,6 +415,13 @@ export const AddDownloadsModal = () => {
if (active && firstReadyIndex !== null) {
setSelectedItemIndex(firstReadyIndex);
const firstFile = updatedItems[firstReadyIndex].file;
if (firstFile) {
const category = categoryForFileName(firstFile);
const settingsStore = useSettingsStore.getState();
const categoryDir = (settingsStore.downloadDirectories && settingsStore.downloadDirectories[category]) || settingsStore.defaultDownloadPath || '~/Downloads';
setSaveLocation(categoryDir);
}
}
}, 400);
+25 -8
View File
@@ -137,14 +137,31 @@ export default function SettingsView() {
});
if (base && typeof base === 'string') {
const cleanBase = base.replace(/\/$/, '');
settings.setCategoryDirectory('Musics', `${cleanBase}/Musics`);
settings.setCategoryDirectory('Movies', `${cleanBase}/Movies`);
settings.setCategoryDirectory('Compressed', `${cleanBase}/Compressed`);
settings.setCategoryDirectory('Documents', `${cleanBase}/Documents`);
settings.setCategoryDirectory('Pictures', `${cleanBase}/Pictures`);
settings.setCategoryDirectory('Applications', `${cleanBase}/Applications`);
settings.setCategoryDirectory('Other', `${cleanBase}/Other`);
showToast("Updated all categories to use base folder");
const paths = [
`${cleanBase}/Musics`,
`${cleanBase}/Movies`,
`${cleanBase}/Compressed`,
`${cleanBase}/Documents`,
`${cleanBase}/Pictures`,
`${cleanBase}/Applications`,
`${cleanBase}/Other`
];
settings.setCategoryDirectory('Musics', paths[0]);
settings.setCategoryDirectory('Movies', paths[1]);
settings.setCategoryDirectory('Compressed', paths[2]);
settings.setCategoryDirectory('Documents', paths[3]);
settings.setCategoryDirectory('Pictures', paths[4]);
settings.setCategoryDirectory('Applications', paths[5]);
settings.setCategoryDirectory('Other', paths[6]);
try {
await invoke('create_category_directories', { paths });
} catch (e) {
console.error("Failed to create directories on disk:", e);
}
showToast("Updated and created all category folders at base");
}
} catch (e) {
console.error("Failed to browse base path:", e);
+1
View File
@@ -93,6 +93,7 @@ type CommandMap = {
db_get_all_queues: { args: undefined; result: string[] };
db_save_queue: { args: { id: string; data: string }; result: void };
db_delete_queue: { args: { id: string }; result: void };
create_category_directories: { args: { paths: string[] }; result: void };
};
type CommandName = keyof CommandMap;
+11 -4
View File
@@ -8,8 +8,15 @@ import { useSettingsStore } from './useSettingsStore';
export type { DownloadCategory } from '../utils/downloads';
const getProxyArgs = (settings: ReturnType<typeof useSettingsStore.getState>) => {
if (settings.proxyMode === 'system') return 'system';
const getProxyArgs = async (settings: ReturnType<typeof useSettingsStore.getState>) => {
if (settings.proxyMode === 'system') {
try {
return await invoke('get_system_proxy');
} catch (e) {
console.warn("Failed to get system proxy:", e);
return null;
}
}
if (settings.proxyMode === 'custom' && settings.proxyHost) {
return `http://${settings.proxyHost}:${settings.proxyPort}`;
}
@@ -420,7 +427,7 @@ export const useDownloadStore = create<DownloadState>((set, get) => ({
username: item.username || (login ? login.username : null),
password: item.password || keychainPassword,
headers: item.headers || null,
proxy: getProxyArgs(settings),
proxy: await getProxyArgs(settings),
userAgent: settings.customUserAgent || null,
maxTries: settings.maxAutomaticRetries
});
@@ -440,7 +447,7 @@ export const useDownloadStore = create<DownloadState>((set, get) => ({
mirrors: item.mirrors || null,
userAgent: settings.customUserAgent || null,
maxTries: settings.maxAutomaticRetries,
proxy: getProxyArgs(settings)
proxy: await getProxyArgs(settings)
});
}
} catch (e) {
+6 -6
View File
@@ -19,12 +19,12 @@ const MEDIA_DOMAINS = [
export const categoryForFileName = (fileName: string): DownloadCategory => {
const ext = fileName.split('.').pop()?.toLowerCase() || '';
if (['mp4', 'mkv', 'avi', 'mov', 'wmv', 'flv', 'webm', 'm4v'].includes(ext)) return 'Movies';
if (['mp3', 'wav', 'aac', 'flac', 'ogg', 'm4a', 'wma'].includes(ext)) return 'Musics';
if (['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf'].includes(ext)) return 'Documents';
if (['exe', 'dmg', 'apk', 'app', 'pkg', 'deb', 'rpm', 'msi', 'iso', 'bin', 'run'].includes(ext)) return 'Applications';
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tiff', 'svg'].includes(ext)) return 'Pictures';
if (['zip', 'rar', '7z', 'tar', 'gz', 'xz', 'bz2'].includes(ext)) return 'Compressed';
if (['mp4', 'mkv', 'avi', 'mov', 'wmv', 'flv', 'webm', 'm4v', 'mpeg', 'mpg', '3gp', 'ts', 'vob'].includes(ext)) return 'Movies';
if (['mp3', 'wav', 'aac', 'flac', 'ogg', 'm4a', 'wma', 'alac', 'ape', 'mid', 'midi'].includes(ext)) return 'Musics';
if (['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'rtf', 'csv', 'md', 'epub', 'mobi', 'azw3'].includes(ext)) return 'Documents';
if (['exe', 'msi', 'bat', 'cmd', 'app', 'dmg', 'pkg', 'apk', 'appx', 'deb', 'rpm', 'appimage', 'run', 'sh', 'bin', 'jar'].includes(ext)) return 'Applications';
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'tiff', 'svg', 'ico', 'heic', 'raw', 'psd', 'ai'].includes(ext)) return 'Pictures';
if (['zip', 'rar', '7z', 'tar', 'gz', 'xz', 'bz2', 'lz', 'lzma', 'zst', 'iso', 'cab', 'tgz', 'tbz', 'z', 'sit', 'sitx'].includes(ext)) return 'Compressed';
return 'Other';
};