refs #1542 Set proxy config for BrowserWindow
This commit is contained in:
parent
e52b29b363
commit
87303ba457
|
@ -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 => {
|
||||
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 => {
|
||||
} catch (err) {
|
||||
log.error(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('get-proxy-configuration', async (event: IpcMainEvent) => {
|
||||
|
|
Loading…
Reference in New Issue