mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-11 04:00:32 +08:00
chore: integrate sysproxy-rs v0.1.0 napi module
This commit is contained in:
parent
2bbf896584
commit
f9176f3fa0
@ -316,11 +316,57 @@ const resolveEnableLoopback = () =>
|
|||||||
file: 'enableLoopback.exe',
|
file: 'enableLoopback.exe',
|
||||||
downloadURL: `https://github.com/Kuingsmile/uwp-tool/releases/download/latest/enableLoopback.exe`
|
downloadURL: `https://github.com/Kuingsmile/uwp-tool/releases/download/latest/enableLoopback.exe`
|
||||||
})
|
})
|
||||||
const resolveSysproxy = () =>
|
/* ======= sysproxy-rs ======= */
|
||||||
resolveResource({
|
const SYSPROXY_RS_VERSION = 'v0.1.0'
|
||||||
file: 'sysproxy.exe',
|
const SYSPROXY_RS_URL_PREFIX = `https://github.com/mihomo-party-org/sysproxy-rs-opti/releases/download/${SYSPROXY_RS_VERSION}`
|
||||||
downloadURL: `https://github.com/mihomo-party-org/sysproxy/releases/download/${arch}/sysproxy.exe`
|
|
||||||
})
|
function getSysproxyNodeName() {
|
||||||
|
const isMusl = (() => {
|
||||||
|
if (platform !== 'linux') return false
|
||||||
|
try {
|
||||||
|
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
||||||
|
return fs.readFileSync(lddPath, 'utf8').includes('musl')
|
||||||
|
} catch {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
|
switch (platform) {
|
||||||
|
case 'win32':
|
||||||
|
if (arch === 'x64') return 'sysproxy.win32-x64-msvc.node'
|
||||||
|
if (arch === 'arm64') return 'sysproxy.win32-arm64-msvc.node'
|
||||||
|
if (arch === 'ia32') return 'sysproxy.win32-ia32-msvc.node'
|
||||||
|
break
|
||||||
|
case 'darwin':
|
||||||
|
if (arch === 'x64') return 'sysproxy.darwin-x64.node'
|
||||||
|
if (arch === 'arm64') return 'sysproxy.darwin-arm64.node'
|
||||||
|
break
|
||||||
|
case 'linux':
|
||||||
|
if (isMusl) {
|
||||||
|
if (arch === 'x64') return 'sysproxy.linux-x64-musl.node'
|
||||||
|
if (arch === 'arm64') return 'sysproxy.linux-arm64-musl.node'
|
||||||
|
} else {
|
||||||
|
if (arch === 'x64') return 'sysproxy.linux-x64-gnu.node'
|
||||||
|
if (arch === 'arm64') return 'sysproxy.linux-arm64-gnu.node'
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
throw new Error(`Unsupported platform for sysproxy-rs: ${platform}-${arch}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolveSysproxy = async () => {
|
||||||
|
const nodeName = getSysproxyNodeName()
|
||||||
|
const sidecarDir = path.join(cwd, 'extra', 'sidecar')
|
||||||
|
const targetPath = path.join(sidecarDir, nodeName)
|
||||||
|
|
||||||
|
fs.mkdirSync(sidecarDir, { recursive: true })
|
||||||
|
if (fs.existsSync(targetPath)) {
|
||||||
|
fs.rmSync(targetPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
await downloadFile(`${SYSPROXY_RS_URL_PREFIX}/${nodeName}`, targetPath)
|
||||||
|
console.log(`[INFO]: ${nodeName} finished`)
|
||||||
|
}
|
||||||
|
|
||||||
const resolveMonitor = async () => {
|
const resolveMonitor = async () => {
|
||||||
const tempDir = path.join(TEMP_DIR, 'TrafficMonitor')
|
const tempDir = path.join(TEMP_DIR, 'TrafficMonitor')
|
||||||
@ -429,8 +475,7 @@ const tasks = [
|
|||||||
{
|
{
|
||||||
name: 'sysproxy',
|
name: 'sysproxy',
|
||||||
func: resolveSysproxy,
|
func: resolveSysproxy,
|
||||||
retry: 5,
|
retry: 5
|
||||||
winOnly: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'monitor',
|
name: 'monitor',
|
||||||
|
|||||||
4
src/native/sysproxy/index.d.ts
vendored
4
src/native/sysproxy/index.d.ts
vendored
@ -22,3 +22,7 @@ export function triggerAutoProxy(enable: boolean, url: string): void
|
|||||||
export function getSystemProxy(): SysproxyInfo
|
export function getSystemProxy(): SysproxyInfo
|
||||||
|
|
||||||
export function getAutoProxy(): AutoproxyInfo
|
export function getAutoProxy(): AutoproxyInfo
|
||||||
|
|
||||||
|
export function setSystemProxy(proxy: SysproxyInfo): void
|
||||||
|
|
||||||
|
export function setAutoProxy(proxy: AutoproxyInfo): void
|
||||||
|
|||||||
@ -78,3 +78,5 @@ module.exports.triggerManualProxy = binding.triggerManualProxy
|
|||||||
module.exports.triggerAutoProxy = binding.triggerAutoProxy
|
module.exports.triggerAutoProxy = binding.triggerAutoProxy
|
||||||
module.exports.getSystemProxy = binding.getSystemProxy
|
module.exports.getSystemProxy = binding.getSystemProxy
|
||||||
module.exports.getAutoProxy = binding.getAutoProxy
|
module.exports.getAutoProxy = binding.getAutoProxy
|
||||||
|
module.exports.setSystemProxy = binding.setSystemProxy
|
||||||
|
module.exports.setAutoProxy = binding.setAutoProxy
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user