From bceab435b7ddc7c330c6ab27b74a7c01c18c5b08 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Wed, 16 Jun 2021 05:08:48 +0100 Subject: [PATCH] Main: Move session data cleanup to `window-all-closed` event Since the session is shared by all 'BrowserWindow's and it can be accessed without a window reference, it's best to clear data when the 'window-all-closed' event is emitted. --- src/main/index.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index e4344f661..c44040c43 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -260,25 +260,6 @@ function runApp() { newWindow.focus() }) - newWindow.on('close', () => { - // Clear cache and storage if it's the last window - if (openedWindows.length === 1) { - session.defaultSession.clearCache() - session.defaultSession.clearStorageData({ - storages: [ - 'appcache', - 'cookies', - 'filesystem', - 'indexdb', - 'shadercache', - 'websql', - 'serviceworkers', - 'cachestorage' - ] - }) - } - }) - newWindow.on('closed', () => { // Remove closed window openedWindows = openedWindows.filter((window) => window !== newWindow) @@ -388,6 +369,21 @@ function runApp() { }) app.on('window-all-closed', () => { + // Clear cache and storage if it's the last window + session.defaultSession.clearCache() + session.defaultSession.clearStorageData({ + storages: [ + 'appcache', + 'cookies', + 'filesystem', + 'indexdb', + 'shadercache', + 'websql', + 'serviceworkers', + 'cachestorage' + ] + }) + if (process.platform !== 'darwin') { app.quit() }