@sunshine-star/dsh-access-pc 0.1.6 → 0.1.7
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 +21 -40
- package/package.json +4 -3
- package/scripts/shortcut.js +5 -0
- package/start-preload.js +6 -0
- package/start.html +78 -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,18 @@ if (args.version) {
|
|
|
132
132
|
|
|
133
133
|
const hubPrefix = () => cfg.hub.replace(/\/$/, '')
|
|
134
134
|
const singleWindow = cfg.singleWindow === true
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
settingsWindow.focus()
|
|
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 = () => {
|
|
136
|
+
if (!mainWindow || mainWindow.isDestroyed()) return
|
|
137
|
+
void mainWindow.loadFile(path.join(__dirname, 'start.html'))
|
|
162
138
|
}
|
|
163
139
|
|
|
164
|
-
|
|
165
|
-
ipcMain.handle('
|
|
140
|
+
const fromStartPage = event => String(event.senderFrame?.url ?? '').startsWith('file://')
|
|
141
|
+
ipcMain.handle('start:get', event => {
|
|
142
|
+
if (!fromStartPage(event)) throw new Error('forbidden')
|
|
143
|
+
return cfg.hub
|
|
144
|
+
})
|
|
145
|
+
ipcMain.handle('start:connect', (event, value) => {
|
|
146
|
+
if (!fromStartPage(event)) throw new Error('forbidden')
|
|
166
147
|
const hub = String(value ?? '').trim().replace(/\/$/, '')
|
|
167
148
|
let parsed
|
|
168
149
|
try {
|
|
@@ -176,14 +157,9 @@ if (args.version) {
|
|
|
176
157
|
cfg.hub = hub
|
|
177
158
|
saveConfig(file, cfg)
|
|
178
159
|
if (mainWindow && !mainWindow.isDestroyed()) void mainWindow.loadURL(cfg.hub)
|
|
179
|
-
if (settingsWindow && !settingsWindow.isDestroyed()) settingsWindow.close()
|
|
180
160
|
return true
|
|
181
161
|
})
|
|
182
|
-
ipcMain.on('settings:cancel', () => {
|
|
183
|
-
if (settingsWindow && !settingsWindow.isDestroyed()) settingsWindow.close()
|
|
184
|
-
})
|
|
185
162
|
|
|
186
|
-
// 站内链接:默认新窗口(独立于打开者);--single-window 时在同一窗口加载。
|
|
187
163
|
const HOST_BUTTON_ID = '__dsh_access_back'
|
|
188
164
|
const installHostBackButton = contents => {
|
|
189
165
|
let url
|
|
@@ -227,7 +203,7 @@ if (args.version) {
|
|
|
227
203
|
enabled: Boolean(contents.navigationHistory?.canGoBack?.()),
|
|
228
204
|
click: () => contents.navigationHistory?.goBack?.(),
|
|
229
205
|
},
|
|
230
|
-
{ label: '设置 Hub 地址…', click: () =>
|
|
206
|
+
{ label: '设置 Hub 地址…', click: () => showStart() },
|
|
231
207
|
{ label: '刷新', click: () => contents.reload() },
|
|
232
208
|
{ type: 'separator' },
|
|
233
209
|
]
|
|
@@ -260,7 +236,7 @@ if (args.version) {
|
|
|
260
236
|
if (input.type !== 'keyDown') return
|
|
261
237
|
if ((input.control || input.meta) && input.key === ',') {
|
|
262
238
|
event.preventDefault()
|
|
263
|
-
|
|
239
|
+
showStart()
|
|
264
240
|
return
|
|
265
241
|
}
|
|
266
242
|
if (!input.alt || input.key !== 'ArrowLeft') return
|
|
@@ -300,9 +276,11 @@ if (args.version) {
|
|
|
300
276
|
minWidth: 960,
|
|
301
277
|
minHeight: 640,
|
|
302
278
|
title: 'DSH Access',
|
|
279
|
+
icon: path.join(__dirname, 'assets', process.platform === 'win32' ? 'icon.ico' : 'icon.png'),
|
|
303
280
|
backgroundColor: '#0b1220',
|
|
304
281
|
autoHideMenuBar: true,
|
|
305
282
|
webPreferences: {
|
|
283
|
+
preload: path.join(__dirname, 'start-preload.js'),
|
|
306
284
|
contextIsolation: true,
|
|
307
285
|
nodeIntegration: false,
|
|
308
286
|
sandbox: true,
|
|
@@ -320,7 +298,7 @@ if (args.version) {
|
|
|
320
298
|
defaultId: 0,
|
|
321
299
|
cancelId: 1,
|
|
322
300
|
}).then(result => {
|
|
323
|
-
if (result.response === 0)
|
|
301
|
+
if (result.response === 0) showStart()
|
|
324
302
|
})
|
|
325
303
|
console.error(`[${APP_NAME}] 加载失败 ${code} ${description} ${url}`)
|
|
326
304
|
})
|
|
@@ -338,7 +316,7 @@ if (args.version) {
|
|
|
338
316
|
submenu: [
|
|
339
317
|
{ label: '返回', accelerator: 'Alt+Left', click: goBack },
|
|
340
318
|
{ label: '主机列表', accelerator: 'Alt+H', click: goHome },
|
|
341
|
-
{ label: '设置 Hub 地址…', accelerator: 'CmdOrCtrl+,', click:
|
|
319
|
+
{ label: '设置 Hub 地址…', accelerator: 'CmdOrCtrl+,', click: showStart },
|
|
342
320
|
{ type: 'separator' },
|
|
343
321
|
{ role: 'reload' },
|
|
344
322
|
{ role: 'forceReload' },
|
|
@@ -348,9 +326,12 @@ if (args.version) {
|
|
|
348
326
|
],
|
|
349
327
|
}]))
|
|
350
328
|
|
|
351
|
-
void mainWindow.loadURL(cfg.hub)
|
|
352
329
|
const explicitHub = typeof args.hub === 'string'
|
|
353
|
-
if (args.
|
|
330
|
+
if (args.connect === true || explicitHub) {
|
|
331
|
+
void mainWindow.loadURL(cfg.hub)
|
|
332
|
+
} else {
|
|
333
|
+
showStart()
|
|
334
|
+
}
|
|
354
335
|
console.log(`[${APP_NAME}] 已打开 ${cfg.hub}(配置 ${file})`)
|
|
355
336
|
|
|
356
337
|
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.7",
|
|
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,78 @@
|
|
|
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
|
+
window.start.get().then(value => {
|
|
61
|
+
input.value = value || ''
|
|
62
|
+
input.focus()
|
|
63
|
+
input.select()
|
|
64
|
+
})
|
|
65
|
+
document.getElementById('form').addEventListener('submit', async event => {
|
|
66
|
+
event.preventDefault()
|
|
67
|
+
err.textContent = ''
|
|
68
|
+
button.disabled = true
|
|
69
|
+
try {
|
|
70
|
+
await window.start.connect(input.value.trim())
|
|
71
|
+
} catch (error) {
|
|
72
|
+
err.textContent = error?.message || String(error)
|
|
73
|
+
button.disabled = false
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
</script>
|
|
77
|
+
</body>
|
|
78
|
+
</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>
|