客户端:附件支持选择文件夹

This commit is contained in:
街角小林 2024-08-28 09:33:14 +08:00
parent b438385cd6
commit cabb37c5b9
3 changed files with 11 additions and 6 deletions

View File

@ -128,9 +128,14 @@ export const bindFileHandleEvent = ({ mainWindow }) => {
})
// 选择本地文件
ipcMain.handle('selectFile', event => {
ipcMain.handle('selectFile', (event, openDirectory = false) => {
const properties = []
if (openDirectory) {
properties.push('openDirectory')
}
const res = dialog.showOpenDialogSync({
title: '选择'
title: '选择',
properties
})
if (res && res[0]) {
console.log(111, res[0])
@ -229,8 +234,8 @@ export const bindFileHandleEvent = ({ mainWindow }) => {
shell.showItemInFolder(file)
})
// 打开指定文件
ipcMain.handle('openPath', (event, file) => {
// 打开指定文件
ipcMain.handle('openPath', (event, file) => {
const exist = fs.existsSync(file)
if (!exist) {
return '文件不存在'

View File

@ -25,7 +25,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
openFile: file => ipcRenderer.invoke('openFile', file),
selectOpenFile: () => ipcRenderer.send('selectOpenFile'),
copyFile: file => ipcRenderer.invoke('copyFile', file),
selectFile: () => ipcRenderer.invoke('selectFile'),
selectFile: openDirectory => ipcRenderer.invoke('selectFile', openDirectory),
openPath: path => ipcRenderer.invoke('openPath', path),
saveClientConfig: config => ipcRenderer.invoke('saveClientConfig', config),
getClientConfig: () => ipcRenderer.invoke('getClientConfig')

View File

@ -70,7 +70,7 @@ export default {
// activeNodes.forEach(node => {
// node.setAttachment('/test.md', '')
// })
const file = await window.electronAPI.selectFile()
const file = await window.electronAPI.selectFile(true)
if (file) {
activeNodes.forEach(node => {
node.setAttachment(file.file, file.name)