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

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/main.js +12 -10
  2. package/package.json +1 -1
  3. package/start.html +2 -0
package/main.js CHANGED
@@ -132,9 +132,10 @@ if (args.version) {
132
132
 
133
133
  const hubPrefix = () => cfg.hub.replace(/\/$/, '')
134
134
  const singleWindow = cfg.singleWindow === true
135
- const showStart = () => {
135
+ const showStart = error => {
136
136
  if (!mainWindow || mainWindow.isDestroyed()) return
137
- void mainWindow.loadFile(path.join(__dirname, 'start.html'))
137
+ const options = error ? { query: { error: String(error).slice(0, 200) } } : undefined
138
+ void mainWindow.loadFile(path.join(__dirname, 'start.html'), options)
138
139
  }
139
140
 
140
141
  const fromStartPage = event => String(event.senderFrame?.url ?? '').startsWith('file://')
@@ -288,17 +289,18 @@ if (args.version) {
288
289
  })
289
290
 
290
291
  // 加载失败时给出可读提示,而不是白屏。
291
- mainWindow.webContents.on('did-fail-load', (_event, code, description, url) => {
292
+ mainWindow.webContents.on('did-fail-load', (_event, code, description, url, isMainFrame) => {
293
+ if (isMainFrame === false) return
294
+ if (code === -3) return // 主动导航取消
295
+ // 连接失败:先回到连接页(可编辑地址),再弹提示。
296
+ showStart(`${description}(${code})`)
292
297
  void dialog.showMessageBox(mainWindow, {
293
298
  type: 'error',
294
- title: '无法打开 hub',
295
- message: `加载失败:${description}(${code})`,
296
- detail: `${url}\n\n请检查网络、hub 地址与证书。配置文件:${file}`,
297
- buttons: ['设置 Hub 地址…', '知道了'],
299
+ title: '无法连接 Hub',
300
+ message: `连接失败:${description}(${code})`,
301
+ detail: `${url}\n\n请检查地址与网络,修改后重试。`,
302
+ buttons: ['返回连接页'],
298
303
  defaultId: 0,
299
- cancelId: 1,
300
- }).then(result => {
301
- if (result.response === 0) showStart()
302
304
  })
303
305
  console.error(`[${APP_NAME}] 加载失败 ${code} ${description} ${url}`)
304
306
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunshine-star/dsh-access-pc",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "DSH Access PC client (Electron shell around the hub console)",
5
5
  "main": "main.js",
6
6
  "bin": {
package/start.html CHANGED
@@ -57,6 +57,8 @@
57
57
  const input = document.getElementById('hub')
58
58
  const err = document.getElementById('err')
59
59
  const button = document.getElementById('connect')
60
+ const failed = new URLSearchParams(location.search).get('error')
61
+ if (failed) err.textContent = '连接失败:' + failed
60
62
  window.start.get().then(value => {
61
63
  input.value = value || ''
62
64
  input.focus()