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.
This commit is contained in:
Svallinn 2021-06-16 05:08:48 +01:00
parent bbc9b63357
commit bceab435b7
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
1 changed files with 15 additions and 19 deletions

View File

@ -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()
}