@sunshine-star/dsh-access-pc 0.1.8 → 0.1.10

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/main.js CHANGED
@@ -22,6 +22,7 @@ const DEFAULT_WINDOW = '1440,900'
22
22
  // 客户端只渲染一个网页,软件渲染足够,先关掉更稳。
23
23
  app.disableHardwareAcceleration()
24
24
  if (process.platform === 'win32') app.setAppUserModelId('com.sunshine-star.dsh-access')
25
+ app.setName('dsh-access-pc')
25
26
 
26
27
  /** 解析 --key value 形式的参数。 */
27
28
  function parseArgs(argv) {
@@ -143,6 +144,7 @@ if (args.version) {
143
144
  if (!fromStartPage(event)) throw new Error('forbidden')
144
145
  return cfg.hub
145
146
  })
147
+ ipcMain.on('app:show-start', () => showStart())
146
148
  ipcMain.handle('start:connect', (event, value) => {
147
149
  if (!fromStartPage(event)) throw new Error('forbidden')
148
150
  const hub = String(value ?? '').trim().replace(/\/$/, '')
@@ -186,6 +188,31 @@ if (args.version) {
186
188
  })()`, true).catch(() => {})
187
189
  }
188
190
 
191
+ const LOGIN_BACK_ID = '__dsh_connect_back'
192
+ const installLoginBackButton = contents => {
193
+ let url
194
+ try { url = new URL(contents.getURL()) } catch { return }
195
+ if (url.pathname !== '/login' && url.pathname !== '/login/') return
196
+ contents.executeJavaScript(`(() => {
197
+ if (document.getElementById('${LOGIN_BACK_ID}')) return
198
+ const button = document.createElement('button')
199
+ button.id = '${LOGIN_BACK_ID}'
200
+ button.type = 'button'
201
+ button.title = '返回连接页'
202
+ button.textContent = String.fromCharCode(8592)
203
+ Object.assign(button.style, {
204
+ position: 'fixed', left: '10px', top: '50%', transform: 'translateY(-50%)',
205
+ width: '38px', height: '38px', borderRadius: '19px',
206
+ border: '1px solid rgba(124,156,255,.55)', background: 'rgba(20,27,49,.88)',
207
+ color: '#e8ecf7', fontSize: '18px', lineHeight: '1', cursor: 'pointer',
208
+ zIndex: '2147483647', boxShadow: '0 6px 20px rgba(0,0,0,.35)',
209
+ backdropFilter: 'blur(6px)',
210
+ })
211
+ button.addEventListener('click', () => { window.start?.back?.() })
212
+ document.body.appendChild(button)
213
+ })()`, true).catch(() => {})
214
+ }
215
+
189
216
  app.on('web-contents-created', (_event, contents) => {
190
217
  // 右键菜单:导航、链接、编辑、检查元素。
191
218
  contents.on('context-menu', (_event, params) => {
@@ -230,8 +257,8 @@ if (args.version) {
230
257
  Menu.buildFromTemplate(items).popup({ window })
231
258
  })
232
259
 
233
- contents.on('did-finish-load', () => installHostBackButton(contents))
234
- contents.on('did-navigate-in-page', () => installHostBackButton(contents))
260
+ contents.on('did-finish-load', () => { installHostBackButton(contents); installLoginBackButton(contents) })
261
+ contents.on('did-navigate-in-page', () => { installHostBackButton(contents); installLoginBackButton(contents) })
235
262
  // 单窗口模式下没有浏览器工具栏,Alt+← 用来回主机列表。
236
263
  contents.on('before-input-event', (event, input) => {
237
264
  if (input.type !== 'keyDown') return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunshine-star/dsh-access-pc",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "DSH Access PC client (Electron shell around the hub console)",
5
5
  "main": "main.js",
6
6
  "bin": {
@@ -87,17 +87,47 @@ Type=Application
87
87
  Name=${APP_NAME}
88
88
  Comment=Remote DSH client
89
89
  Exec="${electron}" "${appDir}"
90
- Icon=${iconPng}
90
+ Icon=dsh-access-pc
91
91
  Terminal=false
92
92
  Categories=Network;RemoteAccess;
93
93
  StartupWMClass=dsh-access-pc
94
94
  `
95
95
  }
96
96
 
97
+ function markTrusted(file) {
98
+ try {
99
+ spawnSync('gio', ['set', file, 'metadata::trusted', 'true'], { stdio: 'ignore' })
100
+ } catch {
101
+ // 没有 gio 或非 GNOME 环境,忽略。
102
+ }
103
+ }
104
+
105
+ function installLinuxIcon() {
106
+ const home = os.homedir()
107
+ const sizes = [
108
+ [256, path.join(appDir, 'assets', 'icon-256.png')],
109
+ [512, path.join(appDir, 'assets', 'icon-512.png')],
110
+ ]
111
+ for (const [size, source] of sizes) {
112
+ if (!fs.existsSync(source)) continue
113
+ const target = path.join(home, '.local', 'share', 'icons', 'hicolor', `${size}x${size}`, 'apps', 'dsh-access-pc.png')
114
+ fs.mkdirSync(path.dirname(target), { recursive: true })
115
+ fs.copyFileSync(source, target)
116
+ fs.chmodSync(target, 0o644)
117
+ }
118
+ try {
119
+ spawnSync('gtk-update-icon-cache', ['-f', '-t', path.join(home, '.local', 'share', 'icons', 'hicolor')], { stdio: 'ignore' })
120
+ } catch {
121
+ // 忽略
122
+ }
123
+ }
124
+
97
125
  function createLinuxEntry(targetPath) {
98
126
  fs.mkdirSync(path.dirname(targetPath), { recursive: true })
127
+ installLinuxIcon()
99
128
  fs.writeFileSync(targetPath, desktopEntry())
100
129
  fs.chmodSync(targetPath, 0o755)
130
+ markTrusted(targetPath)
101
131
  return targetPath
102
132
  }
103
133
 
@@ -116,11 +146,17 @@ function createShortcuts({ desktop = true, menu = true } = {}) {
116
146
  const base = path.join(os.homedir(), '.local', 'share', 'applications')
117
147
  const entry = path.join(base, 'dsh-access-pc.desktop')
118
148
  created.push(createLinuxEntry(entry))
149
+ try {
150
+ spawnSync('update-desktop-database', [base], { stdio: 'ignore' })
151
+ } catch {
152
+ // 忽略
153
+ }
119
154
  if (desktop) {
120
155
  const desktopPath = path.join(desktopDir(), 'dsh-access-pc.desktop')
121
156
  try {
122
157
  fs.copyFileSync(entry, desktopPath)
123
158
  fs.chmodSync(desktopPath, 0o755)
159
+ markTrusted(desktopPath)
124
160
  created.push(desktopPath)
125
161
  } catch {
126
162
  // 没有桌面目录就只留应用菜单项。
package/start-preload.js CHANGED
@@ -3,4 +3,5 @@ const { contextBridge, ipcRenderer } = require('electron')
3
3
  contextBridge.exposeInMainWorld('start', {
4
4
  get: () => ipcRenderer.invoke('start:get'),
5
5
  connect: hub => ipcRenderer.invoke('start:connect', hub),
6
+ back: () => ipcRenderer.send('app:show-start'),
6
7
  })