diff --git a/src/main/sys/sysproxy.ts b/src/main/sys/sysproxy.ts index ee98f5a..b3e3183 100644 --- a/src/main/sys/sysproxy.ts +++ b/src/main/sys/sysproxy.ts @@ -63,10 +63,14 @@ export async function enableSysProxy(): Promise { switch (mode || 'manual') { case 'auto': { if (process.platform === 'win32') { - await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ - 'pac', - `http://${host || '127.0.0.1'}:${pacPort}/pac` - ]) + try { + await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ + 'pac', + `http://${host || '127.0.0.1'}:${pacPort}/pac` + ]) + } catch { + triggerAutoProxy(true, `http://${host || '127.0.0.1'}:${pacPort}/pac`) + } } else { triggerAutoProxy(true, `http://${host || '127.0.0.1'}:${pacPort}/pac`) } @@ -76,11 +80,15 @@ export async function enableSysProxy(): Promise { case 'manual': { if (process.platform === 'win32') { - await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ - 'global', - `${host || '127.0.0.1'}:${port}`, - bypass.join(';') - ]) + try { + await execFilePromise(path.join(resourcesFilesDir(), 'sysproxy.exe'), [ + 'global', + `${host || '127.0.0.1'}:${port}`, + bypass.join(';') + ]) + } catch { + triggerManualProxy(true, host || '127.0.0.1', port, bypass.join(',')) + } } else { triggerManualProxy(true, host || '127.0.0.1', port, bypass.join(',')) } diff --git a/src/renderer/src/components/sider/sysproxy-switcher.tsx b/src/renderer/src/components/sider/sysproxy-switcher.tsx index 9413808..f0857a1 100644 --- a/src/renderer/src/components/sider/sysproxy-switcher.tsx +++ b/src/renderer/src/components/sider/sysproxy-switcher.tsx @@ -27,9 +27,13 @@ const SysproxySwitcher: React.FC = () => { }) const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null const onChange = async (enable: boolean): Promise => { - await triggerSysProxy(enable) - await patchAppConfig({ sysProxy: { enable } }) - window.electron.ipcRenderer.send('updateTrayMenu') + try { + await triggerSysProxy(enable) + await patchAppConfig({ sysProxy: { enable } }) + window.electron.ipcRenderer.send('updateTrayMenu') + } catch (e) { + alert(e) + } } return (