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

View File

@ -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) => {