refs #1542 Set proxy config for BrowserWindow

This commit is contained in:
AkiraFukushima 2020-06-30 01:08:18 +09:00
parent e52b29b363
commit 87303ba457
1 changed files with 24 additions and 13 deletions

View File

@ -297,10 +297,6 @@ async function createWindow() {
mainWindowState.manage(mainWindow)
mainWindow.loadURL(winURL)
mainWindow.webContents.on('will-navigate', event => event.preventDefault())
/**
* Get system proxy configuration.
*/
@ -310,6 +306,17 @@ async function createWindow() {
log.info(`System proxy configuration: ${proxyInfo}`)
}
/**
* Set proxy for BrowserWindow
*/
const proxyConfig = await proxyConfiguration.forMastodon()
if (proxyConfig) {
await mainWindow.webContents.session.setProxy({ proxyRules: `${proxyConfig.protocol}://${proxyConfig.host}:${proxyConfig.port}` })
}
mainWindow.loadURL(winURL)
mainWindow.webContents.on('will-navigate', event => event.preventDefault())
mainWindow.on('closed', () => {
mainWindow = null
})
@ -1042,18 +1049,22 @@ ipcMain.on('get-global-header', (event: IpcMainEvent) => {
})
// proxy
ipcMain.on('update-proxy-config', (event: IpcMainEvent, proxy: Proxy) => {
ipcMain.on('update-proxy-config', async (event: IpcMainEvent, proxy: Proxy) => {
const preferences = new Preferences(preferencesDBPath)
preferences
.update({
try {
const conf = await preferences.update({
proxy: proxy
})
.then(conf => {
event.sender.send('response-update-proxy-config', conf)
})
.catch(err => {
log.error(err)
})
const proxyConfig = await proxyConfiguration.forMastodon()
if (proxyConfig) {
await mainWindow?.webContents.session.setProxy({ proxyRules: `${proxyConfig.protocol}://${proxyConfig.host}:${proxyConfig.port}` })
} else {
await mainWindow?.webContents.session.setProxy({})
}
event.sender.send('response-update-proxy-config', conf)
} catch (err) {
log.error(err)
}
})
ipcMain.on('get-proxy-configuration', async (event: IpcMainEvent) => {