@sunshine-star/dsh-access-pc 0.1.0 → 0.1.2
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 +15 -1
- 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/bin/dsh-access-pc.js +5 -0
- package/main.js +44 -1
- package/package.json +6 -2
- package/scripts/postinstall.js +24 -0
- package/scripts/shortcut.js +133 -0
package/README.md
CHANGED
|
@@ -38,6 +38,19 @@ dsh-access-pc --hub http://10.168.1.185:8080
|
|
|
38
38
|
npx -y @sunshine-star/dsh-access-pc --hub http://10.168.1.185:8080
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
安装时可顺便创建桌面图标(Windows 桌面 + 开始菜单;Linux 应用菜单 + 桌面):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
DSH_ACCESS_PC_SHORTCUT=1 npm i -g @sunshine-star/dsh-access-pc
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
装完也可以手动创建:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
dsh-access-pc --create-shortcut # 桌面 + 开始菜单
|
|
51
|
+
dsh-access-pc --create-shortcut --desktop # 只建桌面
|
|
52
|
+
```
|
|
53
|
+
|
|
41
54
|
包内含 Electron(约 100MB);国内可设
|
|
42
55
|
`ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/` 加速下载。
|
|
43
56
|
|
|
@@ -48,7 +61,8 @@ npx -y @sunshine-star/dsh-access-pc --hub http://10.168.1.185:8080
|
|
|
48
61
|
(菜单栏默认隐藏,按一下 `Alt` 可显示“导航”菜单);
|
|
49
62
|
- 需要账号页与多个 DSH 页并存:`npm start -- --multi-window`(或配置 `"singleWindow": false`),
|
|
50
63
|
新窗口独立于打开者,关掉账号页不会连带关掉已打开的 DSH 窗口(`outlivesOpener`);
|
|
51
|
-
-
|
|
64
|
+
- 站外链接交给系统浏览器;**右键菜单**提供:主机列表 / 返回 / 刷新 / 复制页面地址 / 检查元素,
|
|
65
|
+
链接上额外有“在浏览器中打开链接”“复制链接地址”,输入框内为剪切/复制/粘贴/全选。
|
|
52
66
|
|
|
53
67
|
## 与 Go 客户端的关系
|
|
54
68
|
|
|
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/bin/dsh-access-pc.js
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
const { spawn } = require('node:child_process')
|
|
9
9
|
const path = require('node:path')
|
|
10
10
|
|
|
11
|
+
if (process.argv.includes('--create-shortcut')) {
|
|
12
|
+
const { main } = require('../scripts/shortcut.js')
|
|
13
|
+
process.exit(main(process.argv.slice(2)))
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
const electronPath = require('electron')
|
|
12
17
|
const appDir = path.join(__dirname, '..')
|
|
13
18
|
const env = { ...process.env }
|
package/main.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// - 支持 Windows / Linux / macOS;
|
|
10
10
|
// - 支持 --hub / --check / --version,并复用 ~/.dsh-access 或
|
|
11
11
|
// %APPDATA%\dsh-access\config.json 里的配置(与 Go 客户端同一份)。
|
|
12
|
-
const { app, BrowserWindow, Menu, shell, dialog } = require('electron')
|
|
12
|
+
const { app, BrowserWindow, Menu, clipboard, shell, dialog } = require('electron')
|
|
13
13
|
const fs = require('node:fs')
|
|
14
14
|
const path = require('node:path')
|
|
15
15
|
const os = require('node:os')
|
|
@@ -21,6 +21,7 @@ const DEFAULT_WINDOW = '1440,900'
|
|
|
21
21
|
// 虚拟机/远程桌面/受限显卡环境下,硬件加速常常导致进程在 ready 前崩溃。
|
|
22
22
|
// 客户端只渲染一个网页,软件渲染足够,先关掉更稳。
|
|
23
23
|
app.disableHardwareAcceleration()
|
|
24
|
+
if (process.platform === 'win32') app.setAppUserModelId('com.sunshine-star.dsh-access')
|
|
24
25
|
|
|
25
26
|
/** 解析 --key value 形式的参数。 */
|
|
26
27
|
function parseArgs(argv) {
|
|
@@ -159,6 +160,47 @@ if (args.version) {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
app.on('web-contents-created', (_event, contents) => {
|
|
163
|
+
// 右键菜单:导航、链接、编辑、检查元素。
|
|
164
|
+
contents.on('context-menu', (_event, params) => {
|
|
165
|
+
const window = BrowserWindow.fromWebContents(contents)
|
|
166
|
+
if (!window || window.isDestroyed()) return
|
|
167
|
+
const items = [
|
|
168
|
+
{
|
|
169
|
+
label: '主机列表',
|
|
170
|
+
click: () => {
|
|
171
|
+
if (mainWindow && !mainWindow.isDestroyed()) void mainWindow.loadURL(cfg.hub)
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
label: '返回',
|
|
176
|
+
enabled: Boolean(contents.navigationHistory?.canGoBack?.()),
|
|
177
|
+
click: () => contents.navigationHistory?.goBack?.(),
|
|
178
|
+
},
|
|
179
|
+
{ label: '刷新', click: () => contents.reload() },
|
|
180
|
+
{ type: 'separator' },
|
|
181
|
+
]
|
|
182
|
+
if (params.linkURL) {
|
|
183
|
+
items.push({ label: '在浏览器中打开链接', click: () => { void shell.openExternal(params.linkURL) } })
|
|
184
|
+
items.push({ label: '复制链接地址', click: () => { clipboard.writeText(params.linkURL) } })
|
|
185
|
+
items.push({ type: 'separator' })
|
|
186
|
+
}
|
|
187
|
+
if (params.isEditable) {
|
|
188
|
+
items.push(
|
|
189
|
+
{ role: 'cut', label: '剪切' },
|
|
190
|
+
{ role: 'copy', label: '复制' },
|
|
191
|
+
{ role: 'paste', label: '粘贴' },
|
|
192
|
+
{ role: 'selectAll', label: '全选' },
|
|
193
|
+
)
|
|
194
|
+
} else if (params.selectionText) {
|
|
195
|
+
items.push({ role: 'copy', label: '复制' })
|
|
196
|
+
} else {
|
|
197
|
+
items.push({ label: '复制页面地址', click: () => { clipboard.writeText(contents.getURL()) } })
|
|
198
|
+
}
|
|
199
|
+
items.push({ type: 'separator' })
|
|
200
|
+
items.push({ label: '检查元素', click: () => contents.inspectElement(params.x, params.y) })
|
|
201
|
+
Menu.buildFromTemplate(items).popup({ window })
|
|
202
|
+
})
|
|
203
|
+
|
|
162
204
|
contents.on('did-finish-load', () => installHostBackButton(contents))
|
|
163
205
|
contents.on('did-navigate-in-page', () => installHostBackButton(contents))
|
|
164
206
|
// 单窗口模式下没有浏览器工具栏,Alt+← 用来回主机列表。
|
|
@@ -200,6 +242,7 @@ if (args.version) {
|
|
|
200
242
|
minWidth: 960,
|
|
201
243
|
minHeight: 640,
|
|
202
244
|
title: 'DSH Access',
|
|
245
|
+
icon: path.join(__dirname, 'assets', process.platform === 'win32' ? 'icon.ico' : 'icon.png'),
|
|
203
246
|
backgroundColor: '#0b1220',
|
|
204
247
|
autoHideMenuBar: true,
|
|
205
248
|
webPreferences: {
|
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.2",
|
|
4
4
|
"description": "DSH Access PC client (Electron shell around the hub console)",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
"bin",
|
|
12
12
|
"scripts/start.js",
|
|
13
13
|
"scripts/doctor.js",
|
|
14
|
+
"scripts/shortcut.js",
|
|
15
|
+
"scripts/postinstall.js",
|
|
16
|
+
"assets",
|
|
14
17
|
"README.md"
|
|
15
18
|
],
|
|
16
19
|
"scripts": {
|
|
17
20
|
"start": "node scripts/start.js",
|
|
18
21
|
"check": "node scripts/start.js --check",
|
|
19
|
-
"doctor": "node scripts/doctor.js"
|
|
22
|
+
"doctor": "node scripts/doctor.js",
|
|
23
|
+
"postinstall": "node scripts/postinstall.js"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
26
|
"electron": "^33.2.0"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 可选:npm 全局安装时创建桌面/开始菜单快捷方式。
|
|
4
|
+
*
|
|
5
|
+
* 默认不创建,只提示;显式设置 DSH_ACCESS_PC_SHORTCUT=1 才创建:
|
|
6
|
+
* DSH_ACCESS_PC_SHORTCUT=1 npm i -g @sunshine-star/dsh-access-pc
|
|
7
|
+
* 设 0 或 DSH_ACCESS_PC_NO_SHORTCUT=1 可关闭提示。
|
|
8
|
+
*/
|
|
9
|
+
const globalInstall = process.env.npm_config_global === 'true'
|
|
10
|
+
if (!globalInstall) process.exit(0)
|
|
11
|
+
if (process.env.DSH_ACCESS_PC_SHORTCUT === '0' || process.env.DSH_ACCESS_PC_NO_SHORTCUT === '1') process.exit(0)
|
|
12
|
+
|
|
13
|
+
if (process.env.DSH_ACCESS_PC_SHORTCUT === '1' || process.env.DSH_ACCESS_PC_SHORTCUT === 'desktop') {
|
|
14
|
+
try {
|
|
15
|
+
const { createShortcuts } = require('./shortcut.js')
|
|
16
|
+
const created = createShortcuts({ desktop: true, menu: true })
|
|
17
|
+
for (const item of created) console.log(`[dsh-access-pc] 已创建 ${item}`)
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(`[dsh-access-pc] 创建快捷方式失败:${error.message}`)
|
|
20
|
+
console.error('[dsh-access-pc] 可稍后运行:dsh-access-pc --create-shortcut')
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
console.log('[dsh-access-pc] 想创建桌面图标:dsh-access-pc --create-shortcut(安装时设 DSH_ACCESS_PC_SHORTCUT=1 可自动创建)')
|
|
24
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 创建桌面 / 开始菜单快捷方式(无需管理员权限)。
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* dsh-access-pc --create-shortcut # 桌面 + 开始菜单
|
|
7
|
+
* dsh-access-pc --create-shortcut --desktop # 只建桌面
|
|
8
|
+
*
|
|
9
|
+
* 也支持安装时自动创建:DSH_ACCESS_PC_SHORTCUT=1 npm i -g ...
|
|
10
|
+
*/
|
|
11
|
+
const { spawnSync } = require('node:child_process')
|
|
12
|
+
const fs = require('node:fs')
|
|
13
|
+
const os = require('node:os')
|
|
14
|
+
const path = require('node:path')
|
|
15
|
+
|
|
16
|
+
const APP_NAME = 'DSH Access'
|
|
17
|
+
const appDir = path.join(__dirname, '..')
|
|
18
|
+
const iconIco = path.join(appDir, 'assets', 'icon.ico')
|
|
19
|
+
const iconPng = path.join(appDir, 'assets', 'icon.png')
|
|
20
|
+
|
|
21
|
+
function electronBinary() {
|
|
22
|
+
try {
|
|
23
|
+
return require('electron')
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new Error(`找不到 Electron:${error.message}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function desktopDir() {
|
|
30
|
+
return process.env.DSH_ACCESS_SHORTCUT_DIR || path.join(os.homedir(), 'Desktop')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function startMenuDir() {
|
|
34
|
+
return process.env.DSH_ACCESS_START_MENU_DIR ||
|
|
35
|
+
path.join(process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'),
|
|
36
|
+
'Microsoft', 'Windows', 'Start Menu', 'Programs')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createWindowsLink(lnkPath) {
|
|
40
|
+
fs.mkdirSync(path.dirname(lnkPath), { recursive: true })
|
|
41
|
+
const script = `
|
|
42
|
+
$ws = New-Object -ComObject WScript.Shell
|
|
43
|
+
$sc = $ws.CreateShortcut($env:SHORTCUT_LNK)
|
|
44
|
+
$sc.TargetPath = $env:SHORTCUT_TARGET
|
|
45
|
+
$sc.Arguments = $env:SHORTCUT_ARGS
|
|
46
|
+
$sc.WorkingDirectory = $env:SHORTCUT_WD
|
|
47
|
+
$sc.IconLocation = $env:SHORTCUT_ICON
|
|
48
|
+
$sc.Description = 'DSH Access - remote DSH client'
|
|
49
|
+
$sc.Save()
|
|
50
|
+
`
|
|
51
|
+
const env = {
|
|
52
|
+
...process.env,
|
|
53
|
+
SHORTCUT_LNK: lnkPath,
|
|
54
|
+
SHORTCUT_TARGET: electronBinary(),
|
|
55
|
+
SHORTCUT_ARGS: `"${appDir}"`,
|
|
56
|
+
SHORTCUT_WD: appDir,
|
|
57
|
+
SHORTCUT_ICON: iconIco,
|
|
58
|
+
}
|
|
59
|
+
const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
|
|
60
|
+
env,
|
|
61
|
+
encoding: 'utf8',
|
|
62
|
+
})
|
|
63
|
+
if (result.status !== 0) throw new Error((result.stderr || result.stdout || '创建快捷方式失败').trim())
|
|
64
|
+
return lnkPath
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function desktopEntry() {
|
|
68
|
+
const electron = electronBinary()
|
|
69
|
+
return `[Desktop Entry]
|
|
70
|
+
Type=Application
|
|
71
|
+
Name=${APP_NAME}
|
|
72
|
+
Comment=Remote DSH client
|
|
73
|
+
Exec="${electron}" "${appDir}"
|
|
74
|
+
Icon=${iconPng}
|
|
75
|
+
Terminal=false
|
|
76
|
+
Categories=Network;RemoteAccess;
|
|
77
|
+
StartupWMClass=dsh-access-pc
|
|
78
|
+
`
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function createLinuxEntry(targetPath) {
|
|
82
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true })
|
|
83
|
+
fs.writeFileSync(targetPath, desktopEntry())
|
|
84
|
+
fs.chmodSync(targetPath, 0o755)
|
|
85
|
+
return targetPath
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {{ desktop?: boolean, menu?: boolean }} options
|
|
90
|
+
* @returns {string[]} 创建的路径。
|
|
91
|
+
*/
|
|
92
|
+
function createShortcuts({ desktop = true, menu = true } = {}) {
|
|
93
|
+
const created = []
|
|
94
|
+
if (process.platform === 'win32') {
|
|
95
|
+
if (desktop) created.push(createWindowsLink(path.join(desktopDir(), `${APP_NAME}.lnk`)))
|
|
96
|
+
if (menu) created.push(createWindowsLink(path.join(startMenuDir(), `${APP_NAME}.lnk`)))
|
|
97
|
+
return created
|
|
98
|
+
}
|
|
99
|
+
if (process.platform === 'linux') {
|
|
100
|
+
const base = path.join(os.homedir(), '.local', 'share', 'applications')
|
|
101
|
+
const entry = path.join(base, 'dsh-access-pc.desktop')
|
|
102
|
+
created.push(createLinuxEntry(entry))
|
|
103
|
+
if (desktop) {
|
|
104
|
+
const desktopPath = path.join(desktopDir(), 'dsh-access-pc.desktop')
|
|
105
|
+
try {
|
|
106
|
+
fs.copyFileSync(entry, desktopPath)
|
|
107
|
+
fs.chmodSync(desktopPath, 0o755)
|
|
108
|
+
created.push(desktopPath)
|
|
109
|
+
} catch {
|
|
110
|
+
// 没有桌面目录就只留应用菜单项。
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return created
|
|
114
|
+
}
|
|
115
|
+
throw new Error(`暂不支持 ${process.platform} 的快捷方式;macOS 可把 Electron 应用拖入 Applications`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function main(argv = process.argv.slice(2)) {
|
|
119
|
+
const desktop = argv.includes('--desktop') || !argv.includes('--menu-only')
|
|
120
|
+
const menu = !argv.includes('--desktop')
|
|
121
|
+
try {
|
|
122
|
+
const created = createShortcuts({ desktop, menu })
|
|
123
|
+
for (const item of created) console.log(`已创建 ${item}`)
|
|
124
|
+
return 0
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(`[${APP_NAME}] ${error.message}`)
|
|
127
|
+
return 1
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (require.main === module) process.exit(main())
|
|
132
|
+
|
|
133
|
+
module.exports = { createShortcuts, main }
|