Refactor remote resolveProxy calls to be called from main process

This commit is contained in:
Becca 2022-01-25 11:59:27 -05:00
parent ef31b21498
commit c550ddb60e
4 changed files with 16 additions and 7 deletions

View file

@ -70,4 +70,5 @@ export type RequestResponseChannels = {
items: ReadonlyArray<ISerializableMenuItem>
) => Promise<ReadonlyArray<number> | null>
'open-external': (path: string) => Promise<boolean>
'resolve-proxy': (url: string) => Promise<string>
}

View file

@ -1,4 +1,4 @@
import { remote } from 'electron'
import { resolveProxy } from '../ui/main-process-proxy'
import { parsePACString } from './parse-pac-string'
export async function resolveGitProxy(
@ -10,12 +10,10 @@ export async function resolveGitProxy(
// error (if the URL we're given is null or undefined despite
// our best type efforts for example).
// Better safe than sorry.
const pacString = await remote.session.defaultSession
.resolveProxy(url)
.catch(err => {
log.error(`Failed resolving proxy for '${url}'`, err)
return 'DIRECT'
})
const pacString = await resolveProxy(url).catch(err => {
log.error(`Failed resolving proxy for '${url}'`, err)
return 'DIRECT'
})
const proxies = parsePACString(pacString)

View file

@ -531,6 +531,13 @@ app.on('ready', () => {
UNSAFE_openDirectory(path)
}
})
/**
* Handle action to resolve proxy
*/
ipcMain.handle('resolve-proxy', async (_, url: string) => {
return session.defaultSession.resolveProxy(url)
})
})
app.on('activate', () => {

View file

@ -272,3 +272,6 @@ export function sendErrorReport(
) {
_sendErrorReport(getIpcFriendlyError(error), extra, nonFatal)
}
/** Tells the main process to resolve the proxy for a given url */
export const resolveProxy = invokeProxy('resolve-proxy')