mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50: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()]
|
plugins: [externalizeDepsPlugin()]
|
||||||
},
|
},
|
||||||
preload: {
|
preload: {
|
||||||
plugins: [externalizeDepsPlugin()]
|
plugins: [externalizeDepsPlugin()],
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
format: 'cjs',
|
||||||
|
entryFileNames: '[name].cjs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
renderer: {
|
renderer: {
|
||||||
build: {
|
build: {
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
"name": "mihomo-party",
|
"name": "mihomo-party",
|
||||||
"version": "1.9.0",
|
"version": "1.9.0",
|
||||||
"description": "Clash Party",
|
"description": "Clash Party",
|
||||||
|
"type": "module",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "mihomo-party-org",
|
"author": "mihomo-party-org",
|
||||||
"homepage": "https://mihomo.party",
|
"homepage": "https://mihomo.party",
|
||||||
|
|||||||
@ -39,7 +39,7 @@ async function createFloatingWindow(): Promise<void> {
|
|||||||
closable: safeMode,
|
closable: safeMode,
|
||||||
backgroundColor: safeMode ? '#ffffff' : useCompatMode ? '#f0f0f0' : '#00000000',
|
backgroundColor: safeMode ? '#ffffff' : useCompatMode ? '#f0f0f0' : '#00000000',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, '../preload/index.js'),
|
preload: join(__dirname, '../preload/index.cjs'),
|
||||||
spellcheck: false,
|
spellcheck: false,
|
||||||
sandbox: false,
|
sandbox: false,
|
||||||
nodeIntegration: false,
|
nodeIntegration: false,
|
||||||
|
|||||||
@ -39,7 +39,7 @@ export async function createWindow(): Promise<void> {
|
|||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
...(process.platform === 'linux' ? { icon: icon } : {}),
|
...(process.platform === 'linux' ? { icon: icon } : {}),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, '../preload/index.js'),
|
preload: join(__dirname, '../preload/index.cjs'),
|
||||||
spellcheck: false,
|
spellcheck: false,
|
||||||
sandbox: false,
|
sandbox: false,
|
||||||
devTools: true
|
devTools: true
|
||||||
|
|||||||
@ -44,11 +44,24 @@ function getBindingName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getResourcesPath() {
|
function getResourcesPath() {
|
||||||
|
// 开发环境:优先使用 process.cwd()
|
||||||
|
const cwd = process.cwd()
|
||||||
|
if (existsSync(join(cwd, 'extra', 'sidecar'))) {
|
||||||
|
return cwd
|
||||||
|
}
|
||||||
// Electron 打包后的路径
|
// Electron 打包后的路径
|
||||||
if (process.resourcesPath) {
|
if (process.resourcesPath && existsSync(join(process.resourcesPath, 'sidecar'))) {
|
||||||
return process.resourcesPath
|
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
|
let currentDir = __dirname
|
||||||
while (currentDir !== dirname(currentDir)) {
|
while (currentDir !== dirname(currentDir)) {
|
||||||
if (existsSync(join(currentDir, 'extra', 'sidecar'))) {
|
if (existsSync(join(currentDir, 'extra', 'sidecar'))) {
|
||||||
@ -56,14 +69,13 @@ function getResourcesPath() {
|
|||||||
}
|
}
|
||||||
currentDir = dirname(currentDir)
|
currentDir = dirname(currentDir)
|
||||||
}
|
}
|
||||||
return __dirname
|
return cwd
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadBinding() {
|
function loadBinding() {
|
||||||
const bindingName = getBindingName()
|
const bindingName = getBindingName()
|
||||||
const resourcesPath = getResourcesPath()
|
const resourcesPath = getResourcesPath()
|
||||||
|
|
||||||
// 可能的路径列表
|
|
||||||
const searchPaths = [
|
const searchPaths = [
|
||||||
join(resourcesPath, 'sidecar', bindingName),
|
join(resourcesPath, 'sidecar', bindingName),
|
||||||
join(resourcesPath, 'extra', 'sidecar', bindingName)
|
join(resourcesPath, 'extra', 'sidecar', bindingName)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user