@sunshine-star/dsh-access-pc 0.0.0-stage → 0.1.1
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/README.md +72 -2
- package/bin/dsh-access-pc.js +23 -0
- package/main.js +294 -0
- package/package.json +29 -4
- package/scripts/doctor.js +28 -0
- package/scripts/start.js +20 -0
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-access-pc(Electron 客户端)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PC 客户端外壳:把 hub 的控制台(即 dsh web 本体)装进一个**独立桌面窗口**。
|
|
4
|
+
窗口里加载的就是网页本身,所以功能、布局、插件 UI 与浏览器完全一致——我们只负责窗口、配置和登录态隔离。
|
|
5
|
+
|
|
6
|
+
## 为什么是 Electron
|
|
7
|
+
|
|
8
|
+
- 官方 DSH Desktop 也是 Electron,技术栈一致;
|
|
9
|
+
- 自带 Chromium,用户不需要装浏览器,Windows/Linux/macOS 行为一致;
|
|
10
|
+
- 我们的客户端只做"打开一个 URL",不需要写前端。
|
|
11
|
+
|
|
12
|
+
代价:每个平台约 150MB(Chromium 随包分发)。
|
|
13
|
+
|
|
14
|
+
## 运行
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cd clients/pc-electron
|
|
18
|
+
npm install # 首次,下载 Electron(国内可用 ELECTRON_MIRROR 镜像)
|
|
19
|
+
npm start # 打开窗口
|
|
20
|
+
npm start -- --hub https://xrzhang.online
|
|
21
|
+
node_modules/.bin/electron . --check # 只验 hub 可达,不开窗口
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
首次运行会把配置写到:
|
|
25
|
+
|
|
26
|
+
- Windows:`%APPDATA%\dsh-access\config.json`
|
|
27
|
+
- Linux:`~/.config/dsh-access/config.json`
|
|
28
|
+
|
|
29
|
+
可用 `DSH_ACCESS_CONFIG_DIR` 覆盖(便携模式)。浏览器/Electron 的 `userData` 放在同目录下的 `electron-profile/`,与日常浏览器隔离。
|
|
30
|
+
|
|
31
|
+
## 从 npm 安装
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm i -g @sunshine-star/dsh-access-pc
|
|
35
|
+
dsh-access-pc --hub http://10.168.1.185:8080
|
|
36
|
+
|
|
37
|
+
# 或免安装(首次会下载 Electron)
|
|
38
|
+
npx -y @sunshine-star/dsh-access-pc --hub http://10.168.1.185:8080
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
包内含 Electron(约 100MB);国内可设
|
|
42
|
+
`ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/` 加速下载。
|
|
43
|
+
|
|
44
|
+
## 窗口行为
|
|
45
|
+
|
|
46
|
+
- **默认单窗口**:点“打开”在同一个窗口加载 DSH 页面;主机页**右侧边缘有悬浮“←”按钮**,点击回主机列表
|
|
47
|
+
(`Alt+←` 返回、`Alt+H` 也回主机列表)
|
|
48
|
+
(菜单栏默认隐藏,按一下 `Alt` 可显示“导航”菜单);
|
|
49
|
+
- 需要账号页与多个 DSH 页并存:`npm start -- --multi-window`(或配置 `"singleWindow": false`),
|
|
50
|
+
新窗口独立于打开者,关掉账号页不会连带关掉已打开的 DSH 窗口(`outlivesOpener`);
|
|
51
|
+
- 站外链接交给系统浏览器;**右键菜单**提供:主机列表 / 返回 / 刷新 / 复制页面地址 / 检查元素,
|
|
52
|
+
链接上额外有“在浏览器中打开链接”“复制链接地址”,输入框内为剪切/复制/粘贴/全选。
|
|
53
|
+
|
|
54
|
+
## 与 Go 客户端的关系
|
|
55
|
+
|
|
56
|
+
两者共用同一份 `config.json` 格式与同一组参数(`--hub`、`--window`、`--check`、`--version`):
|
|
57
|
+
|
|
58
|
+
- **Go 版**:5.5MB,调用系统 Edge/Chrome,适合"用户已经有浏览器"的场景;
|
|
59
|
+
- **Electron 版**:~150MB,自带 Chromium,适合"双击即用、不依赖环境"的场景。
|
|
60
|
+
|
|
61
|
+
可以同时存在,按分发对象选。
|
|
62
|
+
|
|
63
|
+
## 安全设置
|
|
64
|
+
|
|
65
|
+
- `contextIsolation: true`、`nodeIntegration: false`、`sandbox: true`;
|
|
66
|
+
- 站外链接交给系统浏览器(`shell.openExternal`),不在窗口内导航;
|
|
67
|
+
- 不做任何注入,页面内容完全来自 hub。
|
|
68
|
+
|
|
69
|
+
## 已知限制
|
|
70
|
+
|
|
71
|
+
- 未做打包(electron-builder/forge);当前是 `npm start` 运行。要出安装包,下一步加 `electron-builder` 配置;
|
|
72
|
+
- 未做托盘、开机自启、自动更新;
|
|
73
|
+
- 窗口标题固定 "DSH Access",不跟随页面。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* npm bin:启动随包安装的 Electron,并把参数透传给 main.js。
|
|
4
|
+
*
|
|
5
|
+
* 不能直接 `require('electron')` 当入口跑:DSH 自己用 Electron 时会设置
|
|
6
|
+
* ELECTRON_RUN_AS_NODE=1,继承下来会让 electron.exe 退化成普通 Node。
|
|
7
|
+
*/
|
|
8
|
+
const { spawn } = require('node:child_process')
|
|
9
|
+
const path = require('node:path')
|
|
10
|
+
|
|
11
|
+
const electronPath = require('electron')
|
|
12
|
+
const appDir = path.join(__dirname, '..')
|
|
13
|
+
const env = { ...process.env }
|
|
14
|
+
delete env.ELECTRON_RUN_AS_NODE
|
|
15
|
+
delete env.ELECTRON_NO_ATTACH_CONSOLE
|
|
16
|
+
delete env.ELECTRON_ENABLE_STACK_DUMPING
|
|
17
|
+
|
|
18
|
+
const child = spawn(electronPath, [appDir, ...process.argv.slice(2)], { stdio: 'inherit', env })
|
|
19
|
+
child.on('exit', code => process.exit(code === null ? 0 : code))
|
|
20
|
+
child.on('error', error => {
|
|
21
|
+
console.error(`[dsh-access-pc] 启动 Electron 失败: ${error.message}`)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
})
|
package/main.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// dsh-access PC 客户端(Electron 外壳)。
|
|
2
|
+
//
|
|
3
|
+
// 它不实现任何界面:窗口里加载的就是 hub 的控制台(dsh web 本体),
|
|
4
|
+
// 因此功能和布局与浏览器完全一致,插件 UI 也能原生渲染。
|
|
5
|
+
//
|
|
6
|
+
// 设计约束:
|
|
7
|
+
// - 自带 Chromium,用户不需要装浏览器;
|
|
8
|
+
// - 独立 userData 目录,登录态与日常浏览器隔离;
|
|
9
|
+
// - 支持 Windows / Linux / macOS;
|
|
10
|
+
// - 支持 --hub / --check / --version,并复用 ~/.dsh-access 或
|
|
11
|
+
// %APPDATA%\dsh-access\config.json 里的配置(与 Go 客户端同一份)。
|
|
12
|
+
const { app, BrowserWindow, Menu, clipboard, shell, dialog } = require('electron')
|
|
13
|
+
const fs = require('node:fs')
|
|
14
|
+
const path = require('node:path')
|
|
15
|
+
const os = require('node:os')
|
|
16
|
+
|
|
17
|
+
const APP_NAME = 'dsh-access-pc'
|
|
18
|
+
const DEFAULT_HUB = 'https://xrzhang.online'
|
|
19
|
+
const DEFAULT_WINDOW = '1440,900'
|
|
20
|
+
|
|
21
|
+
// 虚拟机/远程桌面/受限显卡环境下,硬件加速常常导致进程在 ready 前崩溃。
|
|
22
|
+
// 客户端只渲染一个网页,软件渲染足够,先关掉更稳。
|
|
23
|
+
app.disableHardwareAcceleration()
|
|
24
|
+
|
|
25
|
+
/** 解析 --key value 形式的参数。 */
|
|
26
|
+
function parseArgs(argv) {
|
|
27
|
+
const args = {}
|
|
28
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
29
|
+
const token = argv[i]
|
|
30
|
+
if (!token.startsWith('--')) continue
|
|
31
|
+
const key = token.slice(2)
|
|
32
|
+
const next = argv[i + 1]
|
|
33
|
+
if (next && !next.startsWith('--')) {
|
|
34
|
+
args[key] = next
|
|
35
|
+
i += 1
|
|
36
|
+
} else {
|
|
37
|
+
args[key] = true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return args
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 配置目录:DSH_ACCESS_CONFIG_DIR 可覆盖,便于便携模式。 */
|
|
44
|
+
function configDir() {
|
|
45
|
+
if (process.env.DSH_ACCESS_CONFIG_DIR) return process.env.DSH_ACCESS_CONFIG_DIR
|
|
46
|
+
return path.join(app.getPath('appData'), 'dsh-access')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 尽早把 userData 指向配置目录:单实例锁、缓存、Crashpad 都写在里面,
|
|
50
|
+
// 避免默认 %APPDATA% 在受限环境(容器/沙箱)下不可写导致启动即崩。
|
|
51
|
+
app.setPath('userData', path.join(configDir(), 'electron-profile'))
|
|
52
|
+
|
|
53
|
+
/** 读取与 Go 客户端共享的 config.json。 */
|
|
54
|
+
function loadConfig(dir) {
|
|
55
|
+
const file = path.join(dir, 'config.json')
|
|
56
|
+
let cfg = { hub: DEFAULT_HUB, window: DEFAULT_WINDOW, singleWindow: true }
|
|
57
|
+
try {
|
|
58
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
59
|
+
if (typeof parsed.hub === 'string' && parsed.hub) cfg.hub = parsed.hub
|
|
60
|
+
if (typeof parsed.window === 'string' && parsed.window) cfg.window = parsed.window
|
|
61
|
+
if (typeof parsed.singleWindow === 'boolean') cfg.singleWindow = parsed.singleWindow
|
|
62
|
+
} catch {
|
|
63
|
+
// 文件不存在或损坏:用默认值,下次启动会写回。
|
|
64
|
+
}
|
|
65
|
+
return { cfg, file }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 写回配置(失败不阻塞启动)。 */
|
|
69
|
+
function saveConfig(file, cfg) {
|
|
70
|
+
try {
|
|
71
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
72
|
+
fs.writeFileSync(`${file}.tmp`, `${JSON.stringify(cfg, null, 2)}\n`)
|
|
73
|
+
fs.renameSync(`${file}.tmp`, file)
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.warn(`[${APP_NAME}] 配置未持久化: ${error.message}`)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** --check:只验证 hub 可达,不建窗口。 */
|
|
80
|
+
async function checkHub(hub) {
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetch(`${hub.replace(/\/$/, '')}/login`, { redirect: 'manual' })
|
|
83
|
+
if (res.status >= 400) {
|
|
84
|
+
console.error(`[${APP_NAME}] hub 返回 ${res.status}`)
|
|
85
|
+
return 1
|
|
86
|
+
}
|
|
87
|
+
console.log(`CHECK PASS ${hub}`)
|
|
88
|
+
return 0
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`[${APP_NAME}] hub 不可达: ${error.message}`)
|
|
91
|
+
return 1
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const args = parseArgs(process.argv.slice(2))
|
|
96
|
+
|
|
97
|
+
if (args.version) {
|
|
98
|
+
console.log(`${APP_NAME} ${app.getVersion()} (electron ${process.versions.electron}, ${process.platform}/${process.arch})`)
|
|
99
|
+
app.quit()
|
|
100
|
+
} else {
|
|
101
|
+
// 单实例:第二次启动直接聚焦已有窗口。
|
|
102
|
+
if (!app.requestSingleInstanceLock()) {
|
|
103
|
+
app.quit()
|
|
104
|
+
} else {
|
|
105
|
+
let mainWindow = null
|
|
106
|
+
|
|
107
|
+
if (args.check) {
|
|
108
|
+
const dir = configDir()
|
|
109
|
+
const { cfg } = loadConfig(dir)
|
|
110
|
+
const hub = typeof args.hub === 'string' ? args.hub : cfg.hub
|
|
111
|
+
app.whenReady().then(async () => {
|
|
112
|
+
const code = await checkHub(hub)
|
|
113
|
+
app.exit(code)
|
|
114
|
+
})
|
|
115
|
+
} else {
|
|
116
|
+
app.on('second-instance', () => {
|
|
117
|
+
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
118
|
+
if (mainWindow.isMinimized()) mainWindow.restore()
|
|
119
|
+
mainWindow.focus()
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
app.whenReady().then(() => {
|
|
124
|
+
const dir = configDir()
|
|
125
|
+
const { cfg, file } = loadConfig(dir)
|
|
126
|
+
if (typeof args.hub === 'string') cfg.hub = args.hub
|
|
127
|
+
if (typeof args.window === 'string') cfg.window = args.window.replace('x', ',')
|
|
128
|
+
if (args['single-window'] === true) cfg.singleWindow = true
|
|
129
|
+
if (args['multi-window'] === true) cfg.singleWindow = false
|
|
130
|
+
saveConfig(file, cfg)
|
|
131
|
+
|
|
132
|
+
const hubPrefix = cfg.hub.replace(/\/$/, '')
|
|
133
|
+
const singleWindow = cfg.singleWindow === true
|
|
134
|
+
|
|
135
|
+
// 站内链接:默认新窗口(独立于打开者);--single-window 时在同一窗口加载。
|
|
136
|
+
const HOST_BUTTON_ID = '__dsh_access_back'
|
|
137
|
+
const installHostBackButton = contents => {
|
|
138
|
+
let url
|
|
139
|
+
try { url = new URL(contents.getURL()) } catch { return }
|
|
140
|
+
if (!url.pathname.startsWith('/h/')) return
|
|
141
|
+
contents.executeJavaScript(`(() => {
|
|
142
|
+
if (document.getElementById('${HOST_BUTTON_ID}')) return
|
|
143
|
+
const button = document.createElement('button')
|
|
144
|
+
button.id = '${HOST_BUTTON_ID}'
|
|
145
|
+
button.type = 'button'
|
|
146
|
+
button.title = '返回主机列表'
|
|
147
|
+
button.textContent = String.fromCharCode(8592)
|
|
148
|
+
Object.assign(button.style, {
|
|
149
|
+
position: 'fixed', right: '10px', top: '50%', transform: 'translateY(-50%)',
|
|
150
|
+
width: '38px', height: '38px', borderRadius: '19px',
|
|
151
|
+
border: '1px solid rgba(124,156,255,.55)', background: 'rgba(20,27,49,.88)',
|
|
152
|
+
color: '#e8ecf7', fontSize: '18px', lineHeight: '1', cursor: 'pointer',
|
|
153
|
+
zIndex: '2147483647', boxShadow: '0 6px 20px rgba(0,0,0,.35)',
|
|
154
|
+
backdropFilter: 'blur(6px)',
|
|
155
|
+
})
|
|
156
|
+
button.addEventListener('click', () => { location.href = '/hosts' })
|
|
157
|
+
document.body.appendChild(button)
|
|
158
|
+
})()`, true).catch(() => {})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
app.on('web-contents-created', (_event, contents) => {
|
|
162
|
+
// 右键菜单:导航、链接、编辑、检查元素。
|
|
163
|
+
contents.on('context-menu', (_event, params) => {
|
|
164
|
+
const window = BrowserWindow.fromWebContents(contents)
|
|
165
|
+
if (!window || window.isDestroyed()) return
|
|
166
|
+
const items = [
|
|
167
|
+
{
|
|
168
|
+
label: '主机列表',
|
|
169
|
+
click: () => {
|
|
170
|
+
if (mainWindow && !mainWindow.isDestroyed()) void mainWindow.loadURL(cfg.hub)
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
label: '返回',
|
|
175
|
+
enabled: Boolean(contents.navigationHistory?.canGoBack?.()),
|
|
176
|
+
click: () => contents.navigationHistory?.goBack?.(),
|
|
177
|
+
},
|
|
178
|
+
{ label: '刷新', click: () => contents.reload() },
|
|
179
|
+
{ type: 'separator' },
|
|
180
|
+
]
|
|
181
|
+
if (params.linkURL) {
|
|
182
|
+
items.push({ label: '在浏览器中打开链接', click: () => { void shell.openExternal(params.linkURL) } })
|
|
183
|
+
items.push({ label: '复制链接地址', click: () => { clipboard.writeText(params.linkURL) } })
|
|
184
|
+
items.push({ type: 'separator' })
|
|
185
|
+
}
|
|
186
|
+
if (params.isEditable) {
|
|
187
|
+
items.push(
|
|
188
|
+
{ role: 'cut', label: '剪切' },
|
|
189
|
+
{ role: 'copy', label: '复制' },
|
|
190
|
+
{ role: 'paste', label: '粘贴' },
|
|
191
|
+
{ role: 'selectAll', label: '全选' },
|
|
192
|
+
)
|
|
193
|
+
} else if (params.selectionText) {
|
|
194
|
+
items.push({ role: 'copy', label: '复制' })
|
|
195
|
+
} else {
|
|
196
|
+
items.push({ label: '复制页面地址', click: () => { clipboard.writeText(contents.getURL()) } })
|
|
197
|
+
}
|
|
198
|
+
items.push({ type: 'separator' })
|
|
199
|
+
items.push({ label: '检查元素', click: () => contents.inspectElement(params.x, params.y) })
|
|
200
|
+
Menu.buildFromTemplate(items).popup({ window })
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
contents.on('did-finish-load', () => installHostBackButton(contents))
|
|
204
|
+
contents.on('did-navigate-in-page', () => installHostBackButton(contents))
|
|
205
|
+
// 单窗口模式下没有浏览器工具栏,Alt+← 用来回主机列表。
|
|
206
|
+
contents.on('before-input-event', (event, input) => {
|
|
207
|
+
if (input.type !== 'keyDown' || !input.alt || input.key !== 'ArrowLeft') return
|
|
208
|
+
event.preventDefault()
|
|
209
|
+
if (contents.navigationHistory?.canGoBack?.()) contents.navigationHistory.goBack()
|
|
210
|
+
})
|
|
211
|
+
contents.setWindowOpenHandler(({ url }) => {
|
|
212
|
+
if (!url.startsWith(hubPrefix)) {
|
|
213
|
+
void shell.openExternal(url)
|
|
214
|
+
return { action: 'deny' }
|
|
215
|
+
}
|
|
216
|
+
if (singleWindow) {
|
|
217
|
+
void contents.loadURL(url)
|
|
218
|
+
return { action: 'deny' }
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
action: 'allow',
|
|
222
|
+
// 关键:关闭账号/列表窗口时,不连带关掉已打开的 DSH 窗口。
|
|
223
|
+
outlivesOpener: true,
|
|
224
|
+
overrideBrowserWindowOptions: {
|
|
225
|
+
autoHideMenuBar: true,
|
|
226
|
+
backgroundColor: '#0b1220',
|
|
227
|
+
webPreferences: {
|
|
228
|
+
contextIsolation: true,
|
|
229
|
+
nodeIntegration: false,
|
|
230
|
+
sandbox: true,
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
const [width, height] = cfg.window.split(',').map(Number)
|
|
238
|
+
mainWindow = new BrowserWindow({
|
|
239
|
+
width: Number.isFinite(width) ? width : 1440,
|
|
240
|
+
height: Number.isFinite(height) ? height : 900,
|
|
241
|
+
minWidth: 960,
|
|
242
|
+
minHeight: 640,
|
|
243
|
+
title: 'DSH Access',
|
|
244
|
+
backgroundColor: '#0b1220',
|
|
245
|
+
autoHideMenuBar: true,
|
|
246
|
+
webPreferences: {
|
|
247
|
+
contextIsolation: true,
|
|
248
|
+
nodeIntegration: false,
|
|
249
|
+
sandbox: true,
|
|
250
|
+
},
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
// 加载失败时给出可读提示,而不是白屏。
|
|
254
|
+
mainWindow.webContents.on('did-fail-load', (_event, code, description, url) => {
|
|
255
|
+
void dialog.showMessageBox(mainWindow, {
|
|
256
|
+
type: 'error',
|
|
257
|
+
title: '无法打开 hub',
|
|
258
|
+
message: `加载失败:${description}(${code})`,
|
|
259
|
+
detail: `${url}\n\n请检查网络、hub 地址与证书。配置文件:${file}`,
|
|
260
|
+
buttons: ['知道了'],
|
|
261
|
+
})
|
|
262
|
+
console.error(`[${APP_NAME}] 加载失败 ${code} ${description} ${url}`)
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
const goHome = () => {
|
|
266
|
+
if (mainWindow && !mainWindow.isDestroyed()) void mainWindow.loadURL(cfg.hub)
|
|
267
|
+
}
|
|
268
|
+
const goBack = () => {
|
|
269
|
+
const target = BrowserWindow.getFocusedWindow() ?? mainWindow
|
|
270
|
+
const history = target?.webContents?.navigationHistory
|
|
271
|
+
if (history?.canGoBack?.()) history.goBack()
|
|
272
|
+
}
|
|
273
|
+
Menu.setApplicationMenu(Menu.buildFromTemplate([{
|
|
274
|
+
label: '导航',
|
|
275
|
+
submenu: [
|
|
276
|
+
{ label: '返回', accelerator: 'Alt+Left', click: goBack },
|
|
277
|
+
{ label: '主机列表', accelerator: 'Alt+H', click: goHome },
|
|
278
|
+
{ type: 'separator' },
|
|
279
|
+
{ role: 'reload' },
|
|
280
|
+
{ role: 'forceReload' },
|
|
281
|
+
{ role: 'toggleDevTools' },
|
|
282
|
+
{ type: 'separator' },
|
|
283
|
+
{ role: 'quit' },
|
|
284
|
+
],
|
|
285
|
+
}]))
|
|
286
|
+
|
|
287
|
+
void mainWindow.loadURL(cfg.hub)
|
|
288
|
+
console.log(`[${APP_NAME}] 已打开 ${cfg.hub}(配置 ${file})`)
|
|
289
|
+
|
|
290
|
+
app.on('window-all-closed', () => app.quit())
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sunshine-star/dsh-access-pc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "DSH Access PC client (Electron shell around the hub console)",
|
|
5
|
+
"main": "main.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"dsh-access-pc": "bin/dsh-access-pc.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"main.js",
|
|
11
|
+
"bin",
|
|
12
|
+
"scripts/start.js",
|
|
13
|
+
"scripts/doctor.js",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "node scripts/start.js",
|
|
18
|
+
"check": "node scripts/start.js --check",
|
|
19
|
+
"doctor": "node scripts/doctor.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"electron": "^33.2.0"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"license": "UNLICENSED"
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// 环境自检:打印会干扰 Electron 的变量与关键版本,便于排查启动问题。
|
|
2
|
+
const fs = require('node:fs')
|
|
3
|
+
const path = require('node:path')
|
|
4
|
+
|
|
5
|
+
let electronVersion = 'unknown'
|
|
6
|
+
try {
|
|
7
|
+
electronVersion = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'node_modules', 'electron', 'package.json'), 'utf8')).version
|
|
8
|
+
} catch {
|
|
9
|
+
// 未安装依赖时忽略
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const blocked = ['ELECTRON_RUN_AS_NODE', 'ELECTRON_NO_ATTACH_CONSOLE', 'ELECTRON_ENABLE_STACK_DUMPING']
|
|
13
|
+
console.log(`electron: ${electronVersion}`)
|
|
14
|
+
console.log(`node: ${process.version}`)
|
|
15
|
+
console.log(`platform: ${process.platform}/${process.arch}`)
|
|
16
|
+
|
|
17
|
+
let conflicts = 0
|
|
18
|
+
for (const name of blocked) {
|
|
19
|
+
if (process.env[name] !== undefined) {
|
|
20
|
+
conflicts += 1
|
|
21
|
+
console.log(`冲突变量: ${name}=${process.env[name]} → 启动脚本会自动清除`)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (conflicts === 0) console.log('没有发现会干扰 Electron 的环境变量')
|
|
25
|
+
|
|
26
|
+
const electronPath = require('electron')
|
|
27
|
+
console.log(`electron 可执行文件: ${electronPath}`)
|
|
28
|
+
console.log(`存在: ${fs.existsSync(electronPath)}`)
|
package/scripts/start.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// 启动包装:清掉会破坏 Electron 的继承环境变量后,再拉起真正的 electron。
|
|
2
|
+
//
|
|
3
|
+
// 背景:DSH 自身用 Electron 跑 Node 时会设置 ELECTRON_RUN_AS_NODE=1,
|
|
4
|
+
// 这个变量被终端继承后,electron.exe 会退化成普通 Node,
|
|
5
|
+
// require('electron') 只返回可执行文件路径,主进程直接失败且没有输出。
|
|
6
|
+
const { spawn } = require('node:child_process')
|
|
7
|
+
|
|
8
|
+
const electronPath = require('electron')
|
|
9
|
+
const env = { ...process.env }
|
|
10
|
+
delete env.ELECTRON_RUN_AS_NODE
|
|
11
|
+
delete env.ELECTRON_NO_ATTACH_CONSOLE
|
|
12
|
+
delete env.ELECTRON_ENABLE_STACK_DUMPING
|
|
13
|
+
|
|
14
|
+
const args = ['.', ...process.argv.slice(2)]
|
|
15
|
+
const child = spawn(electronPath, args, { stdio: 'inherit', env })
|
|
16
|
+
child.on('exit', code => process.exit(code === null ? 0 : code))
|
|
17
|
+
child.on('error', error => {
|
|
18
|
+
console.error(`[dsh-access-pc] 启动 Electron 失败: ${error.message}`)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
})
|