try to fix sysproxy

This commit is contained in:
pompurin404 2024-08-29 10:49:13 +08:00
parent 54306ee64b
commit 2429a5f189
No known key found for this signature in database
2 changed files with 24 additions and 12 deletions

View File

@ -63,10 +63,14 @@ export async function enableSysProxy(): Promise<void> {
switch (mode || 'manual') { switch (mode || 'manual') {
case 'auto': { case 'auto': {
if (process.platform === 'win32') { if (process.platform === 'win32') {
await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ try {
'pac', await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [
`http://${host || '127.0.0.1'}:${pacPort}/pac` 'pac',
]) `http://${host || '127.0.0.1'}:${pacPort}/pac`
])
} catch {
triggerAutoProxy(true, `http://${host || '127.0.0.1'}:${pacPort}/pac`)
}
} else { } else {
triggerAutoProxy(true, `http://${host || '127.0.0.1'}:${pacPort}/pac`) triggerAutoProxy(true, `http://${host || '127.0.0.1'}:${pacPort}/pac`)
} }
@ -76,11 +80,15 @@ export async function enableSysProxy(): Promise<void> {
case 'manual': { case 'manual': {
if (process.platform === 'win32') { if (process.platform === 'win32') {
await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ try {
'global', await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [
`${host || '127.0.0.1'}:${port}`, 'global',
bypass.join(';') `${host || '127.0.0.1'}:${port}`,
]) bypass.join(';')
])
} catch {
triggerManualProxy(true, host || '127.0.0.1', port, bypass.join(','))
}
} else { } else {
triggerManualProxy(true, host || '127.0.0.1', port, bypass.join(',')) triggerManualProxy(true, host || '127.0.0.1', port, bypass.join(','))
} }

View File

@ -27,9 +27,13 @@ const SysproxySwitcher: React.FC = () => {
}) })
const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null
const onChange = async (enable: boolean): Promise<void> => { const onChange = async (enable: boolean): Promise<void> => {
await triggerSysProxy(enable) try {
await patchAppConfig({ sysProxy: { enable } }) await triggerSysProxy(enable)
window.electron.ipcRenderer.send('updateTrayMenu') await patchAppConfig({ sysProxy: { enable } })
window.electron.ipcRenderer.send('updateTrayMenu')
} catch (e) {
alert(e)
}
} }
return ( return (