mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-11 04:00:32 +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: [] }
|
overrideConfig = parse(data) || { items: [] }
|
||||||
}
|
}
|
||||||
if (typeof overrideConfig !== 'object') overrideConfig = { items: [] }
|
if (typeof overrideConfig !== 'object') overrideConfig = { items: [] }
|
||||||
|
if (!Array.isArray(overrideConfig.items)) overrideConfig.items = []
|
||||||
return overrideConfig
|
return overrideConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ export async function getProfileConfig(force = false): Promise<IProfileConfig> {
|
|||||||
profileConfig = parse(data) || { items: [] }
|
profileConfig = parse(data) || { items: [] }
|
||||||
}
|
}
|
||||||
if (typeof profileConfig !== 'object') profileConfig = { items: [] }
|
if (typeof profileConfig !== 'object') profileConfig = { items: [] }
|
||||||
|
if (!Array.isArray(profileConfig.items)) profileConfig.items = []
|
||||||
return structuredClone(profileConfig)
|
return structuredClone(profileConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const { existsSync, readFileSync } = require('fs')
|
const { existsSync, readFileSync } = require('fs')
|
||||||
const { join } = require('path')
|
const { join, dirname } = require('path')
|
||||||
|
|
||||||
const { platform, arch } = process
|
const { platform, arch } = process
|
||||||
|
|
||||||
@ -43,27 +43,41 @@ function getBindingName() {
|
|||||||
throw new Error(`Unsupported platform: ${platform}-${arch}`)
|
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() {
|
function loadBinding() {
|
||||||
const bindingName = getBindingName()
|
const bindingName = getBindingName()
|
||||||
|
const resourcesPath = getResourcesPath()
|
||||||
|
|
||||||
// 查找项目根目录的 sidecar 和 extra/sidecar
|
// 可能的路径列表
|
||||||
let currentDir = __dirname
|
const searchPaths = [
|
||||||
while (currentDir !== require('path').dirname(currentDir)) {
|
join(resourcesPath, 'sidecar', bindingName),
|
||||||
const paths = [
|
join(resourcesPath, 'extra', 'sidecar', bindingName)
|
||||||
join(currentDir, 'sidecar', bindingName),
|
]
|
||||||
join(currentDir, 'extra', 'sidecar', bindingName)
|
|
||||||
]
|
for (const sidecarPath of searchPaths) {
|
||||||
for (const sidecarPath of paths) {
|
if (existsSync(sidecarPath)) {
|
||||||
if (existsSync(sidecarPath)) {
|
try {
|
||||||
try {
|
nativeBinding = require(sidecarPath)
|
||||||
nativeBinding = require(sidecarPath)
|
return nativeBinding
|
||||||
return nativeBinding
|
} catch (e) {
|
||||||
} catch (e) {
|
loadError = e
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentDir = require('path').dirname(currentDir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadError) {
|
if (loadError) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user