mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 11:40:28 +08:00
chore: add type module and fix preload script output format
This commit is contained in:
parent
b071154263
commit
1d053fe636
@ -20,7 +20,15 @@ export default defineConfig({
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
preload: {
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
plugins: [externalizeDepsPlugin()],
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
format: 'cjs',
|
||||
entryFileNames: '[name].cjs'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
renderer: {
|
||||
build: {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
"name": "mihomo-party",
|
||||
"version": "1.9.0",
|
||||
"description": "Clash Party",
|
||||
"type": "module",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "mihomo-party-org",
|
||||
"homepage": "https://mihomo.party",
|
||||
|
||||
@ -39,7 +39,7 @@ async function createFloatingWindow(): Promise<void> {
|
||||
closable: safeMode,
|
||||
backgroundColor: safeMode ? '#ffffff' : useCompatMode ? '#f0f0f0' : '#00000000',
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
preload: join(__dirname, '../preload/index.cjs'),
|
||||
spellcheck: false,
|
||||
sandbox: false,
|
||||
nodeIntegration: false,
|
||||
|
||||
@ -39,7 +39,7 @@ export async function createWindow(): Promise<void> {
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux' ? { icon: icon } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
preload: join(__dirname, '../preload/index.cjs'),
|
||||
spellcheck: false,
|
||||
sandbox: false,
|
||||
devTools: true
|
||||
|
||||
@ -44,11 +44,24 @@ function getBindingName() {
|
||||
}
|
||||
|
||||
function getResourcesPath() {
|
||||
// 开发环境:优先使用 process.cwd()
|
||||
const cwd = process.cwd()
|
||||
if (existsSync(join(cwd, 'extra', 'sidecar'))) {
|
||||
return cwd
|
||||
}
|
||||
// Electron 打包后的路径
|
||||
if (process.resourcesPath) {
|
||||
if (process.resourcesPath && existsSync(join(process.resourcesPath, 'sidecar'))) {
|
||||
return process.resourcesPath
|
||||
}
|
||||
// 开发环境:查找包含 extra/sidecar 的目录
|
||||
// 备选:使用 app.getAppPath() (Electron 特有)
|
||||
try {
|
||||
const { app } = require('electron')
|
||||
const appPath = app.getAppPath()
|
||||
if (existsSync(join(appPath, 'extra', 'sidecar'))) {
|
||||
return appPath
|
||||
}
|
||||
} catch {}
|
||||
// 备选:从 __dirname 向上查找
|
||||
let currentDir = __dirname
|
||||
while (currentDir !== dirname(currentDir)) {
|
||||
if (existsSync(join(currentDir, 'extra', 'sidecar'))) {
|
||||
@ -56,14 +69,13 @@ function getResourcesPath() {
|
||||
}
|
||||
currentDir = dirname(currentDir)
|
||||
}
|
||||
return __dirname
|
||||
return cwd
|
||||
}
|
||||
|
||||
function loadBinding() {
|
||||
const bindingName = getBindingName()
|
||||
const resourcesPath = getResourcesPath()
|
||||
|
||||
// 可能的路径列表
|
||||
const searchPaths = [
|
||||
join(resourcesPath, 'sidecar', bindingName),
|
||||
join(resourcesPath, 'extra', 'sidecar', bindingName)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user