@vincentbanana/banana-gui 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/banana-gui-desktop.mjs +6 -9
- package/bin/banana-gui.mjs +9 -1
- package/desktop/main.cjs +8 -0
- package/package.json +1 -1
|
@@ -32,18 +32,15 @@ if (!binary) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const main = join(here, '..', 'desktop', 'main.cjs');
|
|
35
|
+
// 独立窗口模式:把 electron 放出去,命令行立刻返回,不留黑终端窗口。
|
|
36
|
+
// 不能用 windowsHide:实测那会让 Electron 的窗口创建不出来(只有终端、没有窗口)。
|
|
35
37
|
const child = spawn(binary, [main, ...args], {
|
|
36
|
-
|
|
38
|
+
detached: true,
|
|
39
|
+
stdio: 'ignore',
|
|
37
40
|
env: { ...process.env, BANANA_UI_DIR: join(here, '..', 'ui') },
|
|
38
41
|
});
|
|
39
|
-
child.
|
|
40
|
-
|
|
41
|
-
process.exit(1);
|
|
42
|
-
});
|
|
43
|
-
child.on('exit', (code) => process.exit(code ?? 0));
|
|
44
|
-
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
45
|
-
process.on(signal, () => child.kill(signal));
|
|
46
|
-
}
|
|
42
|
+
child.unref();
|
|
43
|
+
console.log('Banana 桌面版已启动,关闭窗口即退出。');
|
|
47
44
|
|
|
48
45
|
/**
|
|
49
46
|
* 找 electron 可执行文件;二进制缺失时用镜像补下载一次。
|
package/bin/banana-gui.mjs
CHANGED
|
@@ -157,7 +157,15 @@ if (args.includes('--desktop')) {
|
|
|
157
157
|
console.error('不装也没关系:直接运行 banana-gui 用浏览器版,功能完全一样。');
|
|
158
158
|
process.exit(1);
|
|
159
159
|
}
|
|
160
|
-
|
|
160
|
+
// 独立窗口模式:把 electron 放出去,命令行立刻返回,
|
|
161
|
+
// 不留一个黑终端窗口挡着(关掉 Banana 窗口即退出,里面的服务会一起收掉)。
|
|
162
|
+
// 注意:不能用 windowsHide,实测那会让 Electron 的窗口创建不出来(只有终端、没有窗口)。
|
|
163
|
+
const child = spawn(binary, [join(here, '..', 'desktop', 'main.cjs'), ...kernelArgs()], {
|
|
164
|
+
detached: true,
|
|
165
|
+
stdio: 'ignore',
|
|
166
|
+
});
|
|
167
|
+
child.unref();
|
|
168
|
+
console.log('Banana 桌面版已启动,关闭窗口即退出。');
|
|
161
169
|
} else {
|
|
162
170
|
launch(process.execPath, [entry, '--ui', ...kernelArgs()], { BANANA_UI_DIR: uiDir });
|
|
163
171
|
}
|
package/desktop/main.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const { app, BrowserWindow, Menu, shell, dialog } = require('electron');
|
|
4
4
|
const { spawn } = require('node:child_process');
|
|
5
5
|
const { createRequire } = require('node:module');
|
|
6
|
+
const { join } = require('node:path');
|
|
6
7
|
|
|
7
8
|
const require_ = createRequire(__filename);
|
|
8
9
|
let child = null;
|
|
@@ -74,9 +75,14 @@ async function createWindow() {
|
|
|
74
75
|
backgroundColor: '#ffffff',
|
|
75
76
|
title: 'Banana',
|
|
76
77
|
autoHideMenuBar: true,
|
|
78
|
+
// 先不显示,等页面就绪再 show():启动器用了 windowsHide,
|
|
79
|
+
// 那种情况下 Electron 会把首个窗口以隐藏状态创建,不显式 show 就看不到
|
|
80
|
+
show: false,
|
|
77
81
|
webPreferences: { contextIsolation: true, nodeIntegration: false, sandbox: true },
|
|
78
82
|
});
|
|
79
83
|
await win.loadURL(url);
|
|
84
|
+
win.show();
|
|
85
|
+
win.focus();
|
|
80
86
|
win.on('closed', () => {
|
|
81
87
|
win = null;
|
|
82
88
|
});
|
|
@@ -144,6 +150,8 @@ const menuTemplate = [
|
|
|
144
150
|
app.whenReady().then(() => {
|
|
145
151
|
Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate));
|
|
146
152
|
createWindow().catch((error) => {
|
|
153
|
+
// 同时打到 stderr:没有控制台时(比如从启动器拉起)也能看到原因
|
|
154
|
+
console.error('[banana] 启动失败:' + String(error?.stack ?? error?.message ?? error));
|
|
147
155
|
dialog.showErrorBox('Banana 启动失败', String(error?.message ?? error));
|
|
148
156
|
app.quit();
|
|
149
157
|
});
|