feat: 编译exe问题调试
This commit is contained in:
@@ -71,6 +71,7 @@ export enum WINDOW_NAMES {
|
||||
MAIN = 'main',
|
||||
SETTING = 'setting',
|
||||
DIALOG = 'dialog',
|
||||
LOADING = 'loading',
|
||||
}
|
||||
|
||||
export enum CONFIG_KEYS {
|
||||
|
||||
@@ -5,6 +5,8 @@ import started from 'electron-squirrel-startup'
|
||||
import configManager from '@main/service/config-service'
|
||||
import { runTaskOperationService } from '@main/process/runTaskOperationService'
|
||||
import log from 'electron-log';
|
||||
import 'bytenode'; // Ensure bytenode is bundled/externalized correctly
|
||||
|
||||
// import logManager from '@main/service/logger'
|
||||
|
||||
|
||||
|
||||
@@ -26,9 +26,10 @@ export class executeScriptService extends EventEmitter {
|
||||
const channels = options?.channels ?? '';
|
||||
const startTabIndex = options?.startTabIndex ?? '';
|
||||
|
||||
const child = spawn('node', [scriptPath], {
|
||||
const child = spawn(process.execPath, [scriptPath], {
|
||||
env: {
|
||||
...process.env,
|
||||
ELECTRON_RUN_AS_NODE: '1',
|
||||
ROOM_TYPE: String(roomType),
|
||||
START_DATE: String(startTime),
|
||||
END_DATE: String(endTime),
|
||||
|
||||
@@ -225,7 +225,7 @@ class WindowService {
|
||||
}
|
||||
|
||||
private _loadWindowTemplate(window: BrowserWindow, name: WindowNames) {
|
||||
const page = name === 'main' ? 'login' : name;
|
||||
const page = name === WINDOW_NAMES.LOADING ? 'loading' : 'index';
|
||||
this._loadPage(window, page);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { PluginOption } from 'vite'
|
||||
import * as bytenode from 'bytenode'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs-extra'
|
||||
|
||||
@@ -23,7 +22,28 @@ export default function electronBytecode(options?: ElectronBytecodeOptions): Plu
|
||||
const backupPath = `${entryPath}.bak`
|
||||
|
||||
fs.copyFileSync(entryPath, backupPath)
|
||||
await bytenode.compileFile({ filename: entryPath, output: outputPath })
|
||||
|
||||
// We must compile the bytecode using the ELECTRON executable, not the local Node.js!
|
||||
// Node.js and Electron use different V8 versions.
|
||||
const electronPath = require('electron');
|
||||
const { execFileSync } = require('child_process');
|
||||
|
||||
try {
|
||||
// Run a small script inside Electron to compile the file
|
||||
const compileScript = `
|
||||
const bytenode = require('bytenode');
|
||||
bytenode.compileFile({ filename: ${JSON.stringify(entryPath)}, output: ${JSON.stringify(outputPath)} }).then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });
|
||||
`;
|
||||
const tempScriptPath = path.join(path.dirname(entryPath), '_compile.js');
|
||||
fs.writeFileSync(tempScriptPath, compileScript);
|
||||
|
||||
execFileSync(electronPath, [tempScriptPath], { env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' } });
|
||||
fs.unlinkSync(tempScriptPath);
|
||||
} catch (err) {
|
||||
console.error('Failed to compile bytecode with Electron:', err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
const stub = [
|
||||
"require('bytenode')",
|
||||
`require('./${path.basename(outputPath)}')`
|
||||
|
||||
@@ -54,7 +54,10 @@ export const Session = {
|
||||
|
||||
// 获取临时缓存
|
||||
get(key: string) {
|
||||
if (key === 'token' || key === 'refresh_token') return Cookies.get(key);
|
||||
if (key === 'token' || key === 'refresh_token') {
|
||||
const cookieVal = Cookies.get(key);
|
||||
if (cookieVal) return cookieVal;
|
||||
}
|
||||
let json = <string>window.sessionStorage.getItem(key);
|
||||
return JSON.parse(json);
|
||||
},
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- <img class="w-[540px]" src="@assets/images/login/logo.png" /> -->
|
||||
<img class="w-[540px]" src="@assets/images/login/logo.png" />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user