mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +08:00
fix: ensure items array exists in profile and override config
This commit is contained in:
parent
f9176f3fa0
commit
a0bac512dd
@ -14,6 +14,7 @@ export async function getOverrideConfig(force = false): Promise<IOverrideConfig>
|
||||
overrideConfig = parse(data) || { items: [] }
|
||||
}
|
||||
if (typeof overrideConfig !== 'object') overrideConfig = { items: [] }
|
||||
if (!Array.isArray(overrideConfig.items)) overrideConfig.items = []
|
||||
return overrideConfig
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ export async function getProfileConfig(force = false): Promise<IProfileConfig> {
|
||||
profileConfig = parse(data) || { items: [] }
|
||||
}
|
||||
if (typeof profileConfig !== 'object') profileConfig = { items: [] }
|
||||
if (!Array.isArray(profileConfig.items)) profileConfig.items = []
|
||||
return structuredClone(profileConfig)
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { existsSync, readFileSync } = require('fs')
|
||||
const { join } = require('path')
|
||||
const { join, dirname } = require('path')
|
||||
|
||||
const { platform, arch } = process
|
||||
|
||||
@ -43,17 +43,33 @@ function getBindingName() {
|
||||
throw new Error(`Unsupported platform: ${platform}-${arch}`)
|
||||
}
|
||||
|
||||
function getResourcesPath() {
|
||||
// Electron 打包后的路径
|
||||
if (process.resourcesPath) {
|
||||
return process.resourcesPath
|
||||
}
|
||||
// 开发环境:从 __dirname 向上查找项目根目录
|
||||
let currentDir = __dirname
|
||||
while (currentDir !== dirname(currentDir)) {
|
||||
if (existsSync(join(currentDir, 'package.json'))) {
|
||||
return currentDir
|
||||
}
|
||||
currentDir = dirname(currentDir)
|
||||
}
|
||||
return __dirname
|
||||
}
|
||||
|
||||
function loadBinding() {
|
||||
const bindingName = getBindingName()
|
||||
const resourcesPath = getResourcesPath()
|
||||
|
||||
// 查找项目根目录的 sidecar 和 extra/sidecar
|
||||
let currentDir = __dirname
|
||||
while (currentDir !== require('path').dirname(currentDir)) {
|
||||
const paths = [
|
||||
join(currentDir, 'sidecar', bindingName),
|
||||
join(currentDir, 'extra', 'sidecar', bindingName)
|
||||
// 可能的路径列表
|
||||
const searchPaths = [
|
||||
join(resourcesPath, 'sidecar', bindingName),
|
||||
join(resourcesPath, 'extra', 'sidecar', bindingName)
|
||||
]
|
||||
for (const sidecarPath of paths) {
|
||||
|
||||
for (const sidecarPath of searchPaths) {
|
||||
if (existsSync(sidecarPath)) {
|
||||
try {
|
||||
nativeBinding = require(sidecarPath)
|
||||
@ -63,8 +79,6 @@ function loadBinding() {
|
||||
}
|
||||
}
|
||||
}
|
||||
currentDir = require('path').dirname(currentDir)
|
||||
}
|
||||
|
||||
if (loadError) {
|
||||
throw loadError
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user