Skip to content

Commit

Permalink
Make sure that cookies are saved to disk when closing the app
Browse files Browse the repository at this point in the history
  • Loading branch information
yuya-oc committed May 4, 2018
1 parent 59e2e7e commit aa37cfb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import allowProtocolDialog from './main/allowProtocolDialog';
import PermissionManager from './main/PermissionManager';
import permissionRequestHandler from './main/permissionRequestHandler';
import AppStateManager from './main/AppStateManager';
import initCookieManager from './main/cookieManager';

import SpellChecker from './main/SpellChecker';

Expand Down Expand Up @@ -423,6 +424,8 @@ app.on('ready', () => {
}
}

initCookieManager(session.defaultSession);

mainWindow = createMainWindow(config, {
hideOnStartup,
linuxAppIcon: path.join(assetsDir, 'appicon.png'),
Expand Down
22 changes: 22 additions & 0 deletions src/main/cookieManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {app} from 'electron';

function flushCookiesStore(session) {
session.cookies.flushStore((err) => {
if (err) {
console.log(err);
}
});
}

export default function initCookieManager(session) {
// Somehow cookies are not immediately saved to disk.
// So flush cookie store to disk manually.
// https://github.com/electron/electron/issues/8416
app.on('before-quit', () => {
flushCookiesStore(session);
});

app.on('browser-window-blur', () => {
flushCookiesStore(session);
});
}

0 comments on commit aa37cfb

Please sign in to comment.