主进程实现代码:
/**
-
打开文件选择框
-
@param oldPath - 上一次打开的路径
*/
const openFileDialog = async (oldPath: string = app.getPath(‘downloads’)) => {
if (!win) return oldPath
const { canceled, filePaths } = await dialog.showOpenDialog(win, {
title: ‘选择保存位置’,
properties: [‘openDirectory’, ‘createDirectory’],
defaultPath: oldPath,
})
return !canceled ? filePaths[0] : oldPath
}
ipcMain.handle(‘openFileDialog’, (event, oldPath?: string) => openFileDialog(oldPath))
渲染进程代码:
const path = await ipcRenderer.invoke(‘openFileDialog’, ‘PATH’)
3.2 暂停/恢复和取消
================
拿到