@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,140 @@
1
+ /**
2
+ * 宿主界面设置(桌面端 dev-shell)——与宿主 `useTheme` / `useFontSize` 同语义
3
+ * -----------------------------------------------------------------------------
4
+ * - 主题模式:light / dark / system,切换 <html> 的 .dark 类(style.css 的
5
+ * :root.dark 变量组生效)。
6
+ * - 字体大小:以 px 存储(12 = "正常"档位),实际生效为 :root 的 `--ui-scale`
7
+ * 缩放因子(所有界面文字尺寸都写成 calc(基准px * var(--ui-scale)),等比缩放)。
8
+ * - 全部持久化到 localStorage,启动时由 initHostUi() 恢复,避免刷新回退。
9
+ *
10
+ * 与宿主的两处**刻意一致**(不是简化):
11
+ * - **色板不再落到 documentElement**:宿主 `useTheme` 已明确「色板是各 wasm-app
12
+ * 自己的样式主题,宿主壳固定用默认色板」,dev-shell 曾自行给 <html> 写
13
+ * data-palette —— 那会让预览与真机呈现两套配色,故一并退役。
14
+ * - **Linux 基线缩放**:`--ui-scale` 的换算与宿主 `computeUiScale` 逐字同式
15
+ * (Linux 额外 ×1.15),且给 <html> 加 `platform-linux` 类(宿主 style.css 的
16
+ * `html.platform-linux` 规则需要它:根字号 115% + rem 间距同比例放大)。
17
+ */
18
+ import { ref } from 'vue'
19
+
20
+ export type ThemeMode = 'light' | 'dark' | 'system'
21
+
22
+ /** "正常"档位对应的基准字号(px),即默认界面文字大小 */
23
+ export const NORMAL_FONT_SIZE = 12
24
+ /** 滑杆档位范围:小(10) / 正常(12) / 大(14) / 超大(16) */
25
+ export const MIN_FONT_SIZE = 10
26
+ export const MAX_FONT_SIZE = 16
27
+ /** Linux 平台基线 UI 缩放因子(与宿主 useFontSize.PLATFORM_UI_SCALE 同值) */
28
+ export const PLATFORM_UI_SCALE = 1.15
29
+
30
+ const THEME_KEY = 'wasmnest-dev-shell:theme'
31
+ const FONT_SIZE_KEY = 'wasmnest-dev-shell:font-size'
32
+
33
+ const theme = ref<ThemeMode>('system')
34
+ const fontSize = ref<number>(NORMAL_FONT_SIZE)
35
+
36
+ let systemQuery: MediaQueryList | null = null
37
+
38
+ /**
39
+ * 是否 Linux 桌面(宿主经 Tauri 平台信息判定;dev-shell 在浏览器里只能看 UA)
40
+ *
41
+ * Android 的 UA 同样含 "Linux",需排除——宿主那边 Android 走移动端路径,
42
+ * 不叠这层基线缩放。
43
+ */
44
+ export function isLinuxDesktop(): boolean {
45
+ if (typeof navigator === 'undefined') return false
46
+ const ua = navigator.userAgent
47
+ if (/Android/i.test(ua)) return false
48
+ return /Linux|X11/i.test(ua)
49
+ }
50
+
51
+ /**
52
+ * 档位字号 → --ui-scale 换算(纯函数,与宿主 `computeUiScale` 同式)
53
+ *
54
+ * scale = 设置档位 / 正常档位 × (Linux ? PLATFORM_UI_SCALE : 1)。
55
+ * Linux 基线因子只对 Linux 生效——Windows/macOS 必须返回 1.0,
56
+ * 否则为 Linux 调整的字号会泄漏到其他平台。
57
+ */
58
+ export function computeUiScale(size: number, isLinux: boolean): number {
59
+ const clamped = Math.min(MAX_FONT_SIZE, Math.max(MIN_FONT_SIZE, size))
60
+ return (clamped / NORMAL_FONT_SIZE) * (isLinux ? PLATFORM_UI_SCALE : 1)
61
+ }
62
+
63
+ /** 按当前模式 + 系统偏好应用 .dark 类(与宿主 useTheme.applyTheme 同逻辑) */
64
+ function applyTheme(): void {
65
+ const isDark = theme.value === 'system' ? (systemQuery?.matches ?? false) : theme.value === 'dark'
66
+ document.documentElement.classList.toggle('dark', isDark)
67
+ }
68
+
69
+ /** 应用字体大小:字号 / 基准 得 --ui-scale 缩放因子(与宿主 applyFontSize 同式) */
70
+ function applyFontSize(): void {
71
+ const scale = computeUiScale(fontSize.value, isLinuxDesktop())
72
+ document.documentElement.style.setProperty('--ui-scale', String(scale), 'important')
73
+ }
74
+
75
+ function setupSystemListener(): void {
76
+ systemQuery?.removeEventListener('change', applyTheme)
77
+ systemQuery = window.matchMedia('(prefers-color-scheme: dark)')
78
+ systemQuery.addEventListener('change', applyTheme)
79
+ }
80
+
81
+ function teardownSystemListener(): void {
82
+ systemQuery?.removeEventListener('change', applyTheme)
83
+ systemQuery = null
84
+ }
85
+
86
+ /** 启动时调用(main.ts):恢复持久化的主题模式 / 字体大小并应用 */
87
+ export function initHostUi(): void {
88
+ try {
89
+ const savedTheme = localStorage.getItem(THEME_KEY)
90
+ if (savedTheme === 'light' || savedTheme === 'dark' || savedTheme === 'system') {
91
+ theme.value = savedTheme
92
+ }
93
+ const savedSize = Number(localStorage.getItem(FONT_SIZE_KEY))
94
+ if (Number.isFinite(savedSize) && savedSize >= MIN_FONT_SIZE && savedSize <= MAX_FONT_SIZE) {
95
+ fontSize.value = savedSize
96
+ }
97
+ } catch {
98
+ // 隐私模式等场景使用默认值
99
+ }
100
+ // Linux 基线:宿主 main.ts 的 initPlatform() 之后给 <html> 加同名类,
101
+ // style.css 的 `html.platform-linux` 规则(根字号 115%)据此生效
102
+ if (isLinuxDesktop()) {
103
+ document.documentElement.classList.add('platform-linux')
104
+ }
105
+ if (theme.value === 'system') setupSystemListener()
106
+ applyTheme()
107
+ applyFontSize()
108
+ }
109
+
110
+ /** 切换主题模式(持久化;system 时建立系统偏好监听) */
111
+ export function setTheme(mode: ThemeMode): void {
112
+ theme.value = mode
113
+ try {
114
+ localStorage.setItem(THEME_KEY, mode)
115
+ } catch {
116
+ // 忽略持久化失败
117
+ }
118
+ if (mode === 'system') {
119
+ setupSystemListener()
120
+ } else {
121
+ teardownSystemListener()
122
+ }
123
+ applyTheme()
124
+ }
125
+
126
+ /** 切换字体大小(px,持久化,即时生效) */
127
+ export function setFontSize(size: number): void {
128
+ fontSize.value = size
129
+ try {
130
+ localStorage.setItem(FONT_SIZE_KEY, String(size))
131
+ } catch {
132
+ // 忽略持久化失败
133
+ }
134
+ applyFontSize()
135
+ }
136
+
137
+ /** 供设置页读取/切换(响应式) */
138
+ export function useHostUi() {
139
+ return { theme, fontSize, setTheme, setFontSize }
140
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.vue' {
4
+ import type { DefineComponent } from 'vue'
5
+ const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
6
+ export default component
7
+ }
8
+
9
+ /**
10
+ * 虚拟模块:被调试应用列表(vite 虚拟模块,见 dev-shell/vite.config.ts)
11
+ *
12
+ * `entry` = 挂载包模块(app 的 `src/entry.ts`,导出 `mountApp`);缺失 = null。
13
+ * `devMock` = 领域种子模块(app 的 `src/index.ts`,导出 `devMock`);缺失 = null。
14
+ */
15
+ declare module 'virtual:dev-plugins' {
16
+ export interface DevPluginRecordSpec {
17
+ dir: string
18
+ manifest: Record<string, unknown>
19
+ entry: any
20
+ devMock: any
21
+ }
22
+ const records: DevPluginRecordSpec[]
23
+ export default records
24
+ }
@@ -0,0 +1,98 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ // 语义别名与宿主 wasmnest-desktop/tailwind.config.js 保持一致(theme 整段由
3
+ // dev-shell/__tests__/visualParity.test.ts 深比对锁定);
4
+ // content 追加 SDK ui 组件(../src)与被调试应用目录(env WASMNEST_DEV_PLUGINS)。
5
+ import { fileURLToPath } from 'node:url'
6
+ import { resolve } from 'node:path'
7
+
8
+ // 本文件是 ESM(无 __dirname),用 import.meta.url 定位 config 所在目录(dev-shell/ 根)
9
+ const CONFIG_DIR = fileURLToPath(new URL('.', import.meta.url))
10
+ // fast-glob 不支持 `..`(无论相对还是绝对路径),先 resolve 展开为纯绝对路径;
11
+ // glob pattern 分隔符必须是正斜杠(micromatch),Windows 反斜杠需转换
12
+ const SDK_UI_SRC = resolve(CONFIG_DIR, '../src').replace(/\\/g, '/')
13
+
14
+ export default {
15
+ content: [
16
+ './index.html',
17
+ './src/**/*.{vue,js,ts,jsx,tsx}',
18
+ // SDK 共享 UI 组件(@binblink/wasmnest-plugin-sdk-desktop/ui)
19
+ `${SDK_UI_SRC}/**/*.{vue,js,ts,jsx,tsx}`,
20
+ // 被调试应用源码(app 的 Tailwind 类由 dev-shell 这次构建产出;
21
+ // 宿主前端不在此列——dev-shell 只引宿主样式表,不引宿主组件)
22
+ ...(process.env.WASMNEST_DEV_PLUGINS || '')
23
+ .split(',')
24
+ .map((item) => item.trim())
25
+ .filter(Boolean)
26
+ .map((item) => item.split('::')[0] + '/src/**/*.{vue,js,ts,jsx,tsx}'),
27
+ ],
28
+ darkMode: 'class',
29
+ theme: {
30
+ extend: {
31
+ colors: {
32
+ primary: {
33
+ 50: '#f0f9ff',
34
+ 100: '#e0f2fe',
35
+ 200: '#bae6fd',
36
+ 300: '#7dd3fc',
37
+ 400: '#38bdf8',
38
+ 500: '#0ea5e9',
39
+ 600: '#3B82F6',
40
+ 700: '#0369a1',
41
+ 800: '#075985',
42
+ 900: '#0c4a6e',
43
+ 950: '#082f49',
44
+ },
45
+ dark: {
46
+ 50: '#f8fafc',
47
+ 100: '#f1f5f9',
48
+ 200: '#e2e8f0',
49
+ 300: '#cbd5e1',
50
+ 400: '#94a3b8',
51
+ 500: '#64748b',
52
+ 600: '#475569',
53
+ 650: '#3d4f63',
54
+ 700: '#334155',
55
+ 750: '#2d3a4f',
56
+ 800: '#1e293b',
57
+ 850: '#172033',
58
+ 900: '#0f172a',
59
+ 950: '#020617',
60
+ },
61
+ page: 'var(--bg-page)',
62
+ card: 'var(--bg-card)',
63
+ sidebar: 'var(--bg-sidebar)',
64
+ brand: {
65
+ DEFAULT: 'var(--color-primary)',
66
+ light: 'var(--color-primary-light)',
67
+ },
68
+ },
69
+ fontSize: {
70
+ xs: 'calc(12px * var(--ui-scale))',
71
+ sm: 'calc(14px * var(--ui-scale))',
72
+ base: 'calc(16px * var(--ui-scale))',
73
+ lg: 'calc(18px * var(--ui-scale))',
74
+ xl: 'calc(20px * var(--ui-scale))',
75
+ '2xl': 'calc(24px * var(--ui-scale))',
76
+ '3xl': 'calc(30px * var(--ui-scale))',
77
+ },
78
+ fontFamily: {
79
+ sans: ['Inter', 'system-ui', 'sans-serif'],
80
+ mono: ['Consolas', 'Monaco', 'monospace'],
81
+ },
82
+ borderRadius: {
83
+ card: 'var(--radius-card)',
84
+ btn: 'var(--radius-button)',
85
+ input: 'var(--radius-input)',
86
+ tag: 'var(--radius-tag)',
87
+ nav: 'var(--radius-nav)',
88
+ },
89
+ boxShadow: {
90
+ xs: '0 1px 2px 0 rgb(0 0 0 / 0.04)',
91
+ card: 'var(--shadow-card)',
92
+ 'card-hover': 'var(--shadow-card-hover)',
93
+ 'input-focus': 'var(--shadow-input-focus)',
94
+ },
95
+ },
96
+ },
97
+ plugins: [],
98
+ }
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Dev Shell Vite 配置(桌面端 · 挂载包形态)
3
+ *
4
+ * 环境变量:
5
+ * WASMNEST_DEV_PLUGINS 逗号分隔的应用说明,每项 `<应用目录>[::<入口文件>]`
6
+ * (由 `wasmnest-plugin-desktop dev` 注入;入口缺省时
7
+ * 本文件按挂载包约定解析,见 `resolveEntry`)
8
+ * WASMNEST_DEV_PORT 端口(缺省 5173,也可用 vite --port 覆盖)
9
+ *
10
+ * 两个关键接线:
11
+ *
12
+ * 1. **设计 token 单一真源**:monorepo 内 dev-shell 与宿主同仓,直接 alias 到宿主
13
+ * `src/style.css` 与 `src/shell/styles/shell.css`(跟随宿主更新,零维护);
14
+ * npm 包内没有宿主,退回自带副本(`files` 白名单携带),副本与宿主的一致性
15
+ * 由 `dev-shell/__tests__/visualParity.test.ts` 钉住。
16
+ *
17
+ * 2. **挂载包虚拟模块**:每个被调试应用注入两个模块——挂载包入口(`src/entry.ts`,
18
+ * 导出 `mountApp`)与领域种子模块(`src/index.ts`,导出 `devMock`)。两者都
19
+ * 由 vite 解析进构建图,改代码即 HMR。
20
+ */
21
+ import { defineConfig, type Plugin } from 'vite'
22
+ import vue from '@vitejs/plugin-vue'
23
+ import { existsSync, realpathSync } from 'node:fs'
24
+ import { join, resolve } from 'node:path'
25
+ import { fileURLToPath } from 'node:url'
26
+
27
+ const DEV_SHELL_ROOT = fileURLToPath(new URL('.', import.meta.url))
28
+
29
+ /** 宿主前端源码根(wasmnest-desktop/src) */
30
+ const HOST_SRC = resolve(DEV_SHELL_ROOT, '../../../src')
31
+ /** 宿主壳样式目录(wasmnest-desktop/src/shell/styles) */
32
+ const HOST_SHELL_STYLES = resolve(HOST_SRC, 'shell/styles')
33
+ /** dev-shell 自带的样式副本(npm 包内使用) */
34
+ const BUNDLED_STYLES = resolve(DEV_SHELL_ROOT, 'src/styles')
35
+
36
+ /** 设计 token 目录:宿主在场 → 用宿主;否则用自带副本 */
37
+ const TOKEN_STYLE_DIR = existsSync(join(HOST_SRC, 'style.css')) ? HOST_SRC : BUNDLED_STYLES
38
+ /** 壳样式目录:同上 */
39
+ const SHELL_STYLE_DIR = existsSync(join(HOST_SHELL_STYLES, 'shell.css'))
40
+ ? HOST_SHELL_STYLES
41
+ : BUNDLED_STYLES
42
+
43
+ /** token 别名(入口以 `@wasmnest/desktop-styles/style.css` 形式引入) */
44
+ const TOKEN_STYLE_ALIAS = '@wasmnest/desktop-styles'
45
+ /** 壳样式别名 */
46
+ const SHELL_STYLE_ALIAS = '@wasmnest/desktop-shell-styles'
47
+
48
+ /** 单个被调试应用 */
49
+ export interface DevPluginSpec {
50
+ /** 应用目录(绝对路径) */
51
+ dir: string
52
+ /** 挂载包入口(绝对路径);缺省由 `resolveEntry` 按约定解析 */
53
+ entry?: string
54
+ }
55
+
56
+ /**
57
+ * 解析应用的挂载包入口
58
+ *
59
+ * 桌面 app 是**独立构建的挂载包**(机制 B):入口 = `src/entry.ts`,导出
60
+ * `mountApp(root, env)`。`src/index.ts` 是「dev-shell 兼容出口」(只导出
61
+ * `devMock`)——它**不是**挂载入口,故优先取 `src/entry.ts`;两者都没有时返回
62
+ * null(由装载器显性报错,不静默加载一个空模块)。
63
+ */
64
+ export function resolveEntry(dir: string): string | null {
65
+ const entry = resolve(dir, 'src/entry.ts')
66
+ if (existsSync(entry)) return entry
67
+ const legacy = resolve(dir, 'src/index.ts')
68
+ if (existsSync(legacy)) return legacy
69
+ return null
70
+ }
71
+
72
+ /** 解析 WASMNEST_DEV_PLUGINS 环境变量 */
73
+ export function parseDevPlugins(): DevPluginSpec[] {
74
+ const raw = process.env.WASMNEST_DEV_PLUGINS
75
+ if (!raw) return []
76
+ return raw
77
+ .split(',')
78
+ .map((item) => item.trim())
79
+ .filter(Boolean)
80
+ .map((item) => {
81
+ const [dir, entry] = item.split('::')
82
+ const absDir = resolve(dir)
83
+ return {
84
+ dir: absDir,
85
+ entry: entry ? resolve(dir, entry) : undefined,
86
+ }
87
+ })
88
+ }
89
+
90
+ /**
91
+ * 虚拟模块:导出被调试应用列表
92
+ *
93
+ * 每项 `{ dir, manifest, entry, devMock }`:
94
+ * - `entry` = 挂载包模块(`src/entry.ts`;缺失 = null)
95
+ * - `devMock` = 领域种子模块(`src/index.ts`;缺失 = null;与 entry 同文件时复用)
96
+ */
97
+ function devPluginsVirtual(plugins: DevPluginSpec[]): Plugin {
98
+ const VIRTUAL_ID = 'virtual:dev-plugins'
99
+ return {
100
+ name: 'wasmnest-dev-shell:virtual-plugins',
101
+ resolveId(id) {
102
+ if (id === VIRTUAL_ID) return '\0' + VIRTUAL_ID
103
+ },
104
+ load(id) {
105
+ if (id !== '\0' + VIRTUAL_ID) return
106
+ if (plugins.length === 0) return 'export default []'
107
+ const imports: string[] = []
108
+ const records: string[] = []
109
+ plugins.forEach((p, i) => {
110
+ const manifestPath = resolve(p.dir, 'plugin.json')
111
+ imports.push(`import manifest${i} from ${JSON.stringify(manifestPath)}`)
112
+ const entryPath = p.entry ?? resolveEntry(p.dir)
113
+ if (entryPath) {
114
+ imports.push(`import * as entry${i} from ${JSON.stringify(entryPath)}`)
115
+ }
116
+ // 领域种子出口(app 自持演示数据):与挂载入口同文件时复用同一模块。
117
+ // 模块命名空间里取 `devMock` 导出才是**种子本身**(app 的 src/index.ts
118
+ // 形如 `export const devMock = peerDevMock`)——直接把命名空间当种子传下去
119
+ // 会让消费方读到 `{ devMock: {...} }` 而取不到字段。
120
+ const entryExpr = entryPath ? `entry${i}` : 'null'
121
+ const devMockPath = resolve(p.dir, 'src/index.ts')
122
+ if (existsSync(devMockPath) && devMockPath !== entryPath) {
123
+ imports.push(`import * as devmock${i} from ${JSON.stringify(devMockPath)}`)
124
+ }
125
+ const devMockExpr =
126
+ existsSync(devMockPath) && devMockPath !== entryPath
127
+ ? `(devmock${i}.devMock ?? null)`
128
+ : entryPath === devMockPath
129
+ ? `(entry${i}.devMock ?? null)`
130
+ : 'null'
131
+ records.push(
132
+ `{ dir: ${JSON.stringify(p.dir)}, manifest: manifest${i}, entry: ${entryExpr}, devMock: ${devMockExpr} }`,
133
+ )
134
+ })
135
+ return `${imports.join('\n')}\n\nexport default [\n ${records.join(',\n ')},\n]\n`
136
+ },
137
+ }
138
+ }
139
+
140
+ export default defineConfig(() => {
141
+ const plugins = parseDevPlugins()
142
+
143
+ // fs.allow:dev-shell 自身 + 宿主 token 目录 + 被调试应用目录
144
+ // (file: SDK 依赖为软链,需放行真实路径)
145
+ const allow = new Set<string>([DEV_SHELL_ROOT, TOKEN_STYLE_DIR, SHELL_STYLE_DIR])
146
+ for (const p of plugins) {
147
+ allow.add(p.dir)
148
+ try {
149
+ allow.add(realpathSync(p.dir))
150
+ } catch {
151
+ // 目录不存在时 vite 会给出更明确的错误,此处仅尽力放行
152
+ }
153
+ }
154
+
155
+ return {
156
+ plugins: [vue(), devPluginsVirtual(plugins)],
157
+ resolve: {
158
+ // 强制应用源码与 dev-shell 共用同一份 vue 实例(provide/inject、响应式共享依赖它)
159
+ dedupe: ['vue', 'vue-i18n', 'pinia', 'vue-router'],
160
+ alias: {
161
+ [TOKEN_STYLE_ALIAS]: TOKEN_STYLE_DIR,
162
+ [SHELL_STYLE_ALIAS]: SHELL_STYLE_DIR,
163
+ },
164
+ },
165
+ // main.ts 使用 top-level await 串行初始化 → 装载应用 → 挂载
166
+ build: {
167
+ target: 'esnext',
168
+ },
169
+ server: {
170
+ port: Number(process.env.WASMNEST_DEV_PORT || 5173),
171
+ fs: { allow: [...allow] },
172
+ },
173
+ }
174
+ })
@@ -0,0 +1,150 @@
1
+ import { PluginContext, PluginDialogOptions, ConfigProperty, PluginConfiguration, AppUpdateReason, AppUpdateCheckResult } from './types.js';
2
+ export { AppUpdateAPI, CommandContribution, CommandRegistry, Disposable, EndpointAuthTier, EventAPI, FileHandlerContribution, FileHandlerDescriptor, HttpAPI, HttpEndpointContribution, I18nAPI, InputExtensionDescriptor, LifecycleContribution, MonitorPanelContribution, PageToolbarItemDescriptor, PluginContributes, PluginDevMock, PluginDialogAction, PluginDialogHandle, PluginInfo, PluginManifest, PluginModule, PluginState, PluginType, PluginUpdateDecl, RequestHandler, SessionAPI, SidebarPanelDescriptor, StatusBarItemDescriptor, StorageAPI, TerminalAPI, TerminalContribution, TerminalToolbarItemDescriptor, TitleBarItemDescriptor, ToolProviderContribution, ToolboxPageDescriptor, UIRegistry, ViewContribution, WsEndpointContribution } from './types.js';
3
+ import { Ref, ComputedRef } from 'vue';
4
+
5
+ /**
6
+ * @binblink/wasmnest-plugin-sdk-desktop 运行时代理
7
+ *
8
+ * 插件通过这些函数访问宿主共享模块,避免直接依赖 window 全局变量
9
+ */
10
+
11
+ /** 获取宿主共享模块 */
12
+ declare function getSharedModule(name: string): any;
13
+ /** 获取宿主 i18n 实例(模块级代码使用,组件内请用 useI18n()) */
14
+ declare function getI18n(): any;
15
+ /** 获取宿主 Vue 实例 */
16
+ declare function getVue(): any;
17
+ /** 获取宿主 vue-i18n 模块 */
18
+ declare function getVueI18n(): any;
19
+ /** 获取宿主 Pinia 模块 */
20
+ declare function getPinia(): any;
21
+ /** 获取宿主 Router 实例 */
22
+ declare function getRouter(): any;
23
+ /** 从 Vue inject 获取 PluginContext(组件 setup 阶段调用) */
24
+ declare function getPluginContext(): PluginContext;
25
+
26
+ /**
27
+ * 全局弹窗控制器(桌面宿主 + dev-shell 共用)
28
+ *
29
+ * 发布-订阅实现:不直接依赖 Vue reactivity,宿主 / dev-shell 的
30
+ * PluginGlobalDialog 组件经 subscribeGlobalDialog 订阅渲染,单元测试无需
31
+ * 初始化共享运行时即可驱动。
32
+ *
33
+ * 语义:
34
+ * - FIFO 队列:同一时刻至多一个弹窗,后到的排队;当前关闭后自动接替;
35
+ * - update() 生成新条目对象再广播(订阅方拿到新引用触发重渲染);
36
+ * - close() 幂等;排队中的条目也可关闭(从队列移除);
37
+ * - 定时自动关闭为**可选能力**:仅当提供 timeoutSec / deadlineAt 时生效,
38
+ * 计时从条目成为当前弹窗起计算(迟到打开/排队经过的时间不重复计入相对秒数)。
39
+ */
40
+
41
+ /** 内部弹窗条目 = 公开选项 + 宿主注入字段 */
42
+ interface GlobalDialogEntry extends PluginDialogOptions {
43
+ /** 内部唯一 ID(句柄路由用) */
44
+ _id: number;
45
+ /** 内容组件宿主上下文(provide('pluginContext') 用;宿主 showDialog 注入) */
46
+ pluginContext?: unknown;
47
+ /** 条目创建时刻(ms) */
48
+ createdAt: number;
49
+ }
50
+ /** 订阅输入(宿主注入 pluginContext 后交 openGlobalDialog) */
51
+ type OpenGlobalDialogInput = PluginDialogOptions & {
52
+ pluginContext?: unknown;
53
+ };
54
+ type GlobalDialogListener = (entry: GlobalDialogEntry | null) => void;
55
+ /** 打开/更新/关闭返回的句柄(供插件调用方使用) */
56
+ interface GlobalDialogHandleOutput {
57
+ close(): void;
58
+ update(options: Partial<PluginDialogOptions>): void;
59
+ }
60
+ /** 当前弹窗(无则 null) */
61
+ declare function getGlobalDialog(): GlobalDialogEntry | null;
62
+ /** 订阅弹窗变化;立即以当前值回调一次,返回退订函数 */
63
+ declare function subscribeGlobalDialog(listener: GlobalDialogListener): () => void;
64
+ /** 解析条目的绝对截止时刻(deadlineAt 优先;缺省无定时关闭) */
65
+ declare function resolveDialogDeadline(entry: GlobalDialogEntry): number | null;
66
+ /** 关闭指定弹窗:当前弹窗关闭后队列自动顶上;排队中直接移除(均幂等) */
67
+ declare function closeGlobalDialog(id: number): void;
68
+ /** 热更新指定弹窗(当前或排队中;新对象广播触发重渲染) */
69
+ declare function updateGlobalDialog(id: number, options: Partial<PluginDialogOptions>): void;
70
+ /**
71
+ * 打开全局弹窗(宿主 ui.showDialog 调用)。
72
+ * 返回句柄:close() 幂等关闭(当前或排队项),update() 热更新选项。
73
+ */
74
+ declare function openGlobalDialog(input: OpenGlobalDialogInput): GlobalDialogHandleOutput;
75
+
76
+ /**
77
+ * Plugin Configuration Helpers
78
+ *
79
+ * SDK 侧配置约定:统一 storage key + 声明式配置助手。
80
+ * 插件运行时读写配置走 context.storage,与宿主配置页共享 key。
81
+ */
82
+
83
+ /**
84
+ * 插件配置在 storage 中的统一键名
85
+ *
86
+ * 插件运行时:context.storage.get(PLUGIN_CONFIG_STORAGE_KEY)
87
+ * 宿主配置页:pluginStorageGet(pluginId, PLUGIN_CONFIG_STORAGE_KEY)
88
+ * 两者共享同一 key,保证数据一致
89
+ */
90
+ declare const PLUGIN_CONFIG_STORAGE_KEY = "config";
91
+ /**
92
+ * 声明式构建插件配置(manifest contributes.configuration)
93
+ *
94
+ * 用途:插件开发者在代码中声明配置 schema,与 plugin.json 中保持一致。
95
+ * 实际 manifest 中的 configuration 以 plugin.json 为单一真源。
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const config = defineConfiguration('My Plugin Settings', {
100
+ * apiKey: { type: 'string', title: 'API Key', description: 'Your API key' },
101
+ * maxRetries: { type: 'number', title: 'Max Retries', default: 3 },
102
+ * debugMode: { type: 'boolean', title: 'Debug Mode', default: false },
103
+ * })
104
+ * ```
105
+ */
106
+ declare function defineConfiguration(title: string, properties: Record<string, Omit<ConfigProperty, 'title'> & {
107
+ title?: string;
108
+ }>): PluginConfiguration;
109
+
110
+ /**
111
+ * 应用更新检查(SDK 默认实现;宿主统一提供 GitHub Release 判定)
112
+ *
113
+ * 数据面由宿主给出(`PluginContext.appUpdate.check`):宿主负责查 Release、校验
114
+ * 身份 / 完整性、做平台兼容裁决;本模块只做状态机与展示口径,供应用设置页复用。
115
+ *
116
+ * 应用可以选择:
117
+ * - **默认实现**:`useAppUpdate()` / `<AppUpdateSection />`(宿主能力 + 本模块状态);
118
+ * - **自实现**:自己查更新 / 自己画界面,不消费本模块。
119
+ *
120
+ * 失败口径:检查是被动动作,不向用户抛技术错误——状态落 `error`,技术详情由宿主
121
+ * 日志承载(应用可自行决定是否提示)。
122
+ */
123
+
124
+ /** 状态机的展示态(与宿主返回的 status 子集一致) */
125
+ type AppUpdateStatus = 'idle' | 'checking' | 'up-to-date' | 'available' | 'incompatible' | 'error';
126
+ interface UseAppUpdateOptions {
127
+ /**
128
+ * 自定义检查器(缺省 = 宿主 `PluginContext.appUpdate.check`)
129
+ *
130
+ * 应用自实现更新检查时传入;返回形状与宿主默认实现一致,SDK 默认卡片即可复用。
131
+ */
132
+ check?: () => Promise<AppUpdateCheckResult>;
133
+ }
134
+ interface UseAppUpdate {
135
+ status: Ref<AppUpdateStatus>;
136
+ latestVersion: Ref<string | undefined>;
137
+ currentVersion: Ref<string | undefined>;
138
+ reason: Ref<AppUpdateReason | undefined>;
139
+ checking: ComputedRef<boolean>;
140
+ /** 当前平台是否提供更新检查能力(旧宿主 / dev-shell 可能没有) */
141
+ supported: ComputedRef<boolean>;
142
+ /** 执行一次检查;并发调用复用同一在途请求 */
143
+ check: () => Promise<void>;
144
+ }
145
+ /**
146
+ * 应用更新状态机(模块内无全局单例:每个设置页实例各自持状态,避免跨应用串状态)
147
+ */
148
+ declare function useAppUpdate(options?: UseAppUpdateOptions): UseAppUpdate;
149
+
150
+ export { AppUpdateCheckResult, AppUpdateReason, type AppUpdateStatus, ConfigProperty, type GlobalDialogEntry, type GlobalDialogHandleOutput, type GlobalDialogListener, type OpenGlobalDialogInput, PLUGIN_CONFIG_STORAGE_KEY, PluginConfiguration, PluginContext, PluginDialogOptions, type UseAppUpdate, type UseAppUpdateOptions, closeGlobalDialog, defineConfiguration, getGlobalDialog, getI18n, getPinia, getPluginContext, getRouter, getSharedModule, getVue, getVueI18n, openGlobalDialog, resolveDialogDeadline, subscribeGlobalDialog, updateGlobalDialog, useAppUpdate };