From 89f467a23829f9d6017414c6b00be9c7ba5a84a4 Mon Sep 17 00:00:00 2001 From: "583641232@qq.com" <583641232@qq.com> Date: Tue, 9 Jul 2024 14:35:32 +0800 Subject: [PATCH] :sparkles: go --- main.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 96480aa..3f3d609 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,7 @@ function createWindow () { mainWindow.loadFile('./dist/index.html') // Open the DevTools. - // mainWindow.webContents.openDevTools() + mainWindow.webContents.openDevTools() mainWindow.on('close', e => { const choice = dialog.showMessageBoxSync(mainWindow, { @@ -36,7 +36,7 @@ function createWindow () { }) const leave = choice === 0; if (!leave) { - + clearCache(mainWindow) } else { // 点击取消按钮 e.preventDefault(); @@ -48,6 +48,14 @@ function createWindow () { }) } +/** +  * @description 清除缓存 +  */ +function clearCache(mainWindow) { + // 在窗口即将关闭时清除 localStorage 和 sessionStorage + mainWindow.webContents.executeJavaScript('localStorage.clear();') + mainWindow.webContents.executeJavaScript('sessionStorage.clear();') +} // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs.