diff --git a/src/background.js b/src/background.js index 2a074336..5d0fd81a 100644 --- a/src/background.js +++ b/src/background.js @@ -6,7 +6,7 @@ import { deleteFile, deleteFolder, getFileFromUser, linkToFile, - newFileFromSidebar, newFolder, renameFileOrFolder, + newFileFromSidebar, newFolder, renameFileOrFolder, moveFileOrFolder, saveFile, saveToTarget, saveToPDFTarget, @@ -129,6 +129,9 @@ app.on('ready', async () => { ipcMain.on('renameFileOrFolder', (e, newPath, oldPath) => { renameFileOrFolder(newPath, oldPath) }) + ipcMain.on('move-file-or-folder', (e, srcPath, dstPath) => { + moveFileOrFolder(srcPath, dstPath) + }) ipcMain.on('newFileFromSidebar', (e, filePath, fileName) => { newFileFromSidebar(filePath, fileName) }) diff --git a/src/main/filesystem/fileManipulate.js b/src/main/filesystem/fileManipulate.js index aa3f9251..9a12a7c9 100644 --- a/src/main/filesystem/fileManipulate.js +++ b/src/main/filesystem/fileManipulate.js @@ -174,7 +174,7 @@ export const saveToPDFTarget = async (fileContent) => { * @param {string} srcPath 原文件/文件夹路径 * @param {string} destDir 目标文件夹 */ -export const move = async (srcPath, destDir) => { +export const moveFileOrFolder = async (srcPath, destDir) => { try { const fname = path.basename(srcPath) const targetPath = makeValidFilePath(path.resolve(destDir, fname)) diff --git a/src/main/filesystem/linkManager.js b/src/main/filesystem/linkManager.js index f55da870..4d6a4260 100644 --- a/src/main/filesystem/linkManager.js +++ b/src/main/filesystem/linkManager.js @@ -2,7 +2,7 @@ import path from 'path' import { addTagToDoc, getLinksInFile, removeTagFromDoc } from '../../common/parseLinks' import fs from 'fs-extra' import { isValidMarkdownFilePath } from '../helper/path' -import { deleteFolder, move } from '@/main/filesystem/fileManipulate' +import { deleteFolder, moveFileOrFolder } from '@/main/filesystem/fileManipulate' class LinkManager { /** * 管理tag和cites @@ -227,7 +227,7 @@ class LinkManager { for (const filename of filepaths) { const filepath = path.resolve(dirPath, filename) this.removeFile(filepath) - const newPath = await move(filepath, targetPath) + const newPath = await moveFileOrFolder(filepath, targetPath) this.addFile(newPath) this.win.webContents.send('set-file-path-by-move', { oldPath: filepath, newPath }) const doc = (await fs.promises.readFile(newPath)).toString() @@ -249,7 +249,7 @@ class LinkManager { const subItemPath = path.resolve(folderPath, subItem) if (isValidMarkdownFilePath(subItemPath)) { this.removeFile(subItemPath) - const newPath = await move(subItemPath, targetPath) + const newPath = await moveFileOrFolder(subItemPath, targetPath) this.addFile(newPath) this.win.webContents.send('set-file-path-by-move', { subItemPath, newPath }) const doc = (await fs.promises.readFile(newPath)).toString() diff --git a/src/main/preload.js b/src/main/preload.js index d01821fe..331fb767 100644 --- a/src/main/preload.js +++ b/src/main/preload.js @@ -22,6 +22,8 @@ contextBridge.exposeInMainWorld('electronAPI', { openFolder: () => ipcRenderer.send('open-folder'), openFolderByPath: (path) => ipcRenderer.send('open-folder-by-path', path), + moveFileOrFolder: (srcPath, dstPath) => ipcRenderer.send('move-file-or-folder', srcPath, dstPath), // TODO + saveFile: (path, content) => ipcRenderer.send('save-file', path, content), saveToAnotherFile: (content) => ipcRenderer.send('save-as', content), exportPDF: (html) => ipcRenderer.invoke('exportPDF', html), @@ -91,6 +93,7 @@ contextBridge.exposeInMainWorld('pathAPI', { join: path.join, relative: path.relative, basename: path.basename, + dirname: path.dirname, existSync: fs.pathExistsSync, isMarkdownExtname, sep: path.sep, diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 832b8808..04fb69cc 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -1,11 +1,11 @@