From 5d9c46afc33f42d5b2da37f242af012eaf59b7a1 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Sun, 23 Aug 2026 08:30:31 +0530 Subject: [PATCH] fix(menu): make Clear Recent Files actually clear the list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the recent-files.json deletion logic into a standalone clearRecentFilesOnDisk() function and call it from both the menu click handler and the ipcMain.on handler. Previously the menu sent the message in the wrong direction (main→renderer instead of renderer→main), causing the feature to silently no-op. Both paths now use the same function and send the correct 'recent-files-cleared' notification to keep the renderer in sync. Amit Haridas --- src/main.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.js b/src/main.js index 86df24e..c12970c 100644 --- a/src/main.js +++ b/src/main.js @@ -731,7 +731,12 @@ function buildRecentFilesMenu() { { label: 'Clear Recent Files', click: () => { - mainWindow.webContents.send('clear-recent-files'); + try { + clearRecentFilesOnDisk(); + mainWindow.webContents.send('recent-files-cleared'); + } catch (error) { + console.error('Error clearing recent files:', error); + } }, }, ]; @@ -4467,6 +4472,14 @@ app.on('activate', () => { } }); +// Clear recent files from disk +function clearRecentFilesOnDisk() { + const userDataPath = app.getPath('userData'); + const recentFilesPath = path.join(userDataPath, 'recent-files.json'); + fs.writeFileSync(recentFilesPath, JSON.stringify([], null, 2)); + createMenu(); +} + // IPC handlers for recent files ipcMain.on('save-recent-files', (event, recentFiles) => { try { @@ -4479,11 +4492,7 @@ ipcMain.on('save-recent-files', (event, recentFiles) => { }); ipcMain.on('clear-recent-files', (event) => { try { - const userDataPath = app.getPath('userData'); - const recentFilesPath = path.join(userDataPath, 'recent-files.json'); - fs.writeFileSync(recentFilesPath, JSON.stringify([], null, 2)); - // Rebuild menu to reflect changes - createMenu(); + clearRecentFilesOnDisk(); event.reply('recent-files-cleared'); } catch (error) { console.error('Error clearing recent files:', error);