From bbc9b63357289da2e4e5f68c12ea58615020d238 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Wed, 16 Jun 2021 05:03:46 +0100 Subject: [PATCH] Main: Simplify `createWindow` function With the knowledge that the session is shared by all 'BrowserWindow's, proxy and cookie related logic can now be set once on startup and it's not necessary to set them again for every window created. --- src/main/index.js | 48 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 7703beef..e4344f66 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -132,9 +132,28 @@ function runApp() { app.commandLine.appendSwitch('enable-smooth-scrolling') } - const proxyUrl = `${proxyProtocol}://${proxyHostname}:${proxyPort}` + if (useProxy) { + session.defaultSession.setProxy({ + proxyRules: `${proxyProtocol}://${proxyHostname}:${proxyPort}` + }) + } - createWindow(useProxy, proxyUrl) + // Set CONSENT cookie on reasonable domains + const consentCookieDomains = [ + 'http://www.youtube.com', + 'https://www.youtube.com', + 'http://youtube.com', + 'https://youtube.com' + ] + consentCookieDomains.forEach(url => { + session.defaultSession.cookies.set({ + url: url, + name: 'CONSENT', + value: 'YES+' + }) + }) + + createWindow() if (isDev) { installDevTools() @@ -156,7 +175,7 @@ function runApp() { } } - function createWindow(useProxy = false, proxyUrl = '', replaceMainWindow = true) { + function createWindow(replaceMainWindow = true) { /** * Initial window options */ @@ -187,27 +206,6 @@ function runApp() { height: 800 }) - if (useProxy) { - session.defaultSession.setProxy({ - proxyRules: proxyUrl - }) - } - - // Set CONSENT cookie on reasonable domains - const consentCookieDomains = [ - 'http://www.youtube.com', - 'https://www.youtube.com', - 'http://youtube.com', - 'https://youtube.com' - ] - consentCookieDomains.forEach(url => { - session.defaultSession.cookies.set({ - url: url, - name: 'CONSENT', - value: 'YES+' - }) - }) - settingsDb.findOne({ _id: 'bounds' }, function (err, doc) { @@ -371,7 +369,7 @@ function runApp() { }) ipcMain.on('createNewWindow', () => { - createWindow(false, '', false) + createWindow(false) }) ipcMain.on('syncSetting', (event, setting) => {