fix(menu): make Clear Recent Files actually clear the list

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
This commit is contained in:
2026-08-23 19:31:33 +05:30
parent bf3438902b
commit 5d9c46afc3
+15 -6
View File
@@ -731,7 +731,12 @@ function buildRecentFilesMenu() {
{ {
label: 'Clear Recent Files', label: 'Clear Recent Files',
click: () => { 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 // IPC handlers for recent files
ipcMain.on('save-recent-files', (event, recentFiles) => { ipcMain.on('save-recent-files', (event, recentFiles) => {
try { try {
@@ -4479,11 +4492,7 @@ ipcMain.on('save-recent-files', (event, recentFiles) => {
}); });
ipcMain.on('clear-recent-files', (event) => { ipcMain.on('clear-recent-files', (event) => {
try { try {
const userDataPath = app.getPath('userData'); clearRecentFilesOnDisk();
const recentFilesPath = path.join(userDataPath, 'recent-files.json');
fs.writeFileSync(recentFilesPath, JSON.stringify([], null, 2));
// Rebuild menu to reflect changes
createMenu();
event.reply('recent-files-cleared'); event.reply('recent-files-cleared');
} catch (error) { } catch (error) {
console.error('Error clearing recent files:', error); console.error('Error clearing recent files:', error);