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

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.9",
4
4
  "description": "DSH Access PC client (Electron shell around the hub console)",
5
5
  "main": "main.js",
6
6
  "bin": {
@@ -94,10 +94,19 @@ 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
+
97
105
  function createLinuxEntry(targetPath) {
98
106
  fs.mkdirSync(path.dirname(targetPath), { recursive: true })
99
107
  fs.writeFileSync(targetPath, desktopEntry())
100
108
  fs.chmodSync(targetPath, 0o755)
109
+ markTrusted(targetPath)
101
110
  return targetPath
102
111
  }
103
112
 
@@ -116,11 +125,17 @@ function createShortcuts({ desktop = true, menu = true } = {}) {
116
125
  const base = path.join(os.homedir(), '.local', 'share', 'applications')
117
126
  const entry = path.join(base, 'dsh-access-pc.desktop')
118
127
  created.push(createLinuxEntry(entry))
128
+ try {
129
+ spawnSync('update-desktop-database', [base], { stdio: 'ignore' })
130
+ } catch {
131
+ // 忽略
132
+ }
119
133
  if (desktop) {
120
134
  const desktopPath = path.join(desktopDir(), 'dsh-access-pc.desktop')
121
135
  try {
122
136
  fs.copyFileSync(entry, desktopPath)
123
137
  fs.chmodSync(desktopPath, 0o755)
138
+ markTrusted(desktopPath)
124
139
  created.push(desktopPath)
125
140
  } catch {
126
141
  // 没有桌面目录就只留应用菜单项。
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
  })