@binblink/wasmnest-plugin-sdk-desktop 0.0.0-stage → 0.0.2

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 (271) hide show
  1. package/README.md +307 -2
  2. package/README_en.md +284 -0
  3. package/bin/cli.js +602 -0
  4. package/bin/manifest-gen.js +458 -0
  5. package/bin/manifest-validate.js +494 -0
  6. package/bin/permission-vocabulary.json +5 -0
  7. package/bin/plugin-watch.js +331 -0
  8. package/bin/wasm-hash.js +124 -0
  9. package/dev-shell/README.md +122 -0
  10. package/dev-shell/index.html +12 -0
  11. package/dev-shell/package.json +28 -0
  12. package/dev-shell/pnpm-workspace.yaml +9 -0
  13. package/dev-shell/postcss.config.js +6 -0
  14. package/dev-shell/src/App.vue +90 -0
  15. package/dev-shell/src/components/LogPanel.vue +90 -0
  16. package/dev-shell/src/loader.ts +104 -0
  17. package/dev-shell/src/locale.ts +29 -0
  18. package/dev-shell/src/locales.ts +50 -0
  19. package/dev-shell/src/main.ts +46 -0
  20. package/dev-shell/src/mock/app-env.ts +102 -0
  21. package/dev-shell/src/mock/commands.ts +54 -0
  22. package/dev-shell/src/mock/domain-context.ts +46 -0
  23. package/dev-shell/src/mock/events.ts +16 -0
  24. package/dev-shell/src/mock/file-transfer.ts +512 -0
  25. package/dev-shell/src/mock/tauri-ipc.ts +109 -0
  26. package/dev-shell/src/registry.ts +90 -0
  27. package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
  28. package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
  29. package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
  30. package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
  31. package/dev-shell/src/shell/mount/appSession.ts +45 -0
  32. package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
  33. package/dev-shell/src/shell/types.ts +121 -0
  34. package/dev-shell/src/styles/dev.css +27 -0
  35. package/dev-shell/src/styles/shell.css +752 -0
  36. package/dev-shell/src/styles/style.css +1178 -0
  37. package/dev-shell/src/theme.ts +140 -0
  38. package/dev-shell/src/vite-env.d.ts +24 -0
  39. package/dev-shell/tailwind.config.js +98 -0
  40. package/dev-shell/vite.config.ts +174 -0
  41. package/dist/index.d.ts +150 -0
  42. package/dist/index.js +238 -0
  43. package/dist/types.d.ts +632 -0
  44. package/dist/types.js +0 -0
  45. package/dist/vite-plugin.d.ts +25 -0
  46. package/dist/vite-plugin.js +80 -0
  47. package/go/.gitignore +5 -0
  48. package/go/README.md +80 -0
  49. package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
  50. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
  51. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
  52. package/go/gen/wasmnest/app/host-app/empty.s +3 -0
  53. package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
  54. package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
  55. package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
  56. package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
  57. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
  58. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
  59. package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
  60. package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
  61. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
  62. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
  63. package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
  64. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
  65. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
  66. package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
  67. package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
  68. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
  69. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
  70. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
  71. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
  72. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
  73. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
  74. package/go/gen/wasmnest/http/host-http/abi.go +14 -0
  75. package/go/gen/wasmnest/http/host-http/empty.s +3 -0
  76. package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
  77. package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
  78. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
  79. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
  80. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
  81. package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
  82. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
  83. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
  84. package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
  85. package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
  86. package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
  87. package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
  88. package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
  89. package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
  90. package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
  91. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
  92. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
  93. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
  94. package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
  95. package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
  96. package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
  97. package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
  98. package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
  99. package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
  100. package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
  101. package/go/gen/wasmnest/plugin/command/empty.s +3 -0
  102. package/go/gen/wasmnest/plugin/events/empty.s +3 -0
  103. package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
  104. package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
  105. package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
  106. package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
  107. package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
  108. package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
  109. package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
  110. package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
  111. package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
  112. package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
  113. package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
  114. package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
  115. package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
  116. package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
  117. package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
  118. package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
  119. package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
  120. package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
  121. package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
  122. package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
  123. package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
  124. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
  125. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
  126. package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
  127. package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
  128. package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
  129. package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
  130. package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
  131. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
  132. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
  133. package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
  134. package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
  135. package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
  136. package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
  137. package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
  138. package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
  139. package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
  140. package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
  141. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
  142. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
  143. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
  144. package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
  145. package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
  146. package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
  147. package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
  148. package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
  149. package/go/gen/wasmnest/process/host-process/empty.s +3 -0
  150. package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
  151. package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
  152. package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
  153. package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
  154. package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
  155. package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
  156. package/go/gen/wasmnest/task/host-task/abi.go +14 -0
  157. package/go/gen/wasmnest/task/host-task/empty.s +3 -0
  158. package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
  159. package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
  160. package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
  161. package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
  162. package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
  163. package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
  164. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
  165. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
  166. package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
  167. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
  168. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
  169. package/go/go.mod +14 -0
  170. package/go/go.sum +2 -0
  171. package/go/sdk/dispatch.go +49 -0
  172. package/go/sdk/dispatch_test.go +81 -0
  173. package/go/sdk/entry_native.go +13 -0
  174. package/go/sdk/entry_wasip2.go +188 -0
  175. package/go/sdk/host_http_wasip2.go +42 -0
  176. package/go/sdk/host_wasip2.go +251 -0
  177. package/go/sdk/plugin.go +103 -0
  178. package/go/testplugin/index.js +1 -0
  179. package/go/testplugin/main.go +67 -0
  180. package/go/testplugin/plugin.json +24 -0
  181. package/go/tools/assemble-wit.mjs +152 -0
  182. package/go/tools/gen-bindings.mjs +51 -0
  183. package/go/wit/core.wit +273 -0
  184. package/go/wit/deps/api-call/cap-api-call.wit +20 -0
  185. package/go/wit/deps/app/cap-app.wit +54 -0
  186. package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
  187. package/go/wit/deps/clipboard/clipboard.wit +48 -0
  188. package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
  189. package/go/wit/deps/clocks/wall-clock.wit +42 -0
  190. package/go/wit/deps/clocks/world.wit +6 -0
  191. package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
  192. package/go/wit/deps/crypto/cap-crypto.wit +68 -0
  193. package/go/wit/deps/filesystem/preopens.wit +8 -0
  194. package/go/wit/deps/filesystem/types.wit +634 -0
  195. package/go/wit/deps/filesystem/world.wit +6 -0
  196. package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
  197. package/go/wit/deps/http/http.wit +28 -0
  198. package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
  199. package/go/wit/deps/io/error.wit +34 -0
  200. package/go/wit/deps/io/poll.wit +41 -0
  201. package/go/wit/deps/io/streams.wit +262 -0
  202. package/go/wit/deps/io/world.wit +6 -0
  203. package/go/wit/deps/mdns/mdns.wit +45 -0
  204. package/go/wit/deps/notify/notify.wit +51 -0
  205. package/go/wit/deps/peer/peer.wit +126 -0
  206. package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
  207. package/go/wit/deps/process/cap-process.wit +25 -0
  208. package/go/wit/deps/pty/pty.wit +80 -0
  209. package/go/wit/deps/random/insecure-seed.wit +25 -0
  210. package/go/wit/deps/random/insecure.wit +22 -0
  211. package/go/wit/deps/random/random.wit +26 -0
  212. package/go/wit/deps/random/world.wit +7 -0
  213. package/go/wit/deps/sockets/instance-network.wit +9 -0
  214. package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
  215. package/go/wit/deps/sockets/network.wit +145 -0
  216. package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
  217. package/go/wit/deps/sockets/tcp.wit +353 -0
  218. package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
  219. package/go/wit/deps/sockets/udp.wit +266 -0
  220. package/go/wit/deps/sockets/world.wit +11 -0
  221. package/go/wit/deps/task/cap-task.wit +56 -0
  222. package/go/wit/deps/timer/cap-timer.wit +14 -0
  223. package/go/wit/deps/wasi-cli/command.wit +7 -0
  224. package/go/wit/deps/wasi-cli/environment.wit +18 -0
  225. package/go/wit/deps/wasi-cli/exit.wit +4 -0
  226. package/go/wit/deps/wasi-cli/imports.wit +20 -0
  227. package/go/wit/deps/wasi-cli/run.wit +4 -0
  228. package/go/wit/deps/wasi-cli/stdio.wit +17 -0
  229. package/go/wit/deps/wasi-cli/terminal.wit +49 -0
  230. package/go/wit/deps/ws/ws.wit +50 -0
  231. package/go/wit/deps/ws-server/cap-ws.wit +99 -0
  232. package/go/wit/go-plugin.wit +28 -0
  233. package/go/wit/plugin-face.wit +355 -0
  234. package/go/wit/wasmnest.wit +25 -0
  235. package/package.json +100 -3
  236. package/src/config.ts +49 -0
  237. package/src/global-dialog.ts +169 -0
  238. package/src/index.ts +88 -0
  239. package/src/runtime.ts +54 -0
  240. package/src/types.ts +681 -0
  241. package/src/ui/AppUpdateSection.d.ts +44 -0
  242. package/src/ui/AppUpdateSection.vue +253 -0
  243. package/src/ui/MarkdownEditor.vue +520 -0
  244. package/src/ui/NumberField.d.ts +49 -0
  245. package/src/ui/NumberField.vue +390 -0
  246. package/src/ui/PluginGlobalDialog.vue +401 -0
  247. package/src/ui/Select.d.ts +36 -0
  248. package/src/ui/Select.vue +220 -0
  249. package/src/ui/TerminalInputRail.vue +184 -0
  250. package/src/ui/apply-select-position.ts +65 -0
  251. package/src/ui/markdown-editor-syntax.ts +234 -0
  252. package/src/ui/markdown-editor.d.ts +36 -0
  253. package/src/ui/plugin-global-dialog.d.ts +12 -0
  254. package/src/ui/select-position.ts +79 -0
  255. package/src/ui/terminal-input-rail.d.ts +30 -0
  256. package/src/ui/zoom-compensation.d.ts +9 -0
  257. package/src/ui/zoom-compensation.ts +52 -0
  258. package/src/update.ts +123 -0
  259. package/src/vite-plugin.ts +124 -0
  260. package/template/README.md +39 -0
  261. package/template/package.json +23 -0
  262. package/template/plugin.json +14 -0
  263. package/template/rust/Cargo.toml +21 -0
  264. package/template/rust/src/lib.rs +39 -0
  265. package/template/src/env.d.ts +24 -0
  266. package/template/src/index.ts +37 -0
  267. package/template/tsconfig.json +17 -0
  268. package/template/vite.config.ts +21 -0
  269. package/tools/componentize/Cargo.lock +299 -0
  270. package/tools/componentize/Cargo.toml +18 -0
  271. package/tools/componentize/src/main.rs +197 -0
@@ -0,0 +1,44 @@
1
+ import type { DefineComponent } from 'vue'
2
+ import type { AppUpdateCheckResult } from '../types'
3
+
4
+ /** 默认更新卡片文案(应用可覆盖任意字段;`{version}` 由组件替换) */
5
+ export interface AppUpdateLabels {
6
+ title: string
7
+ check: string
8
+ checking: string
9
+ upToDate: string
10
+ available: string
11
+ incompatible: string
12
+ failed: string
13
+ unsupported: string
14
+ reasonNoCompat: string
15
+ reasonMountContract: string
16
+ reasonHostRuntime: string
17
+ reasonHostRuntimeInvalid: string
18
+ }
19
+
20
+ /** AppUpdateSection 组件 props */
21
+ export interface AppUpdateSectionProps {
22
+ /** 当前版本(可选;不传时用检查结果的 currentVersion) */
23
+ currentVersion?: string
24
+ /** 自定义检查器;缺省使用宿主 `PluginContext.appUpdate.check` */
25
+ check?: () => Promise<AppUpdateCheckResult>
26
+ /** 文案覆盖(缺省按系统语言内置中 / 英) */
27
+ labels?: Partial<AppUpdateLabels>
28
+ disabled?: boolean
29
+ }
30
+
31
+ /**
32
+ * 应用更新检查卡片(SDK 默认实现)
33
+ *
34
+ * 用法(应用设置页直接嵌入):
35
+ * ```vue
36
+ * <AppUpdateSection />
37
+ * ```
38
+ * - 数据面 = 宿主 `PluginContext.appUpdate.check`(GitHub Release 统一判定)
39
+ * - 应用自实现更新检查时传 `check` 覆盖,或完全不用本组件
40
+ * - 更新动作统一在宿主应用管理页执行(需停用应用 + 换目录 + 重新审批)
41
+ */
42
+ export declare const AppUpdateSection: DefineComponent<AppUpdateSectionProps>
43
+
44
+ export default AppUpdateSection
@@ -0,0 +1,253 @@
1
+ <template>
2
+ <!--
3
+ 应用更新检查(SDK 默认实现)
4
+
5
+ 应用设置页直接嵌入即可:宿主提供 GitHub Release 判定,本组件只负责状态与
6
+ 展示。应用想自实现时不必使用本组件(或传 `check` 覆盖数据面)。
7
+ -->
8
+ <section class="wasmnest-update" data-testid="sdk-app-update">
9
+ <div class="wasmnest-update__row">
10
+ <div class="wasmnest-update__main">
11
+ <span v-if="text.title" class="wasmnest-update__title">{{ text.title }}</span>
12
+ <span v-if="versionLabel" class="wasmnest-update__version">{{ versionLabel }}</span>
13
+ </div>
14
+ <button
15
+ type="button"
16
+ class="wasmnest-update__button"
17
+ :disabled="disabled || checking || !supported"
18
+ :aria-busy="checking"
19
+ data-testid="sdk-app-update-check"
20
+ @click="onCheck"
21
+ >
22
+ {{ checking ? text.checking : text.check }}
23
+ </button>
24
+ </div>
25
+ <p
26
+ v-if="statusLabel"
27
+ class="wasmnest-update__status"
28
+ :class="{ 'is-error': isBad, 'is-available': status === 'available' }"
29
+ data-testid="sdk-app-update-status"
30
+ >
31
+ {{ statusLabel }}
32
+ </p>
33
+ <p
34
+ v-if="reasonLabel"
35
+ class="wasmnest-update__status is-error"
36
+ data-testid="sdk-app-update-reason"
37
+ >
38
+ {{ reasonLabel }}
39
+ </p>
40
+ </section>
41
+ </template>
42
+
43
+ <script setup lang="ts">
44
+ /**
45
+ * AppUpdateSection — SDK 默认应用更新卡片(双端同形)
46
+ *
47
+ * 数据面:`PluginContext.appUpdate.check`(宿主统一实现)或调用方传入的 `check`
48
+ * (应用自实现)。状态机在 `useAppUpdate`;本组件只做展示,不发起安装——
49
+ * 更新动作统一收口在宿主应用管理页(需要先停用应用、替换插件目录并重新审批)。
50
+ *
51
+ * 视觉:只依赖 `--mobile-*` / 桌面 `--bg-card` 等 token 的回退组合,不引入
52
+ * 任何一端专属组件;应用可在外层继续套自己的卡片样式。
53
+ */
54
+ import { computed } from 'vue'
55
+ import { useAppUpdate } from '../update'
56
+ import type { AppUpdateCheckResult } from '../types'
57
+
58
+ /** 文案包(应用可覆盖任意字段;`{version}` 由组件替换) */
59
+ export interface AppUpdateLabels {
60
+ title: string
61
+ check: string
62
+ checking: string
63
+ upToDate: string
64
+ available: string
65
+ incompatible: string
66
+ failed: string
67
+ unsupported: string
68
+ reasonNoCompat: string
69
+ reasonMountContract: string
70
+ reasonHostRuntime: string
71
+ reasonHostRuntimeInvalid: string
72
+ }
73
+
74
+ const props = withDefaults(
75
+ defineProps<{
76
+ /** 当前版本(可选;不传时用检查结果的 currentVersion) */
77
+ currentVersion?: string
78
+ /** 自定义检查器;缺省使用宿主 `PluginContext.appUpdate.check` */
79
+ check?: () => Promise<AppUpdateCheckResult>
80
+ /** 文案覆盖(缺省按系统语言内置中 / 英) */
81
+ labels?: Partial<AppUpdateLabels>
82
+ disabled?: boolean
83
+ }>(),
84
+ { currentVersion: '', check: undefined, labels: undefined, disabled: false },
85
+ )
86
+
87
+ const ZH: AppUpdateLabels = {
88
+ title: '版本更新',
89
+ check: '检查更新',
90
+ checking: '正在检查…',
91
+ upToDate: '已是最新版本(v{version})',
92
+ available: '发现新版本 v{version};请在应用管理中更新',
93
+ incompatible: '发现新版本 v{version},但与当前平台不兼容',
94
+ failed: '检查失败,请稍后重试',
95
+ unsupported: '当前平台不提供更新检查',
96
+ reasonNoCompat: '该发布物缺少兼容声明(旧版发布格式),无法确认与当前平台兼容',
97
+ reasonMountContract: '要求挂载契约 {required},当前平台为 {current}',
98
+ reasonHostRuntime: '要求宿主运行时 {required},当前为 {current};请先升级平台',
99
+ reasonHostRuntimeInvalid: '兼容声明版本形态异常({required}),已拒绝',
100
+ }
101
+
102
+ const EN: AppUpdateLabels = {
103
+ title: 'Version update',
104
+ check: 'Check for updates',
105
+ checking: 'Checking…',
106
+ upToDate: 'Up to date (v{version})',
107
+ available: 'v{version} available; update it in App Management',
108
+ incompatible: 'v{version} found, but it is incompatible with this platform',
109
+ failed: 'Update check failed, try again later',
110
+ unsupported: 'Update check is not available on this platform',
111
+ reasonNoCompat:
112
+ 'The release lacks a compatibility declaration (legacy format); compatibility cannot be confirmed',
113
+ reasonMountContract: 'Requires mount contract {required}; this platform is {current}',
114
+ reasonHostRuntime:
115
+ 'Requires host runtime {required}; this platform is {current}. Upgrade the platform first',
116
+ reasonHostRuntimeInvalid: 'Malformed compatibility version ({required}); refused',
117
+ }
118
+
119
+ const text = computed<AppUpdateLabels>(() => {
120
+ const isZh = typeof navigator !== 'undefined' && navigator.language.toLowerCase().startsWith('zh')
121
+ return { ...(isZh ? ZH : EN), ...(props.labels ?? {}) }
122
+ })
123
+
124
+ const {
125
+ status,
126
+ latestVersion,
127
+ currentVersion,
128
+ reason,
129
+ checking,
130
+ supported,
131
+ check: runCheck,
132
+ } = useAppUpdate({ check: props.check })
133
+
134
+ const versionLabel = computed(() => {
135
+ const v = props.currentVersion || currentVersion.value
136
+ return v ? `v${v}` : ''
137
+ })
138
+
139
+ function fill(template: string, params: Record<string, string | undefined>): string {
140
+ return template.replace(/\{(\w+)\}/g, (_, key: string) => params[key] ?? '')
141
+ }
142
+
143
+ const statusLabel = computed(() => {
144
+ if (!supported.value) return text.value.unsupported
145
+ switch (status.value) {
146
+ case 'checking':
147
+ return text.value.checking
148
+ case 'up-to-date':
149
+ return fill(text.value.upToDate, {
150
+ version: latestVersion.value || currentVersion.value || '',
151
+ })
152
+ case 'available':
153
+ return fill(text.value.available, { version: latestVersion.value || '' })
154
+ case 'incompatible':
155
+ return fill(text.value.incompatible, { version: latestVersion.value || '' })
156
+ case 'error':
157
+ return text.value.failed
158
+ default:
159
+ return ''
160
+ }
161
+ })
162
+
163
+ const isBad = computed(() => status.value === 'error' || status.value === 'incompatible')
164
+
165
+ const reasonLabel = computed(() => {
166
+ const r = reason.value
167
+ if (!r) return ''
168
+ const params = { ...(r.params ?? {}), version: latestVersion.value }
169
+ if (r.key.endsWith('noCompat')) return text.value.reasonNoCompat
170
+ if (r.key.endsWith('mountContract')) return fill(text.value.reasonMountContract, params)
171
+ if (r.key.endsWith('hostRuntimeInvalid')) return fill(text.value.reasonHostRuntimeInvalid, params)
172
+ if (r.key.endsWith('hostRuntime')) return fill(text.value.reasonHostRuntime, params)
173
+ return ''
174
+ })
175
+
176
+ function onCheck(): void {
177
+ void runCheck()
178
+ }
179
+
180
+ defineExpose({ check: runCheck })
181
+ </script>
182
+
183
+ <style scoped>
184
+ .wasmnest-update {
185
+ border: 1px solid var(--mobile-border, var(--border, rgba(127, 127, 127, 0.28)));
186
+ background: var(--mobile-bg-card, var(--bg-card, transparent));
187
+ border-radius: var(--mobile-radius-lg, 12px);
188
+ padding: 10px 12px;
189
+ display: flex;
190
+ flex-direction: column;
191
+ gap: 6px;
192
+ }
193
+
194
+ .wasmnest-update__row {
195
+ display: flex;
196
+ align-items: center;
197
+ gap: 10px;
198
+ }
199
+
200
+ .wasmnest-update__main {
201
+ flex: 1;
202
+ min-width: 0;
203
+ display: flex;
204
+ align-items: baseline;
205
+ gap: 8px;
206
+ }
207
+
208
+ .wasmnest-update__title {
209
+ font-size: 14px;
210
+ font-weight: 600;
211
+ color: var(--mobile-text-primary, var(--text-primary, inherit));
212
+ }
213
+
214
+ .wasmnest-update__version {
215
+ font-size: 12px;
216
+ color: var(--mobile-text-secondary, var(--text-secondary, #888));
217
+ font-variant-numeric: tabular-nums;
218
+ }
219
+
220
+ .wasmnest-update__button {
221
+ flex-shrink: 0;
222
+ min-height: var(--mobile-touch-target-min, 32px);
223
+ padding: 0 12px;
224
+ border-radius: var(--mobile-radius-md, 8px);
225
+ border: 1px solid var(--mobile-border, var(--border, rgba(127, 127, 127, 0.28)));
226
+ background: transparent;
227
+ color: var(--mobile-accent, var(--brand, #4f8cff));
228
+ font-size: 12px;
229
+ font-weight: 600;
230
+ cursor: pointer;
231
+ transition: opacity 0.2s ease;
232
+ }
233
+
234
+ .wasmnest-update__button:disabled {
235
+ opacity: 0.5;
236
+ cursor: not-allowed;
237
+ }
238
+
239
+ .wasmnest-update__status {
240
+ margin: 0;
241
+ font-size: 12px;
242
+ line-height: 1.5;
243
+ color: var(--mobile-text-secondary, var(--text-secondary, #888));
244
+ }
245
+
246
+ .wasmnest-update__status.is-available {
247
+ color: var(--mobile-accent, var(--brand, #4f8cff));
248
+ }
249
+
250
+ .wasmnest-update__status.is-error {
251
+ color: var(--mobile-error, var(--danger, #e5484d));
252
+ }
253
+ </style>