diff --git a/main.js b/main.js index b2287ae..c7725fa 100644 --- a/main.js +++ b/main.js @@ -195,16 +195,15 @@ function switchActiveFile(filePath) { // IPC Handlers // Save file to a specific path with watcher management -function saveToPath(filePath, content) { +async function saveToPath(filePath, content) { stopWatching(); try { isSelfWriting = true; - fs.writeFileSync(filePath, content, 'utf-8'); - // 写入后短暂延迟再恢复监听,让 fs.watch 错过自身写入的事件 + await fs.promises.writeFile(filePath, content, 'utf-8'); isSelfWriting = false; } catch (err) { isSelfWriting = false; - startWatching(activeFilePath); // Restore watcher on failure + startWatching(activeFilePath); return { success: false, error: err.message }; } activeFilePath = filePath; @@ -250,7 +249,7 @@ ipcMain.handle('file:read', async (event, filePath) => { ipcMain.handle('file:save', async (event, { filePath, content }) => { try { if (filePath) { - return saveToPath(filePath, content); + return await saveToPath(filePath, content); } else { const result = await dialog.showSaveDialog(mainWindow, { filters: [ @@ -258,7 +257,7 @@ ipcMain.handle('file:save', async (event, { filePath, content }) => { ] }); if (!result.canceled) { - return saveToPath(result.filePath, content); + return await saveToPath(result.filePath, content); } return { success: false, canceled: true }; } @@ -275,7 +274,7 @@ ipcMain.handle('file:saveAs', async (event, { content }) => { ] }); if (!result.canceled) { - return saveToPath(result.filePath, content); + return await saveToPath(result.filePath, content); } return { success: false, canceled: true }; } catch (err) { diff --git a/package.json b/package.json index 98ec914..3129efe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marklite", - "version": "1.2.0", + "version": "1.2.1", "description": "Lightweight Markdown Reader for Windows", "main": "main.js", "scripts": { diff --git a/renderer/index.html b/renderer/index.html index 9913871..e6e7b71 100644 --- a/renderer/index.html +++ b/renderer/index.html @@ -112,6 +112,7 @@