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') {
try {
await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [
'pac', 'pac',
`http://${host || '127.0.0.1'}:${pacPort}/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') {
try {
await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [
'global', 'global',
`${host || '127.0.0.1'}:${port}`, `${host || '127.0.0.1'}:${port}`,
bypass.join(';') 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> => {
try {
await triggerSysProxy(enable) await triggerSysProxy(enable)
await patchAppConfig({ sysProxy: { enable } }) await patchAppConfig({ sysProxy: { enable } })
window.electron.ipcRenderer.send('updateTrayMenu') window.electron.ipcRenderer.send('updateTrayMenu')
} catch (e) {
alert(e)
}
} }
return ( return (