@sunshine-star/dsh-access-pc 0.1.1 → 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 +13 -0
- 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 +2 -0
- 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
|
|
|
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
|
@@ -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) {
|
|
@@ -241,6 +242,7 @@ if (args.version) {
|
|
|
241
242
|
minWidth: 960,
|
|
242
243
|
minHeight: 640,
|
|
243
244
|
title: 'DSH Access',
|
|
245
|
+
icon: path.join(__dirname, 'assets', process.platform === 'win32' ? 'icon.ico' : 'icon.png'),
|
|
244
246
|
backgroundColor: '#0b1220',
|
|
245
247
|
autoHideMenuBar: true,
|
|
246
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 }
|