@binblink/wasmnest-plugin-sdk-mobile 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 (122) hide show
  1. package/README.md +439 -2
  2. package/README_en.md +415 -0
  3. package/bin/build.js +271 -0
  4. package/bin/cli.js +96 -0
  5. package/bin/lib.js +349 -0
  6. package/bin/manifest-gen.js +327 -0
  7. package/bin/package.js +151 -0
  8. package/bin/scaffold.js +299 -0
  9. package/dev-shell/README.md +151 -0
  10. package/dev-shell/index.html +27 -0
  11. package/dev-shell/package.json +27 -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/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
  16. package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
  17. package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
  18. package/dev-shell/src/components/DevToolbar.vue +100 -0
  19. package/dev-shell/src/components/DialogHost.vue +119 -0
  20. package/dev-shell/src/components/LogPanel.vue +80 -0
  21. package/dev-shell/src/i18n.ts +22 -0
  22. package/dev-shell/src/loader.ts +239 -0
  23. package/dev-shell/src/locale.ts +29 -0
  24. package/dev-shell/src/locales/en-shell.ts +332 -0
  25. package/dev-shell/src/locales/index.ts +70 -0
  26. package/dev-shell/src/locales/shell.ts +331 -0
  27. package/dev-shell/src/main.ts +58 -0
  28. package/dev-shell/src/mock/dialog-service.ts +58 -0
  29. package/dev-shell/src/mock/file-transfer.ts +390 -0
  30. package/dev-shell/src/mock/mobile-api.ts +369 -0
  31. package/dev-shell/src/mock/preset-tasks.ts +186 -0
  32. package/dev-shell/src/mock/session.ts +121 -0
  33. package/dev-shell/src/mock-context.ts +374 -0
  34. package/dev-shell/src/registry.ts +151 -0
  35. package/dev-shell/src/shared-runtime.ts +44 -0
  36. package/dev-shell/src/shell/ShellView.vue +52 -0
  37. package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
  38. package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
  39. package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
  40. package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
  41. package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
  42. package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
  43. package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
  44. package/dev-shell/src/shell/components/ShellChip.vue +49 -0
  45. package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
  46. package/dev-shell/src/shell/components/ShellHost.vue +75 -0
  47. package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
  48. package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
  49. package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
  50. package/dev-shell/src/shell/components/ShellSection.vue +27 -0
  51. package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
  52. package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
  53. package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
  54. package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
  55. package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
  56. package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
  57. package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
  58. package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
  59. package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
  60. package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
  61. package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
  62. package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
  63. package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
  64. package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
  65. package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
  66. package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
  67. package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
  68. package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
  69. package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
  70. package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
  71. package/dev-shell/src/shell/composables/useToast.ts +33 -0
  72. package/dev-shell/src/shell/index.ts +88 -0
  73. package/dev-shell/src/shell/logger.ts +45 -0
  74. package/dev-shell/src/shell/permissions.ts +145 -0
  75. package/dev-shell/src/shell/registry.ts +220 -0
  76. package/dev-shell/src/shell/slotCards.ts +47 -0
  77. package/dev-shell/src/shell/styles/shell.css +1155 -0
  78. package/dev-shell/src/shell/surfaceIntent.ts +107 -0
  79. package/dev-shell/src/shell/types.ts +152 -0
  80. package/dev-shell/src/shell/utils.ts +54 -0
  81. package/dev-shell/src/styles/main.css +153 -0
  82. package/dev-shell/src/styles/mobile.css +981 -0
  83. package/dev-shell/src/styles/wallpaper.css +130 -0
  84. package/dev-shell/src/theme.ts +71 -0
  85. package/dev-shell/src/vite-env.d.ts +20 -0
  86. package/dev-shell/tailwind.config.js +101 -0
  87. package/dev-shell/tsconfig.json +16 -0
  88. package/dev-shell/vite.config.ts +130 -0
  89. package/dist/index.d.ts +124 -0
  90. package/dist/index.js +229 -0
  91. package/dist/types.d.ts +738 -0
  92. package/dist/types.js +0 -0
  93. package/dist/vite-plugin.d.ts +16 -0
  94. package/dist/vite-plugin.js +95 -0
  95. package/package.json +88 -3
  96. package/src/constants.ts +6 -0
  97. package/src/global-dialog.ts +168 -0
  98. package/src/index.ts +96 -0
  99. package/src/runtime.ts +44 -0
  100. package/src/types.ts +822 -0
  101. package/src/ui/AppUpdateSection.d.ts +44 -0
  102. package/src/ui/AppUpdateSection.vue +253 -0
  103. package/src/ui/PluginGlobalDialog.vue +388 -0
  104. package/src/ui/QuickCard.d.ts +33 -0
  105. package/src/ui/QuickCard.vue +167 -0
  106. package/src/ui/Select.d.ts +37 -0
  107. package/src/ui/Select.vue +307 -0
  108. package/src/ui/plugin-global-dialog.d.ts +11 -0
  109. package/src/ui/useSwipeTabs.d.ts +20 -0
  110. package/src/ui/useSwipeTabs.ts +53 -0
  111. package/src/update.ts +123 -0
  112. package/src/vite-plugin.ts +132 -0
  113. package/template/.gitignore +4 -0
  114. package/template/README.md +46 -0
  115. package/template/package.json +23 -0
  116. package/template/plugin.json +13 -0
  117. package/template/rust/Cargo.toml +19 -0
  118. package/template/rust/src/lib.rs +33 -0
  119. package/template/src/env.d.ts +24 -0
  120. package/template/src/index.ts +37 -0
  121. package/template/tsconfig.json +17 -0
  122. package/template/vite.config.ts +21 -0
@@ -0,0 +1,374 @@
1
+ /**
2
+ * Mock PluginContext
3
+ *
4
+ * 与宿主 context.ts 同接口、同语义(事件名 / i18n 前缀 / storage 命名空间 / UI 注册),
5
+ * 但全部后端通道替换为浏览器实现:
6
+ * - commands.execute:仅执行前端注册 handler;WASM 后端不在浏览器运行,未注册命令记日志
7
+ * - storage:localStorage 持久化
8
+ * - session/lifecycle:接 mock/session.ts 的模拟会话
9
+ * (terminal:TerminalAPI 已随票 15 阶段 B 整面退役,本 mock 同批移除)
10
+ * - 权限检查跳过(dev-shell 视为全部授权,README 已说明与真机的差异)
11
+ *
12
+ * UI 注册面与宿主同构:贡献项写进**壳注册表**(不是 dev-shell 自留副本),
13
+ * 运行面经 PluginContextHost 包装补 provide('pluginContext'),动态路由挂 vue-router。
14
+ */
15
+ import { defineComponent, h } from 'vue'
16
+ import type {
17
+ DialogOptions,
18
+ Disposable,
19
+ EventAPI,
20
+ I18nAPI,
21
+ LifecycleAPI,
22
+ LoggerAPI,
23
+ NotificationAPI,
24
+ PluginContext,
25
+ PluginDialogHandle,
26
+ PluginDialogOptions,
27
+ StatusAPI,
28
+ UIRegistry,
29
+ } from '../../src/types'
30
+ import { openGlobalDialog } from '../../src/global-dialog'
31
+ import {
32
+ emitDevEvent,
33
+ onDevEvent,
34
+ sessions,
35
+ } from './mock/session'
36
+ import { dialogService } from './mock/dialog-service'
37
+ import PluginContextHost from './shell/components/PluginContextHost.vue'
38
+ import { getShellRegistry } from './shell/registry'
39
+ import { subscribeSurfaceIntent } from './shell/surfaceIntent'
40
+ import { getSharedModule } from './shared-runtime'
41
+ import {
42
+ findRoute,
43
+ getPluginRecord,
44
+ pluginRouteName,
45
+ pushLog,
46
+ registerRouteEntry,
47
+ type RouteEntry,
48
+ } from './registry'
49
+
50
+ /** 存储命名空间(与宿主插件 storage 的 per-plugin 隔离一致) */
51
+ function storageKey(pluginId: string, key: string): string {
52
+ return `wasmnest-dev-shell:${pluginId}:${key}`
53
+ }
54
+
55
+ /** 创建插件的 PluginContext */
56
+ /**
57
+ * 把插件的消息树展平为「完整点分 key → 叶子值」(与宿主 context.ts 同口径)
58
+ *
59
+ * 不展平时嵌套消息(`{ hub: { slotTitle } }`)会被挂成带点对象,`t()` 路径寻址
60
+ * 在第二段就断,插件文案全部回退成 key 字面量——预览与真机表现不一致。
61
+ */
62
+ function flattenMessages(
63
+ source: Record<string, unknown>,
64
+ prefix: string,
65
+ out: Record<string, unknown>,
66
+ ): void {
67
+ for (const [key, value] of Object.entries(source)) {
68
+ const fullKey = prefix ? `${prefix}.${key}` : key
69
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
70
+ flattenMessages(value as Record<string, unknown>, fullKey, out)
71
+ } else {
72
+ out[fullKey] = value
73
+ }
74
+ }
75
+ }
76
+
77
+ export function createMockContext(pluginId: string): PluginContext {
78
+ const disposables: Disposable[] = []
79
+ // 供 ui.showDialog 闭包惰性引用(与桌面端 dev-shell 同模式,调用时 context 已初始化)
80
+ let contextRef: PluginContext | null = null
81
+
82
+ /** 收集 disposable,随插件 deactivate 统一清理 */
83
+ function track(disposable: Disposable): Disposable {
84
+ disposables.push(disposable)
85
+ return disposable
86
+ }
87
+
88
+ // ==================== CommandRegistry ====================
89
+ const commandHandlers = new Map<string, (...args: any[]) => any>()
90
+
91
+ const commands = {
92
+ register(id: string, handler: (...args: any[]) => any): Disposable {
93
+ commandHandlers.set(id, handler)
94
+ return track({
95
+ dispose() {
96
+ commandHandlers.delete(id)
97
+ },
98
+ })
99
+ },
100
+ async execute(id: string, ...args: any[]): Promise<any> {
101
+ const handler = commandHandlers.get(id)
102
+ if (handler) return handler(...args)
103
+ pushLog(
104
+ 'warn',
105
+ pluginId,
106
+ `command "${id}" 未注册前端 handler——WASM 后端不在浏览器运行,请注册前端 handler 或到真机验证`,
107
+ )
108
+ return undefined
109
+ },
110
+ }
111
+
112
+ // ==================== SessionAPI ====================
113
+ const session = {
114
+ async list(): Promise<any[]> {
115
+ return sessions.value.map((s) => ({ ...s }))
116
+ },
117
+ async get(sessionId: string): Promise<any> {
118
+ const s = sessions.value.find((x) => x.id === sessionId)
119
+ return s ? { ...s } : null
120
+ },
121
+ onStatusChange(handler: (event: any) => void): Disposable {
122
+ return track(onDevEvent('session:statusChange', handler))
123
+ },
124
+ }
125
+
126
+ // ==================== UIRegistry ====================
127
+ //
128
+ // 与宿主 context.ts 同款:贡献项一律以 appId = 插件 id 写进壳注册表;运行面额外套
129
+ // 一层 PluginContextHost 补 provide('pluginContext')——壳直渲染运行面,不认识插件,
130
+ // 因此插件形态的细节(上下文注入)必须收在插件侧这层包装里。
131
+ const shellRegistry = getShellRegistry()
132
+
133
+ const ui: UIRegistry = {
134
+ registerSurface(surface) {
135
+ const wrapped = defineComponent({
136
+ name: `DevShellSurface-${pluginId}`,
137
+ // 壳透传 { app } prop:声明吞掉,避免作为未知 attr 落到根节点
138
+ props: { app: { type: Object, default: null } },
139
+ setup() {
140
+ return () => h(PluginContextHost, { pluginId, component: surface.component })
141
+ },
142
+ })
143
+ return track(shellRegistry.registerSurface(pluginId, { ...surface, component: wrapped }))
144
+ },
145
+ registerSlot(slot) {
146
+ return track(shellRegistry.registerSlot(pluginId, slot))
147
+ },
148
+ onSurfaceIntent(handler) {
149
+ // 与宿主同构:入口意图按 appId 排队,订阅前到达的补投(见 shell/surfaceIntent.ts)
150
+ return track(subscribeSurfaceIntent(pluginId, handler))
151
+ },
152
+ registerCapsuleItem(item) {
153
+ return track(shellRegistry.registerCapsuleItem(pluginId, item))
154
+ },
155
+ registerRoute(route) {
156
+ // 与宿主 routes.ts 同款:vue-router addRoute 承载整页跳转,注册表只做解析真源
157
+ const router = getSharedModule('router')
158
+ const header = route.header ?? true
159
+ const removeRoute = router.addRoute({
160
+ path: `/plugin/${pluginId}/${route.id}`,
161
+ name: pluginRouteName(pluginId, route.id),
162
+ meta: {
163
+ pluginRoute: { pluginId, routeId: route.id, title: route.title, header },
164
+ },
165
+ component: () => import('./shell/components/screens/PluginRoutePage.vue'),
166
+ })
167
+ const entry: RouteEntry = {
168
+ pluginId,
169
+ route: { ...route, header },
170
+ routeName: pluginRouteName(pluginId, route.id),
171
+ }
172
+ const unregister = registerRouteEntry(entry)
173
+ pushLog('debug', pluginId, `注册插件路由: ${route.id}`)
174
+ return track({
175
+ dispose() {
176
+ removeRoute()
177
+ unregister.dispose()
178
+ },
179
+ })
180
+ },
181
+ openPage(routeId: string): void {
182
+ const entry = findRoute(pluginId, routeId)
183
+ if (!entry) {
184
+ pushLog('warn', pluginId, `openPage("${routeId}") 未找到已注册路由`)
185
+ return
186
+ }
187
+ const router = getSharedModule('router')
188
+ router.push({ name: entry.routeName }).catch((e: unknown) => {
189
+ pushLog('error', pluginId, `openPage("${routeId}") 跳转失败: ${String(e)}`)
190
+ })
191
+ },
192
+ goBack(): void {
193
+ getSharedModule('router').back()
194
+ },
195
+ // Android 系统返回键:dev-shell 无系统返回概念,静默降级(回调永不触发),
196
+ // 保持与宿主插件 API 形状一致,避免插件在浏览器环境调用报错
197
+ onBackPressed() {
198
+ return { dispose() {} }
199
+ },
200
+ showDialog(options: PluginDialogOptions): PluginDialogHandle {
201
+ return openGlobalDialog({ ...options, pluginContext: contextRef! })
202
+ },
203
+ }
204
+
205
+ // ==================== EventAPI ====================
206
+ const events: EventAPI = {
207
+ on(event: string, handler: (...args: any[]) => void): Disposable {
208
+ return track(onDevEvent(event, handler))
209
+ },
210
+ emit(event: string, ...args: any[]): void {
211
+ emitDevEvent(event, ...args)
212
+ },
213
+ }
214
+
215
+ // ==================== StorageAPI ====================
216
+ const storage = {
217
+ async get<T = any>(key: string): Promise<T | undefined> {
218
+ try {
219
+ const raw = localStorage.getItem(storageKey(pluginId, key))
220
+ return raw === null ? undefined : (JSON.parse(raw) as T)
221
+ } catch {
222
+ return undefined
223
+ }
224
+ },
225
+ async set(key: string, value: any): Promise<void> {
226
+ try {
227
+ localStorage.setItem(storageKey(pluginId, key), JSON.stringify(value))
228
+ } catch {
229
+ pushLog('warn', pluginId, `storage.set("${key}") 失败(localStorage 不可用)`)
230
+ }
231
+ },
232
+ async delete(key: string): Promise<void> {
233
+ localStorage.removeItem(storageKey(pluginId, key))
234
+ },
235
+ }
236
+
237
+ // ==================== I18nAPI ====================
238
+ const i18n: I18nAPI = {
239
+ registerMessages(locale: string, messages: Record<string, unknown>): void {
240
+ const hostI18n = (window as any).__WASMNEST_SHARED__?.i18n
241
+ if (!hostI18n) return
242
+ const prefixed: Record<string, unknown> = {}
243
+ flattenMessages(messages, pluginId, prefixed)
244
+ hostI18n.global.mergeLocaleMessage(locale, prefixed)
245
+ },
246
+ t(key: string, params?: Record<string, unknown>): string {
247
+ const hostI18n = (window as any).__WASMNEST_SHARED__?.i18n
248
+ if (!hostI18n) return key
249
+ return hostI18n.global.t(`${pluginId}.${key}`, params)
250
+ },
251
+ }
252
+
253
+ // ==================== LifecycleAPI ====================
254
+ const lifecycle: LifecycleAPI = {
255
+ onAppStartup(handler) {
256
+ return track(onDevEvent('plugin:lifecycle:appStartup', handler))
257
+ },
258
+ onAppShutdown(handler) {
259
+ return track(onDevEvent('plugin:lifecycle:appShutdown', handler))
260
+ },
261
+ onAuthSuccess(handler) {
262
+ return track(onDevEvent('plugin:lifecycle:authSuccess', handler))
263
+ },
264
+ onDisconnect(handler) {
265
+ return track(onDevEvent('plugin:lifecycle:disconnect', (payload: any) => handler(payload.reason)))
266
+ },
267
+ onSessionCreated(handler) {
268
+ return track(onDevEvent('plugin:lifecycle:sessionCreated', (payload: any) => handler(payload.sessionId)))
269
+ },
270
+ onSessionStopped(handler) {
271
+ return track(onDevEvent('plugin:lifecycle:sessionStopped', (payload: any) => handler(payload.sessionId)))
272
+ },
273
+ }
274
+
275
+ // ==================== LoggerAPI ====================
276
+ const logger: LoggerAPI = {
277
+ info(message: string) { pushLog('info', pluginId, message) },
278
+ debug(message: string) { pushLog('debug', pluginId, message) },
279
+ warn(message: string) { pushLog('warn', pluginId, message) },
280
+ error(message: string) { pushLog('error', pluginId, message) },
281
+ }
282
+
283
+ // ==================== DialogAPI ====================
284
+ const dialogs = {
285
+ showDialog(options: DialogOptions) {
286
+ return dialogService.showDialog(options)
287
+ },
288
+ showConfirm(options: DialogOptions) {
289
+ return dialogService.showConfirm(options)
290
+ },
291
+ showPrompt(options: DialogOptions) {
292
+ return dialogService.showPrompt(options)
293
+ },
294
+ showToast(message: string, type: 'info' | 'success' | 'warning' | 'error' = 'info') {
295
+ dialogService.showToast(message, type)
296
+ },
297
+ }
298
+
299
+ // ==================== NotificationAPI ====================
300
+ const notifications: NotificationAPI = {
301
+ async notify(title, body) {
302
+ const msg = body ? `${title}: ${body}` : title
303
+ if ('Notification' in window) {
304
+ if (Notification.permission === 'default') {
305
+ await Notification.requestPermission().catch(() => undefined)
306
+ }
307
+ if (Notification.permission === 'granted') {
308
+ new Notification(title, { body })
309
+ return
310
+ }
311
+ }
312
+ dialogService.showToast(`[通知] ${msg}`, 'info')
313
+ },
314
+ }
315
+
316
+ // ==================== StatusAPI ====================
317
+ const status: StatusAPI = {
318
+ async reportReady() {
319
+ const record = getPluginRecord(pluginId)
320
+ if (record) {
321
+ record.state = 'activated'
322
+ record.error = undefined
323
+ }
324
+ pushLog('info', pluginId, 'status.reportReady() 插件已就绪')
325
+ },
326
+ async reportError(error) {
327
+ const record = getPluginRecord(pluginId)
328
+ if (record) {
329
+ record.state = 'error'
330
+ record.error = error
331
+ }
332
+ pushLog('error', pluginId, `status.reportError: ${error}`)
333
+ },
334
+ }
335
+
336
+ // ==================== SystemAPI(dev-shell 浏览器环境 no-op,与宿主接口对齐) ====================
337
+ const system = {
338
+ async openFile(_path: string, _displayName?: string): Promise<void> {
339
+ pushLog('info', pluginId, 'system.openFile (mock) 浏览器环境不支持')
340
+ },
341
+ async revealInDir(_path: string): Promise<void> {
342
+ pushLog('info', pluginId, 'system.revealInDir (mock) 浏览器环境不支持')
343
+ },
344
+ async revealReceivedFileLocation(_fileName: string): Promise<void> {
345
+ pushLog('info', pluginId, 'system.revealReceivedFileLocation (mock) 浏览器环境不支持')
346
+ },
347
+ async requestAllFilesAccess(): Promise<boolean> {
348
+ pushLog('info', pluginId, 'system.requestAllFilesAccess (mock) 浏览器环境无此权限')
349
+ return true
350
+ },
351
+ async openDownloadDir(): Promise<void> {
352
+ pushLog('info', pluginId, 'system.openDownloadDir (mock) 浏览器环境不支持')
353
+ },
354
+ }
355
+
356
+ const context: PluginContext = {
357
+ id: pluginId,
358
+ commands,
359
+ session,
360
+ ui,
361
+ events,
362
+ storage,
363
+ i18n,
364
+ lifecycle,
365
+ logger,
366
+ dialogs,
367
+ notifications,
368
+ system,
369
+ status,
370
+ _disposables: disposables,
371
+ }
372
+ contextRef = context
373
+ return context
374
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Dev Shell 调试注册表
3
+ * -----------------------------------------------------------------------------
4
+ * 模块级响应式状态(跨组件共享单例):
5
+ * - 调试记录(内置应用 + 被调试插件:state / error / context)
6
+ * - 插件动态路由注册项(registerRoute 的真源,渲染由 vue-router 承载)
7
+ * - 日志面板数据
8
+ *
9
+ * 与宿主 `src/plugin/registry.ts` 的分工:宿主那份存「插件 UI 扩展点」,dev-shell
10
+ * 原来也照抄了一份(surfaces / slots / capsules / settingsEntries + activeView 视图栈)。
11
+ * 票 2026-10-10 起宿主壳只认 registerSurface 一种运行面形态,且壳内导航是屏幕栈而非
12
+ * 视图栈——那份副本已整面退役:
13
+ * · 界面贡献 → 改由 `src/shell/registry.ts`(壳注册表)持有,与宿主同构
14
+ * · 视图栈 → 改由 `src/shell/composables/useShellNavigation.ts`(屏幕栈)承担
15
+ * 保留在这里的只有「调试对象」自身的事实与插件路由注册表。
16
+ */
17
+ import { ref } from 'vue'
18
+ import type { Disposable, PluginDevMock, PluginRouteDescriptor } from '../../src/types'
19
+
20
+ // ==================== 插件 devMock(领域数据注册) ====================
21
+
22
+ /** 按 pluginId 注册的开发期领域数据(loader 在 activate 前调用,deactivate 时清理) */
23
+ const devMocks = new Map<string, PluginDevMock>()
24
+
25
+ export function registerDevMock(pluginId: string, mock: PluginDevMock): Disposable {
26
+ devMocks.set(pluginId, mock)
27
+ return {
28
+ dispose() {
29
+ devMocks.delete(pluginId)
30
+ },
31
+ }
32
+ }
33
+
34
+ /** 取指定插件的领域数据(createMockContext 按 pluginId 合并用) */
35
+ export function getDevMock(pluginId: string): PluginDevMock | undefined {
36
+ return devMocks.get(pluginId)
37
+ }
38
+
39
+ /** 全部已注册领域数据(mobileApi 等全局单例能力按序合并用,如队列种子) */
40
+ export function getAllDevMocks(): PluginDevMock[] {
41
+ return [...devMocks.values()]
42
+ }
43
+
44
+ // ==================== 日志 ====================
45
+
46
+ export interface DevLogEntry {
47
+ id: number
48
+ ts: string
49
+ pluginId: string
50
+ level: 'debug' | 'info' | 'warn' | 'error'
51
+ message: string
52
+ }
53
+
54
+ const logs = ref<DevLogEntry[]>([])
55
+ let nextLogId = 0
56
+ const MAX_LOGS = 500
57
+
58
+ /** 记录日志(同步到 console,供浏览器 devtools 与日志面板双通道排查) */
59
+ export function pushLog(
60
+ level: DevLogEntry['level'],
61
+ pluginId: string,
62
+ message: string,
63
+ ): void {
64
+ const entry: DevLogEntry = {
65
+ id: ++nextLogId,
66
+ ts: new Date().toLocaleTimeString('zh-CN', { hour12: false }),
67
+ pluginId,
68
+ level,
69
+ message,
70
+ }
71
+ logs.value.push(entry)
72
+ if (logs.value.length > MAX_LOGS) logs.value.splice(0, logs.value.length - MAX_LOGS)
73
+ const fn = level === 'error' ? console.error : level === 'warn' ? console.warn : console.log
74
+ fn(`[dev-shell][${pluginId}] ${message}`)
75
+ }
76
+
77
+ export function clearLogs(): void {
78
+ logs.value = []
79
+ }
80
+
81
+ // ==================== 调试记录(壳应用的数据源) ====================
82
+
83
+ export type DevPluginState = 'loaded' | 'activated' | 'deactivated' | 'error'
84
+
85
+ export interface DevPluginRecord {
86
+ id: string
87
+ name: string
88
+ /** plugin.json 原文(内置应用给等价的静态元信息) */
89
+ manifest: Record<string, unknown>
90
+ /** 入口模块(内置应用为 null) */
91
+ entry: any
92
+ state: DevPluginState
93
+ error?: string
94
+ context: any
95
+ /** devMock 注册句柄(deactivate 时清理) */
96
+ devMockDisposable?: Disposable
97
+ /** 内置应用标记(dev-shell 自带、非被调试插件):壳里显示「官方」徽标 */
98
+ builtin?: boolean
99
+ }
100
+
101
+ const plugins = ref<DevPluginRecord[]>([])
102
+
103
+ export function getPluginRecord(pluginId: string): DevPluginRecord | undefined {
104
+ return plugins.value.find((p) => p.id === pluginId)
105
+ }
106
+
107
+ // ==================== 插件动态路由(渲染承载在 vue-router) ====================
108
+
109
+ /**
110
+ * 已注册路由条目
111
+ *
112
+ * 与宿主 `src/plugin/routes.ts` 同构:注册时既写这里(解析真源),也在 vue-router
113
+ * 上 addRoute(页面承载);dispose 双向撤销。渲染组件见 `shell/components/screens/
114
+ * PluginRoutePage.vue`。
115
+ */
116
+ export interface RouteEntry {
117
+ pluginId: string
118
+ route: PluginRouteDescriptor
119
+ /** router 路由名(registerRoute 时 addRoute,dispose 时 removeRoute) */
120
+ routeName: string
121
+ }
122
+
123
+ const routes = ref<RouteEntry[]>([])
124
+
125
+ /** 登记路由条目(router 侧由调用方 addRoute 后登记;dispose = 撤销登记) */
126
+ export function registerRouteEntry(entry: RouteEntry): Disposable {
127
+ routes.value.push(entry)
128
+ return {
129
+ dispose() {
130
+ const idx = routes.value.indexOf(entry)
131
+ if (idx !== -1) routes.value.splice(idx, 1)
132
+ },
133
+ }
134
+ }
135
+
136
+ /** 路由名(守卫与跳转共用,避免字符串漂移) */
137
+ export function pluginRouteName(pluginId: string, routeId: string): string {
138
+ return `dev-plugin-route-${pluginId}-${routeId}`
139
+ }
140
+
141
+ /** 取指定插件的路由条目 */
142
+ export function findRoute(pluginId: string, routeId: string): RouteEntry | undefined {
143
+ return routes.value.find((r) => r.pluginId === pluginId && r.route.id === routeId)
144
+ }
145
+
146
+ /** 取指定插件的全部路由 */
147
+ export function routesOf(pluginId: string): RouteEntry[] {
148
+ return routes.value.filter((r) => r.pluginId === pluginId)
149
+ }
150
+
151
+ export { logs, plugins, routes }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Dev Shell 共享运行时
3
+ *
4
+ * 与宿主 shared-runtime.ts 同构:把 dev-shell 自身的 vue / vue-i18n / pinia /
5
+ * router / i18n 实例 + mock 模块(presetTasks / dialogs / mobileApi)暴露到
6
+ * window.__WASMNEST_SHARED__,插件经 SDK getSharedModule() 取用。
7
+ * 必须在导入插件模块之前初始化。
8
+ */
9
+
10
+ const SHARED_KEY = '__WASMNEST_SHARED__'
11
+
12
+ export interface SharedRuntimeOptions {
13
+ pinia: any
14
+ router: any
15
+ i18n: any
16
+ presetTasks: any
17
+ dialogs: any
18
+ mobileApi: any
19
+ }
20
+
21
+ export async function initSharedRuntime(options: SharedRuntimeOptions): Promise<void> {
22
+ const vue = await import('vue')
23
+ const vueI18n = await import('vue-i18n')
24
+ const piniaMod = await import('pinia')
25
+ ;(window as any)[SHARED_KEY] = {
26
+ vue,
27
+ 'vue-i18n': vueI18n,
28
+ pinia: options.pinia,
29
+ i18n: options.i18n,
30
+ router: options.router,
31
+ presetTasks: options.presetTasks,
32
+ dialogs: options.dialogs,
33
+ mobileApi: options.mobileApi,
34
+ }
35
+ }
36
+
37
+ /** 获取共享模块(SDK runtime.ts 同款实现) */
38
+ export function getSharedModule(name: string): any {
39
+ const shared = (window as any)[SHARED_KEY]
40
+ if (!shared) throw new Error('[DevShell] Shared runtime not initialized')
41
+ const mod = shared[name]
42
+ if (!mod) throw new Error(`[DevShell] Shared module "${name}" not found`)
43
+ return mod
44
+ }
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <div class="flex flex-col h-full min-h-0 mobile-app mobile-ui bg-[var(--mobile-bg-primary)] text-[var(--mobile-text-primary)]">
3
+ <ShellHost />
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ /**
9
+ * Dev Shell 宿主壳入口(宿主 ShellView.vue 的同形实现)
10
+ * -----------------------------------------------------------------------------
11
+ * 这一层只做三件事:注册应用数据源、首次拉清单、卸载时回收。其余全部交给
12
+ * ShellHost——入口越薄,将来换数据源时改动面越小。
13
+ *
14
+ * 与宿主的三处差异(都是浏览器环境使然,不改变壳的形态):
15
+ * · 无安全区注入:宿主读 Tauri 的安全区值,浏览器的 env() 已由 mobile.css 兜住
16
+ * · 无 100dvh 容器:高度由 App.vue 的手机视口容器承担(宿主承担者是 ShellView 自己)
17
+ * · 数据源是 dev-shell 的调试记录(内置应用 + 被调试插件),不是宿主插件运行时
18
+ */
19
+ import { onMounted, onUnmounted } from 'vue'
20
+ import ShellHost from './components/ShellHost.vue'
21
+ import { createDevAppSource, DEV_APP_SOURCE_ID } from './adapters/devAppSource'
22
+ import { activatePlugin, deactivatePlugin } from '../loader'
23
+ import { useShellApps } from './composables/useShellApps'
24
+ import { getShellRegistry } from './registry'
25
+ import { logger } from './logger'
26
+ import type { Disposable } from './types'
27
+
28
+ const registry = getShellRegistry()
29
+ const { refresh } = useShellApps()
30
+
31
+ let sourceDisposable: Disposable | null = null
32
+
33
+ onMounted(async () => {
34
+ // 数据源在挂载时注册:壳本身不 import 任何具体形态的实现细节
35
+ sourceDisposable = registry.registerSource(
36
+ createDevAppSource({ activate: activatePlugin, deactivate: deactivatePlugin }),
37
+ )
38
+ try {
39
+ await refresh()
40
+ } catch (e) {
41
+ // refresh 内部已逐源兜底并记录,这里只兜住意外抛出,避免挂了白屏
42
+ logger.error(`initial refresh failed: ${String(e)}`)
43
+ }
44
+ })
45
+
46
+ onUnmounted(() => {
47
+ // 对称回收:先清该源写入的应用,再摘数据源,避免留下无主的记录
48
+ registry.clearSource(DEV_APP_SOURCE_ID)
49
+ sourceDisposable?.dispose()
50
+ sourceDisposable = null
51
+ })
52
+ </script>