diff --git a/electron/main.cjs b/electron/main.cjs index fbb5333..9d04f21 100644 --- a/electron/main.cjs +++ b/electron/main.cjs @@ -475,9 +475,20 @@ ipcMain.handle('update-settings', (event, settings) => { return true }) -ipcMain.handle('pick-paths', async () => { +function pickDialogProperties(kind) { + if (kind === 'directories') { + return ['openDirectory', 'multiSelections'] + } + if (kind === 'mixed') { + return ['openFile', 'openDirectory', 'multiSelections'] + } + return ['openFile', 'multiSelections'] +} + +ipcMain.handle('pick-paths', async (event, options = {}) => { + const kind = typeof options?.kind === 'string' ? options.kind : 'files' const result = await dialog.showOpenDialog(mainWindow, { - properties: ['openFile', 'openDirectory', 'multiSelections'], + properties: pickDialogProperties(kind), }) return result.canceled ? [] : result.filePaths }) diff --git a/electron/preload.cjs b/electron/preload.cjs index 17fb860..2e47ca0 100644 --- a/electron/preload.cjs +++ b/electron/preload.cjs @@ -8,7 +8,7 @@ contextBridge.exposeInMainWorld('electronAPI', { checkForUpdates: () => ipcRenderer.invoke('check-for-updates'), setSetting: (key, value) => ipcRenderer.invoke('set-setting', key, value), updateSettings: (settings) => ipcRenderer.invoke('update-settings', settings), - pickPaths: () => ipcRenderer.invoke('pick-paths'), + pickPaths: (options = {}) => ipcRenderer.invoke('pick-paths', options), openPath: (filePath) => ipcRenderer.invoke('open-path', filePath), openExternalLink: (event) => { event.preventDefault(); diff --git a/src/LibraryManager.jsx b/src/LibraryManager.jsx index 78b6e7f..0fa9c87 100644 --- a/src/LibraryManager.jsx +++ b/src/LibraryManager.jsx @@ -121,19 +121,23 @@ export default function LibraryManager({ } } - async function addPaths() { + async function registerPaths(paths) { + await runAction(async () => { + const response = await fetch(`${apiBase}/libraries/${library.slug}/files/register`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ paths }) + }) + await expectOk(response) + }) + } + + async function addPaths(kind = 'files') { if (!library) return - const paths = await window.electronAPI?.pickPaths?.() + const paths = await window.electronAPI?.pickPaths?.({ kind }) if (!Array.isArray(paths) || paths.length === 0) return try { - await runAction(async () => { - const response = await fetch(`${apiBase}/libraries/${library.slug}/files/register`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ paths }) - }) - await expectOk(response) - }) + await registerPaths(paths) } catch (error) { setErrorMessage(String(error?.message || error)) } @@ -346,7 +350,8 @@ export default function LibraryManager({