@sunshine-star/dsh-access-pc 0.1.6 → 0.1.8
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 +6 -8
- package/assets/icon-128.png +0 -0
- package/assets/icon-16.png +0 -0
- package/assets/icon-24.png +0 -0
- package/assets/icon-256.png +0 -0
- package/assets/icon-32.png +0 -0
- package/assets/icon-48.png +0 -0
- package/assets/icon-512.png +0 -0
- package/assets/icon-64.png +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/main.js +30 -47
- package/package.json +4 -3
- package/scripts/shortcut.js +5 -0
- package/start-preload.js +6 -0
- package/start.html +80 -0
- package/settings-preload.js +0 -7
- package/settings.html +0 -63
package/README.md
CHANGED
|
@@ -50,14 +50,12 @@ dsh-access-pc --create-shortcut --desktop # 只建桌面
|
|
|
50
50
|
包内含 Electron(约 100MB);国内可设
|
|
51
51
|
`ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/` 加速下载。
|
|
52
52
|
|
|
53
|
-
##
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
- 设置窗口会从配置文件加载当前值(首次默认 `http://127.0.0.1:8080`),保存后写入配置并立即连接新地址;
|
|
60
|
-
- hub 加载失败时,错误对话框也提供“设置 Hub 地址…”按钮。
|
|
53
|
+
## 连接 Hub
|
|
54
|
+
|
|
55
|
+
- 启动先显示**“连接 Hub”整页**(不是弹窗),输入框从配置文件加载当前值,首次默认 `http://127.0.0.1:8080`;
|
|
56
|
+
- 确认地址后点“连接”,进入 hub 的登录界面;
|
|
57
|
+
- 进入后按 **Ctrl+,** 或菜单“导航 → 设置 Hub 地址…”回到该页;
|
|
58
|
+
- `--connect` 跳过连接页直接连;`--hub <url>` 指定地址并直接连。
|
|
61
59
|
|
|
62
60
|
配置文件:Windows `%APPDATA%\dsh-access\config.json`,Linux `~/.config/dsh-access/config.json`。
|
|
63
61
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/assets/icon.ico
ADDED
|
Binary file
|
package/assets/icon.png
ADDED
|
Binary file
|
package/main.js
CHANGED
|
@@ -132,37 +132,19 @@ if (args.version) {
|
|
|
132
132
|
|
|
133
133
|
const hubPrefix = () => cfg.hub.replace(/\/$/, '')
|
|
134
134
|
const singleWindow = cfg.singleWindow === true
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
settingsWindow = new BrowserWindow({
|
|
142
|
-
width: 480,
|
|
143
|
-
height: 250,
|
|
144
|
-
parent: mainWindow,
|
|
145
|
-
modal: false,
|
|
146
|
-
resizable: false,
|
|
147
|
-
minimizable: false,
|
|
148
|
-
maximizable: false,
|
|
149
|
-
fullscreenable: false,
|
|
150
|
-
title: '设置 Hub 地址',
|
|
151
|
-
backgroundColor: '#0b1220',
|
|
152
|
-
autoHideMenuBar: true,
|
|
153
|
-
webPreferences: {
|
|
154
|
-
preload: path.join(__dirname, 'settings-preload.js'),
|
|
155
|
-
contextIsolation: true,
|
|
156
|
-
nodeIntegration: false,
|
|
157
|
-
sandbox: true,
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
void settingsWindow.loadFile(path.join(__dirname, 'settings.html'))
|
|
161
|
-
settingsWindow.on('closed', () => { settingsWindow = null })
|
|
135
|
+
const showStart = error => {
|
|
136
|
+
if (!mainWindow || mainWindow.isDestroyed()) return
|
|
137
|
+
const options = error ? { query: { error: String(error).slice(0, 200) } } : undefined
|
|
138
|
+
void mainWindow.loadFile(path.join(__dirname, 'start.html'), options)
|
|
162
139
|
}
|
|
163
140
|
|
|
164
|
-
|
|
165
|
-
ipcMain.handle('
|
|
141
|
+
const fromStartPage = event => String(event.senderFrame?.url ?? '').startsWith('file://')
|
|
142
|
+
ipcMain.handle('start:get', event => {
|
|
143
|
+
if (!fromStartPage(event)) throw new Error('forbidden')
|
|
144
|
+
return cfg.hub
|
|
145
|
+
})
|
|
146
|
+
ipcMain.handle('start:connect', (event, value) => {
|
|
147
|
+
if (!fromStartPage(event)) throw new Error('forbidden')
|
|
166
148
|
const hub = String(value ?? '').trim().replace(/\/$/, '')
|
|
167
149
|
let parsed
|
|
168
150
|
try {
|
|
@@ -176,14 +158,9 @@ if (args.version) {
|
|
|
176
158
|
cfg.hub = hub
|
|
177
159
|
saveConfig(file, cfg)
|
|
178
160
|
if (mainWindow && !mainWindow.isDestroyed()) void mainWindow.loadURL(cfg.hub)
|
|
179
|
-
if (settingsWindow && !settingsWindow.isDestroyed()) settingsWindow.close()
|
|
180
161
|
return true
|
|
181
162
|
})
|
|
182
|
-
ipcMain.on('settings:cancel', () => {
|
|
183
|
-
if (settingsWindow && !settingsWindow.isDestroyed()) settingsWindow.close()
|
|
184
|
-
})
|
|
185
163
|
|
|
186
|
-
// 站内链接:默认新窗口(独立于打开者);--single-window 时在同一窗口加载。
|
|
187
164
|
const HOST_BUTTON_ID = '__dsh_access_back'
|
|
188
165
|
const installHostBackButton = contents => {
|
|
189
166
|
let url
|
|
@@ -227,7 +204,7 @@ if (args.version) {
|
|
|
227
204
|
enabled: Boolean(contents.navigationHistory?.canGoBack?.()),
|
|
228
205
|
click: () => contents.navigationHistory?.goBack?.(),
|
|
229
206
|
},
|
|
230
|
-
{ label: '设置 Hub 地址…', click: () =>
|
|
207
|
+
{ label: '设置 Hub 地址…', click: () => showStart() },
|
|
231
208
|
{ label: '刷新', click: () => contents.reload() },
|
|
232
209
|
{ type: 'separator' },
|
|
233
210
|
]
|
|
@@ -260,7 +237,7 @@ if (args.version) {
|
|
|
260
237
|
if (input.type !== 'keyDown') return
|
|
261
238
|
if ((input.control || input.meta) && input.key === ',') {
|
|
262
239
|
event.preventDefault()
|
|
263
|
-
|
|
240
|
+
showStart()
|
|
264
241
|
return
|
|
265
242
|
}
|
|
266
243
|
if (!input.alt || input.key !== 'ArrowLeft') return
|
|
@@ -300,9 +277,11 @@ if (args.version) {
|
|
|
300
277
|
minWidth: 960,
|
|
301
278
|
minHeight: 640,
|
|
302
279
|
title: 'DSH Access',
|
|
280
|
+
icon: path.join(__dirname, 'assets', process.platform === 'win32' ? 'icon.ico' : 'icon.png'),
|
|
303
281
|
backgroundColor: '#0b1220',
|
|
304
282
|
autoHideMenuBar: true,
|
|
305
283
|
webPreferences: {
|
|
284
|
+
preload: path.join(__dirname, 'start-preload.js'),
|
|
306
285
|
contextIsolation: true,
|
|
307
286
|
nodeIntegration: false,
|
|
308
287
|
sandbox: true,
|
|
@@ -310,17 +289,18 @@ if (args.version) {
|
|
|
310
289
|
})
|
|
311
290
|
|
|
312
291
|
// 加载失败时给出可读提示,而不是白屏。
|
|
313
|
-
mainWindow.webContents.on('did-fail-load', (_event, code, description, url) => {
|
|
292
|
+
mainWindow.webContents.on('did-fail-load', (_event, code, description, url, isMainFrame) => {
|
|
293
|
+
if (isMainFrame === false) return
|
|
294
|
+
if (code === -3) return // 主动导航取消
|
|
295
|
+
// 连接失败:先回到连接页(可编辑地址),再弹提示。
|
|
296
|
+
showStart(`${description}(${code})`)
|
|
314
297
|
void dialog.showMessageBox(mainWindow, {
|
|
315
298
|
type: 'error',
|
|
316
|
-
title: '
|
|
317
|
-
message:
|
|
318
|
-
detail: `${url}\n\n
|
|
319
|
-
buttons: ['
|
|
299
|
+
title: '无法连接 Hub',
|
|
300
|
+
message: `连接失败:${description}(${code})`,
|
|
301
|
+
detail: `${url}\n\n请检查地址与网络,修改后重试。`,
|
|
302
|
+
buttons: ['返回连接页'],
|
|
320
303
|
defaultId: 0,
|
|
321
|
-
cancelId: 1,
|
|
322
|
-
}).then(result => {
|
|
323
|
-
if (result.response === 0) openSettings()
|
|
324
304
|
})
|
|
325
305
|
console.error(`[${APP_NAME}] 加载失败 ${code} ${description} ${url}`)
|
|
326
306
|
})
|
|
@@ -338,7 +318,7 @@ if (args.version) {
|
|
|
338
318
|
submenu: [
|
|
339
319
|
{ label: '返回', accelerator: 'Alt+Left', click: goBack },
|
|
340
320
|
{ label: '主机列表', accelerator: 'Alt+H', click: goHome },
|
|
341
|
-
{ label: '设置 Hub 地址…', accelerator: 'CmdOrCtrl+,', click:
|
|
321
|
+
{ label: '设置 Hub 地址…', accelerator: 'CmdOrCtrl+,', click: showStart },
|
|
342
322
|
{ type: 'separator' },
|
|
343
323
|
{ role: 'reload' },
|
|
344
324
|
{ role: 'forceReload' },
|
|
@@ -348,9 +328,12 @@ if (args.version) {
|
|
|
348
328
|
],
|
|
349
329
|
}]))
|
|
350
330
|
|
|
351
|
-
void mainWindow.loadURL(cfg.hub)
|
|
352
331
|
const explicitHub = typeof args.hub === 'string'
|
|
353
|
-
if (args.
|
|
332
|
+
if (args.connect === true || explicitHub) {
|
|
333
|
+
void mainWindow.loadURL(cfg.hub)
|
|
334
|
+
} else {
|
|
335
|
+
showStart()
|
|
336
|
+
}
|
|
354
337
|
console.log(`[${APP_NAME}] 已打开 ${cfg.hub}(配置 ${file})`)
|
|
355
338
|
|
|
356
339
|
app.on('window-all-closed', () => app.quit())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sunshine-star/dsh-access-pc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "DSH Access PC client (Electron shell around the hub console)",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"main.js",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"start.html",
|
|
12
|
+
"start-preload.js",
|
|
13
13
|
"bin",
|
|
14
14
|
"scripts/start.js",
|
|
15
15
|
"scripts/doctor.js",
|
|
16
16
|
"scripts/shortcut.js",
|
|
17
17
|
"scripts/postinstall.js",
|
|
18
|
+
"assets",
|
|
18
19
|
"README.md"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
package/scripts/shortcut.js
CHANGED
|
@@ -15,6 +15,8 @@ const path = require('node:path')
|
|
|
15
15
|
|
|
16
16
|
const APP_NAME = 'DSH Access'
|
|
17
17
|
const appDir = path.join(__dirname, '..')
|
|
18
|
+
const iconIco = path.join(appDir, 'assets', 'icon.ico')
|
|
19
|
+
const iconPng = path.join(appDir, 'assets', 'icon.png')
|
|
18
20
|
|
|
19
21
|
function electronBinary() {
|
|
20
22
|
// npm 先跑本包 postinstall、再跑 electron 的下载脚本,此时 require('electron')
|
|
@@ -58,6 +60,7 @@ $sc = $ws.CreateShortcut($env:SHORTCUT_LNK)
|
|
|
58
60
|
$sc.TargetPath = $env:SHORTCUT_TARGET
|
|
59
61
|
$sc.Arguments = $env:SHORTCUT_ARGS
|
|
60
62
|
$sc.WorkingDirectory = $env:SHORTCUT_WD
|
|
63
|
+
$sc.IconLocation = $env:SHORTCUT_ICON
|
|
61
64
|
$sc.Description = 'DSH Access - remote DSH client'
|
|
62
65
|
$sc.Save()
|
|
63
66
|
`
|
|
@@ -67,6 +70,7 @@ $sc.Save()
|
|
|
67
70
|
SHORTCUT_TARGET: electronBinary(),
|
|
68
71
|
SHORTCUT_ARGS: `"${appDir}"`,
|
|
69
72
|
SHORTCUT_WD: appDir,
|
|
73
|
+
SHORTCUT_ICON: iconIco,
|
|
70
74
|
}
|
|
71
75
|
const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
|
|
72
76
|
env,
|
|
@@ -83,6 +87,7 @@ Type=Application
|
|
|
83
87
|
Name=${APP_NAME}
|
|
84
88
|
Comment=Remote DSH client
|
|
85
89
|
Exec="${electron}" "${appDir}"
|
|
90
|
+
Icon=${iconPng}
|
|
86
91
|
Terminal=false
|
|
87
92
|
Categories=Network;RemoteAccess;
|
|
88
93
|
StartupWMClass=dsh-access-pc
|
package/start-preload.js
ADDED
package/start.html
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>连接 Hub · DSH Access</title>
|
|
6
|
+
<style>
|
|
7
|
+
:root { color-scheme: dark; }
|
|
8
|
+
* { box-sizing: border-box; }
|
|
9
|
+
body {
|
|
10
|
+
margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center;
|
|
11
|
+
padding: 24px;
|
|
12
|
+
font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
|
|
13
|
+
background: radial-gradient(1200px 600px at 50% -10%, #1b2a55 0%, #0b1220 60%);
|
|
14
|
+
color: #e8ecf7;
|
|
15
|
+
}
|
|
16
|
+
.card {
|
|
17
|
+
width: min(520px, 100%); padding: 30px 32px;
|
|
18
|
+
background: #141b31; border: 1px solid #27304a; border-radius: 16px;
|
|
19
|
+
box-shadow: 0 18px 60px rgba(0,0,0,.35);
|
|
20
|
+
}
|
|
21
|
+
.eyebrow { margin: 0 0 6px; color: #7c9cff; font-size: 12px; letter-spacing: .14em; }
|
|
22
|
+
h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; }
|
|
23
|
+
.hint { margin: 0 0 18px; color: #94a0bd; font-size: 13px; }
|
|
24
|
+
label { display: block; margin-bottom: 6px; color: #c7cfe4; font-size: 13px; }
|
|
25
|
+
input {
|
|
26
|
+
width: 100%; padding: 11px 12px; border-radius: 8px;
|
|
27
|
+
border: 1px solid #3a4a75; background: #0a1226; color: #e8ecf7;
|
|
28
|
+
font-size: 15px; outline: none;
|
|
29
|
+
}
|
|
30
|
+
input:focus { border-color: #7c9cff; box-shadow: 0 0 0 3px rgba(124,156,255,.25); }
|
|
31
|
+
.err { min-height: 18px; margin: 8px 0 0; color: #ff8d8d; font-size: 12px; }
|
|
32
|
+
.actions { display: flex; justify-content: flex-end; margin-top: 14px; }
|
|
33
|
+
button {
|
|
34
|
+
padding: 9px 22px; border-radius: 9px; border: 1px solid #7c9cff;
|
|
35
|
+
background: #7c9cff; color: #08122b; font-size: 14px; font-weight: 600; cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
button:hover { filter: brightness(1.08); }
|
|
38
|
+
.footer { margin: 16px 0 0; color: #6b7799; font-size: 12px; }
|
|
39
|
+
</style>
|
|
40
|
+
</head>
|
|
41
|
+
<body>
|
|
42
|
+
<div class="card">
|
|
43
|
+
<p class="eyebrow">DSH ACCESS</p>
|
|
44
|
+
<h1>连接 Hub</h1>
|
|
45
|
+
<p class="hint">确认服务器地址后点“连接”,进入登录界面。</p>
|
|
46
|
+
<form id="form">
|
|
47
|
+
<label for="hub">Hub 地址</label>
|
|
48
|
+
<input id="hub" type="text" spellcheck="false" autocomplete="off" placeholder="http://127.0.0.1:8080">
|
|
49
|
+
<p class="err" id="err"></p>
|
|
50
|
+
<div class="actions">
|
|
51
|
+
<button type="submit" id="connect">连接</button>
|
|
52
|
+
</div>
|
|
53
|
+
</form>
|
|
54
|
+
<p class="footer">之后可在菜单“导航 → 设置 Hub 地址…”或 Ctrl+, 回到这里。</p>
|
|
55
|
+
</div>
|
|
56
|
+
<script>
|
|
57
|
+
const input = document.getElementById('hub')
|
|
58
|
+
const err = document.getElementById('err')
|
|
59
|
+
const button = document.getElementById('connect')
|
|
60
|
+
const failed = new URLSearchParams(location.search).get('error')
|
|
61
|
+
if (failed) err.textContent = '连接失败:' + failed
|
|
62
|
+
window.start.get().then(value => {
|
|
63
|
+
input.value = value || ''
|
|
64
|
+
input.focus()
|
|
65
|
+
input.select()
|
|
66
|
+
})
|
|
67
|
+
document.getElementById('form').addEventListener('submit', async event => {
|
|
68
|
+
event.preventDefault()
|
|
69
|
+
err.textContent = ''
|
|
70
|
+
button.disabled = true
|
|
71
|
+
try {
|
|
72
|
+
await window.start.connect(input.value.trim())
|
|
73
|
+
} catch (error) {
|
|
74
|
+
err.textContent = error?.message || String(error)
|
|
75
|
+
button.disabled = false
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
</script>
|
|
79
|
+
</body>
|
|
80
|
+
</html>
|
package/settings-preload.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const { contextBridge, ipcRenderer } = require('electron')
|
|
2
|
-
|
|
3
|
-
contextBridge.exposeInMainWorld('settings', {
|
|
4
|
-
get: () => ipcRenderer.invoke('settings:get'),
|
|
5
|
-
save: hub => ipcRenderer.invoke('settings:save', hub),
|
|
6
|
-
cancel: () => ipcRenderer.send('settings:cancel'),
|
|
7
|
-
})
|
package/settings.html
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>设置 Hub 地址</title>
|
|
6
|
-
<style>
|
|
7
|
-
:root { color-scheme: dark; }
|
|
8
|
-
* { box-sizing: border-box; }
|
|
9
|
-
body {
|
|
10
|
-
margin: 0; padding: 20px 22px;
|
|
11
|
-
font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
|
|
12
|
-
background: #0b1220; color: #e8ecf7;
|
|
13
|
-
}
|
|
14
|
-
h1 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
|
|
15
|
-
.hint { margin: 0 0 14px; color: #94a0bd; font-size: 12px; }
|
|
16
|
-
input {
|
|
17
|
-
width: 100%; padding: 9px 11px; border-radius: 8px;
|
|
18
|
-
border: 1px solid #3a4a75; background: #0a1226; color: #e8ecf7;
|
|
19
|
-
font-size: 14px; outline: none;
|
|
20
|
-
}
|
|
21
|
-
input:focus { border-color: #7c9cff; box-shadow: 0 0 0 3px rgba(124,156,255,.25); }
|
|
22
|
-
.err { min-height: 18px; margin: 6px 0 0; color: #ff8d8d; font-size: 12px; }
|
|
23
|
-
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
|
|
24
|
-
button {
|
|
25
|
-
padding: 7px 16px; border-radius: 8px; border: 1px solid #27304a;
|
|
26
|
-
background: transparent; color: #e8ecf7; font-size: 13px; cursor: pointer;
|
|
27
|
-
}
|
|
28
|
-
button.primary { background: #7c9cff; border-color: #7c9cff; color: #08122b; font-weight: 600; }
|
|
29
|
-
button:hover { filter: brightness(1.08); }
|
|
30
|
-
</style>
|
|
31
|
-
</head>
|
|
32
|
-
<body>
|
|
33
|
-
<h1>Hub 地址</h1>
|
|
34
|
-
<p class="hint">例如 http://127.0.0.1:8080 或 https://hub.example.com</p>
|
|
35
|
-
<form id="form">
|
|
36
|
-
<input id="hub" type="text" spellcheck="false" autocomplete="off" placeholder="http://127.0.0.1:8080">
|
|
37
|
-
<p class="err" id="err"></p>
|
|
38
|
-
<div class="actions">
|
|
39
|
-
<button type="button" id="cancel">取消</button>
|
|
40
|
-
<button type="submit" class="primary">保存并连接</button>
|
|
41
|
-
</div>
|
|
42
|
-
</form>
|
|
43
|
-
<script>
|
|
44
|
-
const input = document.getElementById('hub')
|
|
45
|
-
const err = document.getElementById('err')
|
|
46
|
-
window.settings.get().then(value => {
|
|
47
|
-
input.value = value || ''
|
|
48
|
-
input.focus()
|
|
49
|
-
input.select()
|
|
50
|
-
})
|
|
51
|
-
document.getElementById('form').addEventListener('submit', async event => {
|
|
52
|
-
event.preventDefault()
|
|
53
|
-
err.textContent = ''
|
|
54
|
-
try {
|
|
55
|
-
await window.settings.save(input.value.trim())
|
|
56
|
-
} catch (error) {
|
|
57
|
-
err.textContent = error?.message || String(error)
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
document.getElementById('cancel').addEventListener('click', () => window.settings.cancel())
|
|
61
|
-
</script>
|
|
62
|
-
</body>
|
|
63
|
-
</html>
|