bugfix: 修复 `linux` 和 `mac` 操作系统下,启用 `系统代理` 报 `NPE` 的问题

pull/349/head
王良 2024-09-10 12:08:57 +08:00
parent 31f7752c6b
commit caa0e809fa
1 changed files with 12 additions and 3 deletions

View File

@ -10,6 +10,11 @@ const log = require('../../../utils/util.log')
const extraPath = require('../extra-path/index') const extraPath = require('../extra-path/index')
let config = null let config = null
function loadConfig () {
if (config == null) {
config = require('../../../config.js')
}
}
async function _winUnsetProxy (exec, setEnv) { async function _winUnsetProxy (exec, setEnv) {
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@ -37,9 +42,7 @@ async function _winUnsetProxy (exec, setEnv) {
async function _winSetProxy (exec, ip, port, setEnv) { async function _winSetProxy (exec, ip, port, setEnv) {
// 延迟加载config // 延迟加载config
if (config == null) { loadConfig()
config = require('../../../config.js')
}
let excludeIpStr = '' let excludeIpStr = ''
for (const ip in config.get().proxy.excludeIpList) { for (const ip in config.get().proxy.excludeIpList) {
@ -92,6 +95,9 @@ const executor = {
async linux (exec, params = {}) { async linux (exec, params = {}) {
const { ip, port } = params const { ip, port } = params
if (ip != null) { if (ip != null) {
// 延迟加载config
loadConfig()
// const local = 'localhost, 127.0.0.0/8, ::1' // const local = 'localhost, 127.0.0.0/8, ::1'
// https // https
@ -141,6 +147,9 @@ const executor = {
// ` // `
// await exec(removeEnv) // await exec(removeEnv)
} else { } else {
// 延迟加载config
loadConfig()
// https // https
await exec(`networksetup -setsecurewebproxy '${wifiAdaptor}' ${ip} ${port}`) await exec(`networksetup -setsecurewebproxy '${wifiAdaptor}' ${ip} ${port}`)
// http // http