@sunshine-star/dsh-access-pc 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/main.js +42 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -48,7 +48,8 @@ npx -y @sunshine-star/dsh-access-pc --hub http://10.168.1.185:8080
48
48
  (菜单栏默认隐藏,按一下 `Alt` 可显示“导航”菜单);
49
49
  - 需要账号页与多个 DSH 页并存:`npm start -- --multi-window`(或配置 `"singleWindow": false`),
50
50
  新窗口独立于打开者,关掉账号页不会连带关掉已打开的 DSH 窗口(`outlivesOpener`);
51
- - 站外链接交给系统浏览器。
51
+ - 站外链接交给系统浏览器;**右键菜单**提供:主机列表 / 返回 / 刷新 / 复制页面地址 / 检查元素,
52
+ 链接上额外有“在浏览器中打开链接”“复制链接地址”,输入框内为剪切/复制/粘贴/全选。
52
53
 
53
54
  ## 与 Go 客户端的关系
54
55
 
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')
@@ -159,6 +159,47 @@ if (args.version) {
159
159
  }
160
160
 
161
161
  app.on('web-contents-created', (_event, contents) => {
162
+ // 右键菜单:导航、链接、编辑、检查元素。
163
+ contents.on('context-menu', (_event, params) => {
164
+ const window = BrowserWindow.fromWebContents(contents)
165
+ if (!window || window.isDestroyed()) return
166
+ const items = [
167
+ {
168
+ label: '主机列表',
169
+ click: () => {
170
+ if (mainWindow && !mainWindow.isDestroyed()) void mainWindow.loadURL(cfg.hub)
171
+ },
172
+ },
173
+ {
174
+ label: '返回',
175
+ enabled: Boolean(contents.navigationHistory?.canGoBack?.()),
176
+ click: () => contents.navigationHistory?.goBack?.(),
177
+ },
178
+ { label: '刷新', click: () => contents.reload() },
179
+ { type: 'separator' },
180
+ ]
181
+ if (params.linkURL) {
182
+ items.push({ label: '在浏览器中打开链接', click: () => { void shell.openExternal(params.linkURL) } })
183
+ items.push({ label: '复制链接地址', click: () => { clipboard.writeText(params.linkURL) } })
184
+ items.push({ type: 'separator' })
185
+ }
186
+ if (params.isEditable) {
187
+ items.push(
188
+ { role: 'cut', label: '剪切' },
189
+ { role: 'copy', label: '复制' },
190
+ { role: 'paste', label: '粘贴' },
191
+ { role: 'selectAll', label: '全选' },
192
+ )
193
+ } else if (params.selectionText) {
194
+ items.push({ role: 'copy', label: '复制' })
195
+ } else {
196
+ items.push({ label: '复制页面地址', click: () => { clipboard.writeText(contents.getURL()) } })
197
+ }
198
+ items.push({ type: 'separator' })
199
+ items.push({ label: '检查元素', click: () => contents.inspectElement(params.x, params.y) })
200
+ Menu.buildFromTemplate(items).popup({ window })
201
+ })
202
+
162
203
  contents.on('did-finish-load', () => installHostBackButton(contents))
163
204
  contents.on('did-navigate-in-page', () => installHostBackButton(contents))
164
205
  // 单窗口模式下没有浏览器工具栏,Alt+← 用来回主机列表。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunshine-star/dsh-access-pc",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "DSH Access PC client (Electron shell around the hub console)",
5
5
  "main": "main.js",
6
6
  "bin": {