magpie-select-translate 0.3.0 → 0.3.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.
package/bin/helper.exe CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magpie-select-translate",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "划词翻译:选中文字按热键,鼠标旁浮窗流式显示 magpie 模型的译文。Select-to-translate popover for magpie: hit a hotkey on any selection and the translation streams next to your cursor.",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
package/page/index.html CHANGED
@@ -13,30 +13,37 @@
13
13
  p { margin: 0 0 8px; font-size: 12px; opacity: .7; }
14
14
  code { font-family: Consolas, monospace; }
15
15
  </style>
16
+ <!-- magpie 的页面桥:页面必须让它报到(hello),10 秒没报到 magpie 就当页面没响应 -->
17
+ <script src="_magpie/bridge.js"></script>
16
18
  </head>
17
19
  <body>
18
20
  <h1>划词翻译</h1>
19
21
  <p id="said">正在打开设置页…</p>
20
- <p>如果一直没跳转,说明 helper 没起来:设置页由 helper 提供,模型列表也要从本地网关读。
21
- 跑一次 <code>scripts\install.ps1</code>,或重开一次 magpie。</p>
22
+ <p>设置页由 helper 提供(模型列表要从本地网关读)。如果一直没跳转,说明 helper 没起来:
23
+ 跑一次 <code>scripts\install.ps1</code>,或重开一次 magpie。</p>
22
24
 
23
25
  <script>
24
26
  // 带路页:页面在沙箱里(connect-src 'none'),除了解释跳转什么网都联不上,
25
27
  // 所以不能先探活,直接跳到 helper 自己的设置页——那边能读网关模型、能写设置。
26
28
  (async () => {
27
- const fallback = 3477
28
- let port = fallback
29
+ // 碰 magpie.ready 才会给 magpie 发 hello(bridge.js 里就是 call("hello")),
30
+ // 少了这一步 magpie 10 秒后显示“此页面已停止工作 / 页面没有响应”。
31
+ // 只是别被它拖住跳转:magpie 没答就自己走。
32
+ await Promise.race([window.magpie?.ready, new Promise((r) => setTimeout(r, 1500))])
33
+
34
+ let port = 3477
29
35
  try {
30
36
  const opts = await window.magpie?.options?.get?.()
31
37
  if (opts && Number(opts.port) > 0) port = Number(opts.port)
32
38
  } catch { /* 没有宿主就用默认端口 */ }
33
- const target = "http://127.0.0.1:" + port + "/"
34
- // WebKit/WebView2 跳不过去时不报错,页面会停在“正在打开”。5 秒后还没被替换就提示一下。
39
+
40
+ // WebKit/WebView2 跳不过去时不报错,页面会一直停在“正在打开”:5 秒后提示一下。
35
41
  setTimeout(() => {
36
42
  const said = document.getElementById("said")
37
43
  if (said) said.textContent = "没能连上 helper(127.0.0.1:" + port + ")"
38
44
  }, 5000)
39
- location.replace(target)
45
+
46
+ location.replace("http://127.0.0.1:" + port + "/")
40
47
  })()
41
48
  </script>
42
49
  </body>