@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.
- package/README.md +307 -2
- package/README_en.md +284 -0
- package/bin/cli.js +602 -0
- package/bin/manifest-gen.js +458 -0
- package/bin/manifest-validate.js +494 -0
- package/bin/permission-vocabulary.json +5 -0
- package/bin/plugin-watch.js +331 -0
- package/bin/wasm-hash.js +124 -0
- package/dev-shell/README.md +122 -0
- package/dev-shell/index.html +12 -0
- package/dev-shell/package.json +28 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/components/LogPanel.vue +90 -0
- package/dev-shell/src/loader.ts +104 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales.ts +50 -0
- package/dev-shell/src/main.ts +46 -0
- package/dev-shell/src/mock/app-env.ts +102 -0
- package/dev-shell/src/mock/commands.ts +54 -0
- package/dev-shell/src/mock/domain-context.ts +46 -0
- package/dev-shell/src/mock/events.ts +16 -0
- package/dev-shell/src/mock/file-transfer.ts +512 -0
- package/dev-shell/src/mock/tauri-ipc.ts +109 -0
- package/dev-shell/src/registry.ts +90 -0
- package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
- package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
- package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
- package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
- package/dev-shell/src/shell/mount/appSession.ts +45 -0
- package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
- package/dev-shell/src/shell/types.ts +121 -0
- package/dev-shell/src/styles/dev.css +27 -0
- package/dev-shell/src/styles/shell.css +752 -0
- package/dev-shell/src/styles/style.css +1178 -0
- package/dev-shell/src/theme.ts +140 -0
- package/dev-shell/src/vite-env.d.ts +24 -0
- package/dev-shell/tailwind.config.js +98 -0
- package/dev-shell/vite.config.ts +174 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +238 -0
- package/dist/types.d.ts +632 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +25 -0
- package/dist/vite-plugin.js +80 -0
- package/go/.gitignore +5 -0
- package/go/README.md +80 -0
- package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
- package/go/gen/wasmnest/app/host-app/empty.s +3 -0
- package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
- package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
- package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
- package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
- package/go/gen/wasmnest/http/host-http/abi.go +14 -0
- package/go/gen/wasmnest/http/host-http/empty.s +3 -0
- package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
- package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
- package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
- package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
- package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
- package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
- package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
- package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
- package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
- package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
- package/go/gen/wasmnest/plugin/command/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
- package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
- package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
- package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
- package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
- package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
- package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
- package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
- package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
- package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
- package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
- package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
- package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
- package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
- package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
- package/go/gen/wasmnest/process/host-process/empty.s +3 -0
- package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
- package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
- package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
- package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
- package/go/gen/wasmnest/task/host-task/abi.go +14 -0
- package/go/gen/wasmnest/task/host-task/empty.s +3 -0
- package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
- package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
- package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
- package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
- package/go/go.mod +14 -0
- package/go/go.sum +2 -0
- package/go/sdk/dispatch.go +49 -0
- package/go/sdk/dispatch_test.go +81 -0
- package/go/sdk/entry_native.go +13 -0
- package/go/sdk/entry_wasip2.go +188 -0
- package/go/sdk/host_http_wasip2.go +42 -0
- package/go/sdk/host_wasip2.go +251 -0
- package/go/sdk/plugin.go +103 -0
- package/go/testplugin/index.js +1 -0
- package/go/testplugin/main.go +67 -0
- package/go/testplugin/plugin.json +24 -0
- package/go/tools/assemble-wit.mjs +152 -0
- package/go/tools/gen-bindings.mjs +51 -0
- package/go/wit/core.wit +273 -0
- package/go/wit/deps/api-call/cap-api-call.wit +20 -0
- package/go/wit/deps/app/cap-app.wit +54 -0
- package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
- package/go/wit/deps/clipboard/clipboard.wit +48 -0
- package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
- package/go/wit/deps/clocks/wall-clock.wit +42 -0
- package/go/wit/deps/clocks/world.wit +6 -0
- package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
- package/go/wit/deps/crypto/cap-crypto.wit +68 -0
- package/go/wit/deps/filesystem/preopens.wit +8 -0
- package/go/wit/deps/filesystem/types.wit +634 -0
- package/go/wit/deps/filesystem/world.wit +6 -0
- package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
- package/go/wit/deps/http/http.wit +28 -0
- package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
- package/go/wit/deps/io/error.wit +34 -0
- package/go/wit/deps/io/poll.wit +41 -0
- package/go/wit/deps/io/streams.wit +262 -0
- package/go/wit/deps/io/world.wit +6 -0
- package/go/wit/deps/mdns/mdns.wit +45 -0
- package/go/wit/deps/notify/notify.wit +51 -0
- package/go/wit/deps/peer/peer.wit +126 -0
- package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
- package/go/wit/deps/process/cap-process.wit +25 -0
- package/go/wit/deps/pty/pty.wit +80 -0
- package/go/wit/deps/random/insecure-seed.wit +25 -0
- package/go/wit/deps/random/insecure.wit +22 -0
- package/go/wit/deps/random/random.wit +26 -0
- package/go/wit/deps/random/world.wit +7 -0
- package/go/wit/deps/sockets/instance-network.wit +9 -0
- package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
- package/go/wit/deps/sockets/network.wit +145 -0
- package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/tcp.wit +353 -0
- package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/udp.wit +266 -0
- package/go/wit/deps/sockets/world.wit +11 -0
- package/go/wit/deps/task/cap-task.wit +56 -0
- package/go/wit/deps/timer/cap-timer.wit +14 -0
- package/go/wit/deps/wasi-cli/command.wit +7 -0
- package/go/wit/deps/wasi-cli/environment.wit +18 -0
- package/go/wit/deps/wasi-cli/exit.wit +4 -0
- package/go/wit/deps/wasi-cli/imports.wit +20 -0
- package/go/wit/deps/wasi-cli/run.wit +4 -0
- package/go/wit/deps/wasi-cli/stdio.wit +17 -0
- package/go/wit/deps/wasi-cli/terminal.wit +49 -0
- package/go/wit/deps/ws/ws.wit +50 -0
- package/go/wit/deps/ws-server/cap-ws.wit +99 -0
- package/go/wit/go-plugin.wit +28 -0
- package/go/wit/plugin-face.wit +355 -0
- package/go/wit/wasmnest.wit +25 -0
- package/package.json +100 -3
- package/src/config.ts +49 -0
- package/src/global-dialog.ts +169 -0
- package/src/index.ts +88 -0
- package/src/runtime.ts +54 -0
- package/src/types.ts +681 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/MarkdownEditor.vue +520 -0
- package/src/ui/NumberField.d.ts +49 -0
- package/src/ui/NumberField.vue +390 -0
- package/src/ui/PluginGlobalDialog.vue +401 -0
- package/src/ui/Select.d.ts +36 -0
- package/src/ui/Select.vue +220 -0
- package/src/ui/TerminalInputRail.vue +184 -0
- package/src/ui/apply-select-position.ts +65 -0
- package/src/ui/markdown-editor-syntax.ts +234 -0
- package/src/ui/markdown-editor.d.ts +36 -0
- package/src/ui/plugin-global-dialog.d.ts +12 -0
- package/src/ui/select-position.ts +79 -0
- package/src/ui/terminal-input-rail.d.ts +30 -0
- package/src/ui/zoom-compensation.d.ts +9 -0
- package/src/ui/zoom-compensation.ts +52 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +124 -0
- package/template/README.md +39 -0
- package/template/package.json +23 -0
- package/template/plugin.json +14 -0
- package/template/rust/Cargo.toml +21 -0
- package/template/rust/src/lib.rs +39 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
- package/tools/componentize/Cargo.lock +299 -0
- package/tools/componentize/Cargo.toml +18 -0
- package/tools/componentize/src/main.rs +197 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 全局弹窗控制器(桌面宿主 + dev-shell 共用)
|
|
3
|
+
*
|
|
4
|
+
* 发布-订阅实现:不直接依赖 Vue reactivity,宿主 / dev-shell 的
|
|
5
|
+
* PluginGlobalDialog 组件经 subscribeGlobalDialog 订阅渲染,单元测试无需
|
|
6
|
+
* 初始化共享运行时即可驱动。
|
|
7
|
+
*
|
|
8
|
+
* 语义:
|
|
9
|
+
* - FIFO 队列:同一时刻至多一个弹窗,后到的排队;当前关闭后自动接替;
|
|
10
|
+
* - update() 生成新条目对象再广播(订阅方拿到新引用触发重渲染);
|
|
11
|
+
* - close() 幂等;排队中的条目也可关闭(从队列移除);
|
|
12
|
+
* - 定时自动关闭为**可选能力**:仅当提供 timeoutSec / deadlineAt 时生效,
|
|
13
|
+
* 计时从条目成为当前弹窗起计算(迟到打开/排队经过的时间不重复计入相对秒数)。
|
|
14
|
+
*/
|
|
15
|
+
import type { PluginDialogOptions } from './types'
|
|
16
|
+
|
|
17
|
+
/** 内部弹窗条目 = 公开选项 + 宿主注入字段 */
|
|
18
|
+
export interface GlobalDialogEntry extends PluginDialogOptions {
|
|
19
|
+
/** 内部唯一 ID(句柄路由用) */
|
|
20
|
+
_id: number
|
|
21
|
+
/** 内容组件宿主上下文(provide('pluginContext') 用;宿主 showDialog 注入) */
|
|
22
|
+
pluginContext?: unknown
|
|
23
|
+
/** 条目创建时刻(ms) */
|
|
24
|
+
createdAt: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 订阅输入(宿主注入 pluginContext 后交 openGlobalDialog) */
|
|
28
|
+
export type OpenGlobalDialogInput = PluginDialogOptions & { pluginContext?: unknown }
|
|
29
|
+
|
|
30
|
+
export type GlobalDialogListener = (entry: GlobalDialogEntry | null) => void
|
|
31
|
+
|
|
32
|
+
/** 打开/更新/关闭返回的句柄(供插件调用方使用) */
|
|
33
|
+
export interface GlobalDialogHandleOutput {
|
|
34
|
+
close(): void
|
|
35
|
+
update(options: Partial<PluginDialogOptions>): void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let seq = 0
|
|
39
|
+
let current: GlobalDialogEntry | null = null
|
|
40
|
+
const queue: GlobalDialogEntry[] = []
|
|
41
|
+
const listeners = new Set<GlobalDialogListener>()
|
|
42
|
+
/** 条目 → 超时定时器(仅当条目指定 timeoutSec / deadlineAt) */
|
|
43
|
+
const timers = new Map<number, ReturnType<typeof setTimeout>>()
|
|
44
|
+
|
|
45
|
+
/** 当前弹窗(无则 null) */
|
|
46
|
+
export function getGlobalDialog(): GlobalDialogEntry | null {
|
|
47
|
+
return current
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 订阅弹窗变化;立即以当前值回调一次,返回退订函数 */
|
|
51
|
+
export function subscribeGlobalDialog(listener: GlobalDialogListener): () => void {
|
|
52
|
+
listeners.add(listener)
|
|
53
|
+
listener(current)
|
|
54
|
+
return () => {
|
|
55
|
+
listeners.delete(listener)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function emit(): void {
|
|
60
|
+
for (const fn of [...listeners]) fn(current)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function clearTimer(id: number): void {
|
|
64
|
+
const timer = timers.get(id)
|
|
65
|
+
if (timer) {
|
|
66
|
+
clearTimeout(timer)
|
|
67
|
+
timers.delete(id)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 解析条目的绝对截止时刻(deadlineAt 优先;缺省无定时关闭) */
|
|
72
|
+
export function resolveDialogDeadline(entry: GlobalDialogEntry): number | null {
|
|
73
|
+
if (entry.deadlineAt != null && entry.deadlineAt > 0) return entry.deadlineAt
|
|
74
|
+
if (entry.timeoutSec != null && entry.timeoutSec > 0) return entry.createdAt + entry.timeoutSec * 1000
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 条目成为当前弹窗时的侧效:启动(或立即触发)超时计时 */
|
|
79
|
+
function startTimeout(entry: GlobalDialogEntry): void {
|
|
80
|
+
clearTimer(entry._id)
|
|
81
|
+
const deadline = resolveDialogDeadline(entry)
|
|
82
|
+
if (deadline == null) return
|
|
83
|
+
const delay = Math.max(0, deadline - Date.now())
|
|
84
|
+
timers.set(
|
|
85
|
+
entry._id,
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
// 超时:先回调 onTimeout(缺省仅关闭),再关闭(触发 onClose + 队列接替)
|
|
88
|
+
try {
|
|
89
|
+
entry.onTimeout?.()
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error('[PluginDialog] onTimeout failed:', e)
|
|
92
|
+
}
|
|
93
|
+
closeGlobalDialog(entry._id)
|
|
94
|
+
}, delay),
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function fireOnClose(entry: GlobalDialogEntry): void {
|
|
99
|
+
try {
|
|
100
|
+
entry.onClose?.()
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error('[PluginDialog] onClose failed:', e)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 关闭指定弹窗:当前弹窗关闭后队列自动顶上;排队中直接移除(均幂等) */
|
|
107
|
+
export function closeGlobalDialog(id: number): void {
|
|
108
|
+
if (current && current._id === id) {
|
|
109
|
+
const closed = current
|
|
110
|
+
clearTimer(id)
|
|
111
|
+
current = null
|
|
112
|
+
const next = queue.shift() ?? null
|
|
113
|
+
current = next
|
|
114
|
+
emit()
|
|
115
|
+
fireOnClose(closed)
|
|
116
|
+
if (next) startTimeout(next)
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
const idx = queue.findIndex((e) => e._id === id)
|
|
120
|
+
if (idx >= 0) {
|
|
121
|
+
const [removed] = queue.splice(idx, 1)
|
|
122
|
+
fireOnClose(removed)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 热更新指定弹窗(当前或排队中;新对象广播触发重渲染) */
|
|
127
|
+
export function updateGlobalDialog(id: number, options: Partial<PluginDialogOptions>): void {
|
|
128
|
+
if (current && current._id === id) {
|
|
129
|
+
current = { ...current, ...options }
|
|
130
|
+
emit()
|
|
131
|
+
startTimeout(current)
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
const idx = queue.findIndex((e) => e._id === id)
|
|
135
|
+
if (idx >= 0) {
|
|
136
|
+
queue[idx] = { ...queue[idx], ...options }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 打开全局弹窗(宿主 ui.showDialog 调用)。
|
|
142
|
+
* 返回句柄:close() 幂等关闭(当前或排队项),update() 热更新选项。
|
|
143
|
+
*/
|
|
144
|
+
export function openGlobalDialog(input: OpenGlobalDialogInput): GlobalDialogHandleOutput {
|
|
145
|
+
const entry: GlobalDialogEntry = {
|
|
146
|
+
...input,
|
|
147
|
+
_id: ++seq,
|
|
148
|
+
createdAt: Date.now(),
|
|
149
|
+
}
|
|
150
|
+
if (current) {
|
|
151
|
+
queue.push(entry)
|
|
152
|
+
} else {
|
|
153
|
+
current = entry
|
|
154
|
+
emit()
|
|
155
|
+
startTimeout(entry)
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
close: () => closeGlobalDialog(entry._id),
|
|
159
|
+
update: (options) => updateGlobalDialog(entry._id, options),
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 测试辅助:清空全部状态(队列/当前/监听器/定时器),用例间隔离 */
|
|
164
|
+
export function _resetGlobalDialogForTest(): void {
|
|
165
|
+
for (const id of [...timers.keys()]) clearTimer(id)
|
|
166
|
+
current = null
|
|
167
|
+
queue.length = 0
|
|
168
|
+
listeners.clear()
|
|
169
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @binblink/wasmnest-plugin-sdk-desktop
|
|
3
|
+
*
|
|
4
|
+
* WasmNest 插件开发工具包 — 类型定义 + 运行时代理 + 构建工具
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// 类型导出
|
|
8
|
+
export type {
|
|
9
|
+
Disposable,
|
|
10
|
+
PluginType,
|
|
11
|
+
PluginManifest,
|
|
12
|
+
PluginUpdateDecl,
|
|
13
|
+
PluginConfiguration,
|
|
14
|
+
ConfigProperty,
|
|
15
|
+
PluginContributes,
|
|
16
|
+
MonitorPanelContribution,
|
|
17
|
+
EndpointAuthTier,
|
|
18
|
+
HttpEndpointContribution,
|
|
19
|
+
WsEndpointContribution,
|
|
20
|
+
LifecycleContribution,
|
|
21
|
+
CommandContribution,
|
|
22
|
+
ViewContribution,
|
|
23
|
+
TerminalContribution,
|
|
24
|
+
ToolProviderContribution,
|
|
25
|
+
FileHandlerContribution,
|
|
26
|
+
SidebarPanelDescriptor,
|
|
27
|
+
ToolboxPageDescriptor,
|
|
28
|
+
StatusBarItemDescriptor,
|
|
29
|
+
InputExtensionDescriptor,
|
|
30
|
+
TerminalToolbarItemDescriptor,
|
|
31
|
+
TitleBarItemDescriptor,
|
|
32
|
+
PageToolbarItemDescriptor,
|
|
33
|
+
FileHandlerDescriptor,
|
|
34
|
+
PluginDialogAction,
|
|
35
|
+
PluginDialogOptions,
|
|
36
|
+
PluginDialogHandle,
|
|
37
|
+
RequestHandler,
|
|
38
|
+
CommandRegistry,
|
|
39
|
+
TerminalAPI,
|
|
40
|
+
SessionAPI,
|
|
41
|
+
UIRegistry,
|
|
42
|
+
EventAPI,
|
|
43
|
+
StorageAPI,
|
|
44
|
+
HttpAPI,
|
|
45
|
+
I18nAPI,
|
|
46
|
+
PluginContext,
|
|
47
|
+
PluginModule,
|
|
48
|
+
PluginDevMock,
|
|
49
|
+
PluginState,
|
|
50
|
+
PluginInfo,
|
|
51
|
+
AppUpdateReason,
|
|
52
|
+
AppUpdateCheckResult,
|
|
53
|
+
AppUpdateAPI,
|
|
54
|
+
} from './types'
|
|
55
|
+
|
|
56
|
+
// 运行时代理导出
|
|
57
|
+
export {
|
|
58
|
+
getSharedModule,
|
|
59
|
+
getI18n,
|
|
60
|
+
getVue,
|
|
61
|
+
getVueI18n,
|
|
62
|
+
getPinia,
|
|
63
|
+
getRouter,
|
|
64
|
+
getPluginContext,
|
|
65
|
+
} from './runtime'
|
|
66
|
+
|
|
67
|
+
// 全局弹窗控制器导出(宿主 / dev-shell 的 ui.showDialog 实现与渲染组件订阅)
|
|
68
|
+
export {
|
|
69
|
+
openGlobalDialog,
|
|
70
|
+
closeGlobalDialog,
|
|
71
|
+
updateGlobalDialog,
|
|
72
|
+
getGlobalDialog,
|
|
73
|
+
subscribeGlobalDialog,
|
|
74
|
+
resolveDialogDeadline,
|
|
75
|
+
} from './global-dialog'
|
|
76
|
+
export type {
|
|
77
|
+
GlobalDialogEntry,
|
|
78
|
+
GlobalDialogListener,
|
|
79
|
+
OpenGlobalDialogInput,
|
|
80
|
+
GlobalDialogHandleOutput,
|
|
81
|
+
} from './global-dialog'
|
|
82
|
+
|
|
83
|
+
// 配置约定导出
|
|
84
|
+
export { PLUGIN_CONFIG_STORAGE_KEY, defineConfiguration } from './config'
|
|
85
|
+
|
|
86
|
+
// 应用更新检查(SDK 默认实现;宿主统一 GitHub Release 判定)
|
|
87
|
+
export { useAppUpdate } from './update'
|
|
88
|
+
export type { AppUpdateStatus, UseAppUpdate, UseAppUpdateOptions } from './update'
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @binblink/wasmnest-plugin-sdk-desktop 运行时代理
|
|
3
|
+
*
|
|
4
|
+
* 插件通过这些函数访问宿主共享模块,避免直接依赖 window 全局变量
|
|
5
|
+
*/
|
|
6
|
+
import type { PluginContext, I18nAPI } from './types'
|
|
7
|
+
|
|
8
|
+
/** 共享模块全局变量键名 */
|
|
9
|
+
const SHARED_KEY = '__WASMNEST_SHARED__'
|
|
10
|
+
|
|
11
|
+
/** 获取宿主共享模块 */
|
|
12
|
+
export function getSharedModule(name: string): any {
|
|
13
|
+
const shared = (window as any)[SHARED_KEY]
|
|
14
|
+
if (!shared) throw new Error('[PluginSDK] Shared runtime not initialized')
|
|
15
|
+
const mod = shared[name]
|
|
16
|
+
if (!mod) throw new Error(`[PluginSDK] Shared module "${name}" not found`)
|
|
17
|
+
return mod
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 获取宿主 i18n 实例(模块级代码使用,组件内请用 useI18n()) */
|
|
21
|
+
export function getI18n(): any {
|
|
22
|
+
return getSharedModule('i18n')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 获取宿主 Vue 实例 */
|
|
26
|
+
export function getVue(): any {
|
|
27
|
+
return getSharedModule('vue')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 获取宿主 vue-i18n 模块 */
|
|
31
|
+
export function getVueI18n(): any {
|
|
32
|
+
return getSharedModule('vue-i18n')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 获取宿主 Pinia 模块 */
|
|
36
|
+
export function getPinia(): any {
|
|
37
|
+
return getSharedModule('pinia')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 获取宿主 Router 实例 */
|
|
41
|
+
export function getRouter(): any {
|
|
42
|
+
return getSharedModule('router')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 从 Vue inject 获取 PluginContext(组件 setup 阶段调用) */
|
|
46
|
+
export function getPluginContext(): PluginContext {
|
|
47
|
+
const vue = getVue()
|
|
48
|
+
const context = vue.inject('pluginContext')
|
|
49
|
+
if (!context)
|
|
50
|
+
throw new Error(
|
|
51
|
+
'[PluginSDK] PluginContext not available — ensure component is rendered inside PluginViewHost',
|
|
52
|
+
)
|
|
53
|
+
return context
|
|
54
|
+
}
|