@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +363 -2
  2. package/README_en.md +353 -0
  3. package/bin/build.js +269 -0
  4. package/bin/cli.js +96 -0
  5. package/bin/lib.js +349 -0
  6. package/bin/manifest-gen.js +324 -0
  7. package/bin/package.js +150 -0
  8. package/bin/scaffold.js +285 -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 +51 -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 +328 -0
  25. package/dev-shell/src/locales/index.ts +70 -0
  26. package/dev-shell/src/locales/shell.ts +328 -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 +351 -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 +155 -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 +496 -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 +378 -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 +316 -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 +415 -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 +35 -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/useToast.ts +33 -0
  71. package/dev-shell/src/shell/index.ts +88 -0
  72. package/dev-shell/src/shell/logger.ts +45 -0
  73. package/dev-shell/src/shell/permissions.ts +145 -0
  74. package/dev-shell/src/shell/registry.ts +220 -0
  75. package/dev-shell/src/shell/styles/shell.css +841 -0
  76. package/dev-shell/src/shell/types.ts +137 -0
  77. package/dev-shell/src/shell/utils.ts +54 -0
  78. package/dev-shell/src/styles/main.css +153 -0
  79. package/dev-shell/src/styles/mobile.css +884 -0
  80. package/dev-shell/src/styles/wallpaper.css +130 -0
  81. package/dev-shell/src/theme.ts +71 -0
  82. package/dev-shell/src/vite-env.d.ts +20 -0
  83. package/dev-shell/tailwind.config.js +101 -0
  84. package/dev-shell/tsconfig.json +16 -0
  85. package/dev-shell/vite.config.ts +130 -0
  86. package/dist/index.d.ts +84 -0
  87. package/dist/index.js +161 -0
  88. package/dist/types.d.ts +637 -0
  89. package/dist/types.js +0 -0
  90. package/dist/vite-plugin.d.ts +16 -0
  91. package/dist/vite-plugin.js +95 -0
  92. package/package.json +80 -3
  93. package/src/constants.ts +6 -0
  94. package/src/global-dialog.ts +168 -0
  95. package/src/index.ts +87 -0
  96. package/src/runtime.ts +44 -0
  97. package/src/types.ts +715 -0
  98. package/src/ui/PluginGlobalDialog.vue +388 -0
  99. package/src/ui/Select.d.ts +37 -0
  100. package/src/ui/Select.vue +307 -0
  101. package/src/ui/plugin-global-dialog.d.ts +11 -0
  102. package/src/ui/useSwipeTabs.d.ts +20 -0
  103. package/src/ui/useSwipeTabs.ts +53 -0
  104. package/src/vite-plugin.ts +132 -0
  105. package/template/.gitignore +4 -0
  106. package/template/README.md +46 -0
  107. package/template/package.json +23 -0
  108. package/template/plugin.json +13 -0
  109. package/template/rust/Cargo.toml +19 -0
  110. package/template/rust/src/lib.rs +33 -0
  111. package/template/src/env.d.ts +24 -0
  112. package/template/src/index.ts +37 -0
  113. package/template/tsconfig.json +17 -0
  114. package/template/vite.config.ts +21 -0
@@ -0,0 +1,378 @@
1
+ <template>
2
+ <div class="flex flex-col h-full min-h-0">
3
+ <!-- ==================== 返回行 ==================== -->
4
+ <div class="flex items-center gap-2 px-2 pt-2 pb-1">
5
+ <button
6
+ type="button"
7
+ class="flex items-center justify-center rounded-[10px] min-w-[var(--mobile-touch-target-min)] min-h-[var(--mobile-touch-target-min)] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)]"
8
+ :aria-label="t('shell.detail.back')"
9
+ @click="nav.back()"
10
+ >
11
+ <svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
12
+ <path d="M15 6l-6 6 6 6" />
13
+ </svg>
14
+ </button>
15
+ <span class="text-[var(--font-size-base)] font-semibold text-[var(--mobile-text-primary)]">
16
+ {{ t('shell.detail.title') }}
17
+ </span>
18
+ </div>
19
+
20
+ <div v-if="app" class="flex-1 min-h-0 overflow-y-auto pb-6">
21
+ <!-- ==================== Hero ==================== -->
22
+ <div class="flex items-center gap-3.5 px-4 pt-2 pb-4">
23
+ <ShellAppIcon :app="app" :size="60" />
24
+ <div class="flex-1 min-w-0">
25
+ <div class="flex items-center gap-2">
26
+ <b class="text-[var(--font-size-xl)] text-[var(--mobile-text-primary)] truncate">{{ app.name }}</b>
27
+ <ShellChip v-if="app.official" :label="t('shell.detail.official')" tone="accent" />
28
+ </div>
29
+ <div class="mt-0.5 text-[var(--font-size-sm)] text-[var(--mobile-text-secondary)] truncate">
30
+ {{ app.version ? t('shell.detail.version', { version: app.version }) : '' }}
31
+ <span v-if="app.author"> · {{ app.author }}</span>
32
+ </div>
33
+ <div class="mt-1 flex items-center gap-1.5 text-[var(--font-size-xs)]">
34
+ <span class="w-1.5 h-1.5 rounded-full flex-shrink-0" :style="{ background: stateDot }" aria-hidden="true" />
35
+ <span :style="{ color: 'var(--mobile-text-secondary)' }">{{ stateLabel }}</span>
36
+ <span v-if="app.error" class="truncate" :style="{ color: 'var(--mobile-error)' }"> · {{ app.error }}</span>
37
+ </div>
38
+ </div>
39
+ </div>
40
+
41
+ <!-- ==================== 待审批(需要用户动作:整单批准 + 哈希钉扎) ==================== -->
42
+ <div v-if="app.state === 'approval'" class="px-4 pb-1">
43
+ <div
44
+ class="rounded-[12px] border px-3 py-3"
45
+ :style="{
46
+ background: 'var(--mobile-warning-muted)',
47
+ borderColor: 'var(--mobile-warning)',
48
+ }"
49
+ >
50
+ <p class="text-[var(--font-size-sm)] text-[var(--mobile-text-primary)]">
51
+ {{ t('shell.detail.approvalDesc', { count: app.permissions.length }) }}
52
+ </p>
53
+ <button
54
+ type="button"
55
+ class="mt-2.5 w-full rounded-[10px] px-4 py-2.5 text-[var(--font-size-base)] transition-opacity duration-200 active:opacity-80 min-h-[var(--mobile-touch-target-min)]"
56
+ :style="{ background: 'var(--mobile-accent)', color: 'var(--mobile-text-on-accent)' }"
57
+ @click="handleApprove"
58
+ >
59
+ {{ t('shell.detail.approveStart') }}
60
+ </button>
61
+ </div>
62
+ </div>
63
+
64
+ <!-- ==================== 运行状态 ==================== -->
65
+ <!-- 应用自持连接,平台不知道它的连接对端;这里只投影平台确实掌握的事实:运行态 -->
66
+ <ShellSection :title="t('shell.detail.state')" />
67
+ <div class="px-4 pb-1">
68
+ <ShellGroupCard>
69
+ <div class="flex items-center gap-3 px-3 py-3">
70
+ <span class="w-1.5 h-1.5 rounded-full flex-shrink-0" :style="{ background: stateDot }" aria-hidden="true" />
71
+ <div class="flex-1 min-w-0">
72
+ <div class="text-[var(--font-size-base)] font-medium text-[var(--mobile-text-primary)]">
73
+ {{ app.name }}
74
+ </div>
75
+ </div>
76
+ <ShellChip :label="stateLabel" :tone="stateTone" />
77
+ </div>
78
+ </ShellGroupCard>
79
+ </div>
80
+
81
+ <!-- ==================== 权限 ==================== -->
82
+ <ShellSection :title="t('shell.detail.permissions')" :note="permissionsNote" />
83
+ <div class="px-4 pb-1">
84
+ <ShellGroupCard v-if="permissionGroups.length > 0">
85
+ <template v-for="group in permissionGroups" :key="group.id">
86
+ <div class="px-3 pt-2.5 pb-1 text-[var(--font-size-xs)] font-semibold text-[var(--mobile-text-muted)]">
87
+ {{ t(group.titleKey) }}
88
+ </div>
89
+ <div
90
+ v-for="grant in group.items"
91
+ :key="grant.key"
92
+ class="flex items-center gap-3 px-3 py-2.5 min-h-[var(--mobile-touch-target-min)]"
93
+ >
94
+ <div class="flex-1 min-w-0">
95
+ <div class="text-[var(--font-size-base)] font-medium text-[var(--mobile-text-primary)]">
96
+ {{ permissionTitle(grant.key) }}
97
+ <code class="ml-1.5 text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]">{{ grant.key }}</code>
98
+ </div>
99
+ <div
100
+ v-if="permissionDesc(grant.key)"
101
+ class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]"
102
+ >
103
+ {{ permissionDesc(grant.key) }}
104
+ </div>
105
+ <div v-if="grant.locked" class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]">
106
+ {{ t('shell.detail.permissionLocked') }}
107
+ </div>
108
+ <div v-else-if="grant.scope" class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]">
109
+ {{ grant.scope }}
110
+ </div>
111
+ </div>
112
+ <!-- 锁定项:不给开关,只标徽标——隐藏会让用户误以为应用没有该能力 -->
113
+ <ShellChip v-if="grant.locked" :label="t('shell.detail.permissionLocked')" tone="neutral" />
114
+ <Toggle
115
+ v-else
116
+ :model-value="grant.granted"
117
+ :disabled="!permissionControlEnabled"
118
+ @update:model-value="(next: boolean) => handleToggle(grant.key, next)"
119
+ />
120
+ </div>
121
+ </template>
122
+ </ShellGroupCard>
123
+ <p
124
+ v-else
125
+ class="rounded-[12px] border border-dashed border-[var(--mobile-border-hover)] px-3 py-4 text-center text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]"
126
+ >
127
+ {{ t('mobile.plugin.noPermissions') }}
128
+ </p>
129
+ <!-- 能力缺失要显性说明:把开关置灰却不解释,用户会以为是应用的问题 -->
130
+ <p
131
+ v-if="!permissionControlEnabled"
132
+ class="mt-2 px-1 text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]"
133
+ >
134
+ {{ t('shell.detail.permissionUnsupported') }}
135
+ </p>
136
+ <p v-if="toggleError" class="mt-2 px-1 text-[var(--font-size-xs)]" :style="{ color: 'var(--mobile-error)' }">
137
+ {{ toggleError }}
138
+ </p>
139
+ </div>
140
+
141
+ <!-- ==================== 存储 ==================== -->
142
+ <ShellSection :title="t('shell.detail.storage')" />
143
+ <div class="px-4 pb-1">
144
+ <ShellGroupCard>
145
+ <div class="flex items-center px-3 py-3 min-h-[var(--mobile-touch-target-min)]">
146
+ <span class="flex-1 text-[var(--font-size-base)] text-[var(--mobile-text-primary)]">
147
+ {{ t('shell.detail.appData') }}
148
+ </span>
149
+ <span class="text-[var(--font-size-sm)] text-[var(--mobile-text-secondary)]">{{ formatBytes(app.sizeBytes) }}</span>
150
+ </div>
151
+ <!-- 缓存行已删:后端没有缓存统计源,永远显示「—」的行属于空白项 -->
152
+ </ShellGroupCard>
153
+ </div>
154
+
155
+ <!-- ==================== 授权记录 ==================== -->
156
+ <ShellSection :title="t('shell.detail.grants')" :note="t('shell.detail.grantsNote')" />
157
+ <div class="px-4 pb-1">
158
+ <p
159
+ class="rounded-[12px] border border-dashed border-[var(--mobile-border-hover)] px-3 py-4 text-center text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]"
160
+ >
161
+ {{ t('shell.detail.grantsEmpty') }}
162
+ </p>
163
+ </div>
164
+
165
+ <!-- ==================== 操作 ==================== -->
166
+ <!-- 层级:停用(次要)→ 卸载(危险,描边而非淡粉底:淡粉底在浅色主题下
167
+ 看起来像 disabled 按钮,反而弱化了危险性 -->
168
+ <div class="px-4 pt-3 flex flex-col gap-2.5">
169
+ <button
170
+ type="button"
171
+ class="w-full rounded-[10px] border border-[var(--mobile-border)] px-4 py-3 text-[var(--font-size-base)] text-[var(--mobile-text-primary)] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)] min-h-[var(--mobile-touch-target-min)]"
172
+ @click="handleStop"
173
+ >
174
+ {{ t('shell.detail.disable') }}
175
+ </button>
176
+ <button
177
+ v-if="canRemove"
178
+ type="button"
179
+ class="w-full rounded-[10px] border px-4 py-3 text-[var(--font-size-base)] transition-colors duration-200 active:opacity-80 min-h-[var(--mobile-touch-target-min)]"
180
+ :style="{
181
+ borderColor: 'var(--mobile-error)',
182
+ color: 'var(--mobile-error)',
183
+ background: 'transparent',
184
+ }"
185
+ @click="confirmRemove = true"
186
+ >
187
+ {{ t('shell.detail.uninstall') }}
188
+ </button>
189
+ </div>
190
+ </div>
191
+
192
+ <!-- 应用已卸载/不存在:给出原因与出口,不留白屏 -->
193
+ <div v-else class="flex-1 flex items-center justify-center px-8 text-center">
194
+ <p class="text-[var(--font-size-base)] text-[var(--mobile-text-secondary)]">
195
+ {{ t('shell.run.notFound') }}
196
+ </p>
197
+ </div>
198
+
199
+ <!-- 危险操作二次确认:复用平台通用 ConfirmDialog,不用原生对话框
200
+ (原生 confirm 是系统弹窗,视觉与平台不一致,且不可本地化按钮)。
201
+ 放在 `v-if="app"` / `v-else` 配对之外,避免打断两者的相邻关系。 -->
202
+ <ConfirmDialog
203
+ :model-value="confirmRemove"
204
+ variant="danger"
205
+ :title="t('shell.detail.uninstall')"
206
+ :message="app ? t('shell.apps.uninstallConfirm', { name: app.name }) : ''"
207
+ :confirm-text="t('shell.detail.uninstall')"
208
+ :cancel-text="t('shell.common.cancel')"
209
+ @update:model-value="confirmRemove = $event"
210
+ @confirm="handleRemove"
211
+ />
212
+ </div>
213
+ </template>
214
+
215
+ <script setup lang="ts">
216
+ /**
217
+ * 应用详情与权限
218
+ *
219
+ * 权限开关是 UX,裁决在 Rust 端(docs/security.md §1)。因此:
220
+ * · 后端不支持逐项授予时,开关置灰并显式说明,不做「点了就算通过」的假成功
221
+ * · 授权记录区没有后端真源,渲染空态而不是编造几条示例
222
+ */
223
+ import { computed, ref, watch } from 'vue'
224
+ import { useI18n } from 'vue-i18n'
225
+ import ConfirmDialog from '../ui/ConfirmDialog.vue'
226
+ import Toggle from '../ui/Toggle.vue'
227
+ import { useToast } from '../../composables/useToast'
228
+ import { useShellApps } from '../../composables/useShellApps'
229
+ import { useShellNavigation } from '../../composables/useShellNavigation'
230
+ import { groupPermissions, permissionDescKey, permissionTitleKey } from '../../permissions'
231
+ import { formatBytes } from '../../utils'
232
+ import ShellAppIcon from '../ShellAppIcon.vue'
233
+ import ShellChip from '../ShellChip.vue'
234
+ import ShellGroupCard from '../ShellGroupCard.vue'
235
+ import ShellSection from '../ShellSection.vue'
236
+
237
+ const { t } = useI18n()
238
+ const toast = useToast()
239
+ const nav = useShellNavigation()
240
+ const {
241
+ getApp,
242
+ supportsPermissionControl,
243
+ setPermissionGrant,
244
+ supportsRemove,
245
+ removeApp,
246
+ stop,
247
+ approveApp,
248
+ launch,
249
+ } = useShellApps()
250
+
251
+ /** 应用 id 来自导航参数(壳内导航不落 URL) */
252
+ const appId = computed(() => nav.params.value.appId ?? '')
253
+ const app = computed(() => getApp(appId.value))
254
+
255
+ const permissionControlEnabled = computed(() =>
256
+ appId.value ? supportsPermissionControl(appId.value) : false,
257
+ )
258
+ const canRemove = computed(() => (appId.value ? supportsRemove(appId.value) : false))
259
+
260
+ /** 权限按能力域分组;未归类的新权限进「其他」组,保证不会因未归类而消失 */
261
+ const permissionGroups = computed(() =>
262
+ groupPermissions(app.value?.permissions ?? [], 'shell.permission.group.other'),
263
+ )
264
+
265
+ const permissionsNote = computed(() => {
266
+ const list = app.value?.permissions ?? []
267
+ const granted = list.filter((p) => p.granted).length
268
+ const locked = list.filter((p) => p.locked).length
269
+ return t('shell.detail.permissionsNote', { granted, locked })
270
+ })
271
+
272
+ /** 权限标题:复用既有本地化文案,未知权限回退原始权限词(不显示为空白) */
273
+ function permissionTitle(key: string): string {
274
+ const i18nKey = permissionTitleKey(key)
275
+ return i18nKey ? t(i18nKey) : key
276
+ }
277
+
278
+ /** 权限说明:已知说明 key 才展示(dev-shell 只维护 metrics:read 的能力边界文案) */
279
+ function permissionDesc(key: string): string {
280
+ const i18nKey = permissionDescKey(key)
281
+ return i18nKey ? t(i18nKey) : ''
282
+ }
283
+
284
+ const stateLabel = computed(() => {
285
+ switch (app.value?.state) {
286
+ case 'running':
287
+ return t('shell.common.running')
288
+ case 'approval':
289
+ return t('shell.common.approval')
290
+ case 'disabled':
291
+ return t('shell.common.disabled')
292
+ case 'error':
293
+ return t('shell.common.error')
294
+ default:
295
+ return t('shell.common.stopped')
296
+ }
297
+ })
298
+
299
+ const stateTone = computed<'success' | 'warn' | 'danger' | 'neutral'>(() => {
300
+ switch (app.value?.state) {
301
+ case 'running':
302
+ return 'success'
303
+ case 'approval':
304
+ return 'warn'
305
+ case 'disabled':
306
+ return 'warn'
307
+ case 'error':
308
+ return 'danger'
309
+ default:
310
+ return 'neutral'
311
+ }
312
+ })
313
+
314
+ const stateDot = computed(() => {
315
+ switch (app.value?.state) {
316
+ case 'running':
317
+ return 'var(--mobile-success)'
318
+ case 'approval':
319
+ return 'var(--mobile-warning)'
320
+ case 'error':
321
+ return 'var(--mobile-error)'
322
+ default:
323
+ return 'var(--mobile-text-disabled)'
324
+ }
325
+ })
326
+
327
+ const toggleError = ref<string | null>(null)
328
+ /** 卸载二次确认(复用平台 ConfirmDialog,见模板) */
329
+ const confirmRemove = ref(false)
330
+ // 切换应用时清掉上一条的失败提示,避免张冠李戴
331
+ watch(appId, () => {
332
+ toggleError.value = null
333
+ })
334
+
335
+ async function handleToggle(key: string, next: boolean): Promise<void> {
336
+ if (!appId.value) return
337
+ const ok = await setPermissionGrant(appId.value, key, next)
338
+ if (!ok) {
339
+ toggleError.value = t('shell.detail.permissionToggleFailed', {
340
+ reason: t('shell.detail.permissionUnsupported'),
341
+ })
342
+ }
343
+ }
344
+
345
+ async function handleStop(): Promise<void> {
346
+ if (!appId.value) return
347
+ await stop(appId.value)
348
+ }
349
+
350
+ /**
351
+ * 批准并启动
352
+ *
353
+ * 审批是整单的(后端 plugin_approve:全部声明权限 + 内容哈希钉扎);批准失败时
354
+ * 不继续启动——半途而废的「已批准」假象比直接报错更危险(权限是安全面)。
355
+ */
356
+ async function handleApprove(): Promise<void> {
357
+ if (!app.value) return
358
+ const approved = await approveApp(app.value.id)
359
+ if (!approved) {
360
+ toggleError.value = t('shell.permissions.approveFailed')
361
+ return
362
+ }
363
+ const started = await launch(app.value.id)
364
+ if (started) nav.openApp(app.value.id)
365
+ }
366
+
367
+ async function handleRemove(): Promise<void> {
368
+ confirmRemove.value = false
369
+ if (!app.value) return
370
+ const ok = await removeApp(app.value.id)
371
+ if (ok) {
372
+ toast.success(t('shell.apps.uninstallSuccess', { name: app.value.name }))
373
+ nav.back()
374
+ } else {
375
+ toast.error(t('shell.apps.uninstallFailed', { error: t('shell.run.notFound') }))
376
+ }
377
+ }
378
+ </script>
@@ -0,0 +1,90 @@
1
+ <template>
2
+ <!-- 根节点自铺默认页面底色:平台顶栏与应用运行面是同一个应用窗口
3
+ (与真机 ShellAppRunScreen 同形)。 -->
4
+ <div class="flex flex-col h-full min-h-0 bg-[var(--mobile-bg-primary)]">
5
+ <!--
6
+ 平台顶栏:左侧应用身份(图标 + 名称),右侧胶囊(菜单 / 多任务 / 回主屏)。
7
+ 三个按钮都是显式点击路径,不依赖系统手势;胶囊对齐小程序形态——平台的
8
+ 控制项浮在应用之上,但**不**在界面上讲解自己是什么(2026-10-14 修订)。
9
+ -->
10
+ <header class="flex items-center gap-2.5 px-3 pt-1.5 pb-1 flex-shrink-0">
11
+ <ShellAppIcon v-if="app" :app="app" :size="30" />
12
+ <span
13
+ class="flex-1 min-w-0 text-[var(--font-size-base)] font-medium text-[var(--mobile-text-primary)] truncate"
14
+ >
15
+ {{ app?.name ?? t('shell.run.notFound') }}
16
+ </span>
17
+
18
+ <div class="shell-capsule">
19
+ <button
20
+ type="button"
21
+ class="shell-capsule-btn"
22
+ :aria-label="t('shell.run.menu')"
23
+ aria-haspopup="dialog"
24
+ @click="overlays.openCapsule(appId)"
25
+ >
26
+ <svg width="19" height="19" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
27
+ <circle cx="5" cy="12" r="1.9" />
28
+ <circle cx="12" cy="12" r="1.9" />
29
+ <circle cx="19" cy="12" r="1.9" />
30
+ </svg>
31
+ </button>
32
+ <span class="shell-capsule-divider" aria-hidden="true" />
33
+ <button
34
+ type="button"
35
+ class="shell-capsule-btn"
36
+ :aria-label="t('shell.run.recents')"
37
+ @click="nav.openSwitcher()"
38
+ >
39
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
40
+ <rect x="7" y="3" width="14" height="14" rx="3" />
41
+ <path d="M3 7v10a4 4 0 0 0 4 4h10" />
42
+ </svg>
43
+ </button>
44
+ <span class="shell-capsule-divider" aria-hidden="true" />
45
+ <button
46
+ type="button"
47
+ class="shell-capsule-btn"
48
+ :aria-label="t('shell.run.home')"
49
+ @click="nav.goHome()"
50
+ >
51
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
52
+ <path d="M3 10.5L12 3l9 7.5" />
53
+ <path d="M5 9.5V21h14V9.5" />
54
+ </svg>
55
+ </button>
56
+ </div>
57
+ </header>
58
+
59
+ <!-- ==================== 应用运行面 ==================== -->
60
+ <ShellAppSurface :app-id="appId" />
61
+ </div>
62
+ </template>
63
+
64
+ <script setup lang="ts">
65
+ /**
66
+ * 应用运行屏
67
+ *
68
+ * 平台只叠加两样东西:顶部一行应用身份,与右侧胶囊(菜单 / 多任务 / 回主屏)。
69
+ * 应用内部界面由应用自持(ShellAppSurface),平台不画应用内页头,也不给应用
70
+ * 加返回键——返回不是这一层的语义,退出走「回主屏」。
71
+ *
72
+ * 底部系统条已在 2026-10-14 修订中整条退役:入口收进本屏胶囊(多任务 / 回主屏),
73
+ * 非根屏的返回由各屏自己的页头承担。这样平台导航条不再长期占用应用的可视高度。
74
+ */
75
+ import { computed } from 'vue'
76
+ import { useI18n } from 'vue-i18n'
77
+ import { useShellApps } from '../../composables/useShellApps'
78
+ import { useShellNavigation } from '../../composables/useShellNavigation'
79
+ import { useShellOverlays } from '../../composables/useShellOverlays'
80
+ import ShellAppIcon from '../ShellAppIcon.vue'
81
+ import ShellAppSurface from '../ShellAppSurface.vue'
82
+
83
+ const { t } = useI18n()
84
+ const nav = useShellNavigation()
85
+ const overlays = useShellOverlays()
86
+ const { getApp } = useShellApps()
87
+
88
+ const appId = computed(() => nav.params.value.appId ?? '')
89
+ const app = computed(() => getApp(appId.value))
90
+ </script>
@@ -0,0 +1,195 @@
1
+ <template>
2
+ <div class="flex flex-col h-full min-h-0">
3
+ <!-- ==================== 页头(带返回:系统宫格进入的屏,不是栈底) ==================== -->
4
+ <header class="flex items-center gap-2 px-2 pt-2 pb-1">
5
+ <button
6
+ type="button"
7
+ class="flex items-center justify-center rounded-[10px] min-w-[var(--mobile-touch-target-min)] min-h-[var(--mobile-touch-target-min)] transition-colors duration-200 active:bg-[var(--mobile-accent-muted)]"
8
+ :aria-label="t('shell.detail.back')"
9
+ @click="nav.back()"
10
+ >
11
+ <svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
12
+ <path d="M15 6l-6 6 6 6" />
13
+ </svg>
14
+ </button>
15
+ <div class="flex-1 min-w-0">
16
+ <h1 class="text-[var(--font-size-lg)] font-semibold text-[var(--mobile-text-primary)] truncate">
17
+ {{ t('shell.apps.title') }}
18
+ </h1>
19
+ <p class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
20
+ {{ t('shell.apps.subtitle', { installed: stats.installed, running: stats.running }) }}
21
+ </p>
22
+ </div>
23
+ </header>
24
+
25
+ <div class="flex-1 min-h-0 overflow-y-auto pb-6">
26
+ <!-- ==================== 统计条 ==================== -->
27
+ <!-- 单行指标条而非三张等宽卡片:三项指标同质,拆成三栏只会拉长竖向空间并显得像模板;
28
+ 零值不再用 success 色——「0 个运行中」是中性事实,染绿会被误读为健康指示灯 -->
29
+ <div class="px-4 pb-1">
30
+ <div
31
+ class="flex items-center gap-2 rounded-[12px] border border-[var(--mobile-group-border)] bg-[var(--mobile-bg-card)] px-3.5 py-3"
32
+ :style="{ boxShadow: 'var(--mobile-card-shadow)' }"
33
+ >
34
+ <template v-for="(metric, index) in metrics" :key="metric.label">
35
+ <span v-if="index > 0" class="text-[var(--font-size-xs)] text-[var(--mobile-text-muted)]" aria-hidden="true">·</span>
36
+ <span class="flex items-baseline gap-1.5 min-w-0">
37
+ <b
38
+ class="text-[var(--font-size-base)] font-semibold tabular-nums"
39
+ :style="{ color: metric.highlight ? 'var(--mobile-success)' : 'var(--mobile-text-primary)' }"
40
+ >
41
+ {{ metric.value }}
42
+ </b>
43
+ <span class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
44
+ {{ metric.label }}
45
+ </span>
46
+ </span>
47
+ </template>
48
+ </div>
49
+ </div>
50
+
51
+ <!-- ==================== 已安装列表 ==================== -->
52
+ <ShellSection :title="t('shell.apps.installedTitle')" />
53
+ <div class="px-4 pb-1">
54
+ <ShellGroupCard v-if="sortedApps.length > 0">
55
+ <button
56
+ v-for="app in sortedApps"
57
+ :key="app.id"
58
+ type="button"
59
+ class="flex items-center gap-3 w-full px-3 py-3 text-left transition-colors duration-200 active:bg-[var(--mobile-group-row-active)] min-h-[var(--mobile-touch-target-min)]"
60
+ @click="nav.openDetail(app.id)"
61
+ >
62
+ <ShellAppIcon :app="app" :size="40" />
63
+ <span class="flex-1 min-w-0">
64
+ <span class="flex items-center gap-1.5">
65
+ <b class="text-[var(--font-size-base)] text-[var(--mobile-text-primary)] truncate">{{ app.name }}</b>
66
+ <ShellChip v-if="app.official" :label="t('shell.detail.official')" tone="accent" />
67
+ <ShellChip
68
+ v-if="app.state === 'running'"
69
+ :label="t('shell.common.running')"
70
+ tone="success"
71
+ />
72
+ <ShellChip
73
+ v-else-if="app.state === 'disabled'"
74
+ :label="t('shell.common.disabled')"
75
+ tone="neutral"
76
+ />
77
+ <ShellChip
78
+ v-else-if="app.state === 'error'"
79
+ :label="t('shell.common.error')"
80
+ tone="danger"
81
+ />
82
+ </span>
83
+ <span class="block text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
84
+ {{ appMeta(app) }}
85
+ </span>
86
+ </span>
87
+ <svg class="flex-shrink-0" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" :style="{ color: 'var(--mobile-text-secondary)' }">
88
+ <path d="M9 6l6 6-6 6" />
89
+ </svg>
90
+ </button>
91
+ </ShellGroupCard>
92
+ <p
93
+ v-else
94
+ class="rounded-[12px] border border-dashed border-[var(--mobile-border-hover)] px-3 py-5 text-center text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]"
95
+ >
96
+ {{ t('shell.apps.empty') }}
97
+ </p>
98
+ </div>
99
+
100
+ <!-- ==================== 添加应用(按数据源能力渲染) ==================== -->
101
+ <ShellSection v-if="canInstall" :title="t('shell.apps.addTitle')" />
102
+ <div v-if="canInstall" class="px-4 pb-2">
103
+ <ShellGroupCard>
104
+ <button
105
+ type="button"
106
+ class="flex items-center gap-3 w-full px-3 py-3 text-left transition-colors duration-200 active:bg-[var(--mobile-group-row-active)] min-h-[var(--mobile-touch-target-min)]"
107
+ :disabled="installing"
108
+ @click="handleInstall"
109
+ >
110
+ <svg class="flex-shrink-0" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" :style="{ color: 'var(--mobile-text-secondary)' }">
111
+ <path d="M12 3v12" />
112
+ <path d="M7 10l5 5 5-5" />
113
+ <path d="M4 21h16" />
114
+ </svg>
115
+ <span class="flex-1 text-[var(--font-size-base)] text-[var(--mobile-text-primary)]">
116
+ {{ t('shell.apps.installLocal') }}
117
+ </span>
118
+ <span class="flex-shrink-0 text-[var(--font-size-xs)]" :style="{ color: 'var(--mobile-warning)' }">
119
+ {{ installing ? t('shell.common.loading') : t('shell.apps.installLocalHint') }}
120
+ </span>
121
+ </button>
122
+ </ShellGroupCard>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ </template>
127
+
128
+ <script setup lang="ts">
129
+ /**
130
+ * WASM 应用管理
131
+ *
132
+ * 列表只展示平台掌握的事实(版本 / 权限项数 / 数据占用),不猜测应用内部状态。
133
+ * 「添加应用」按数据源能力渲染:没有安装能力的形态不会出现点了没反应的按钮。
134
+ */
135
+ import { computed, ref } from 'vue'
136
+ import { useI18n } from 'vue-i18n'
137
+ import { useToast } from '../../composables/useToast'
138
+ import { useShellApps } from '../../composables/useShellApps'
139
+ import { useShellNavigation } from '../../composables/useShellNavigation'
140
+ import type { ShellApp } from '../../types'
141
+ import { formatBytes } from '../../utils'
142
+ import ShellAppIcon from '../ShellAppIcon.vue'
143
+ import ShellChip from '../ShellChip.vue'
144
+ import ShellGroupCard from '../ShellGroupCard.vue'
145
+ import ShellSection from '../ShellSection.vue'
146
+
147
+ const { t } = useI18n()
148
+ const toast = useToast()
149
+ const nav = useShellNavigation()
150
+ const { sortedApps, stats, supportsInstall, installFromLocalPackage, refresh } = useShellApps()
151
+
152
+ const installing = ref(false)
153
+
154
+ /**
155
+ * 安装能力是「是否有数据源支持」的派生值,做成 computed 而不是在模板里
156
+ * 直接放函数引用——放函数引用的 v-if 恒为真(函数本身永远存在)。
157
+ */
158
+ const canInstall = computed(() => supportsInstall())
159
+
160
+ /** 总占用:任一应用未统计时显示「—」,不把缺失值当 0 累加成假数字 */
161
+ const totalSizeLabel = computed(() =>
162
+ stats.value.totalBytes === undefined ? t('shell.common.na') : formatBytes(stats.value.totalBytes),
163
+ )
164
+
165
+ /** 指标条数据项(单行展示,与顶部副标题不再重复计数——副标题只说“本机共几个”) */
166
+ const metrics = computed(() => [
167
+ { value: String(stats.value.installed), label: t('shell.apps.statInstalled'), highlight: false },
168
+ { value: String(stats.value.running), label: t('shell.apps.statRunning'), highlight: stats.value.running > 0 },
169
+ { value: totalSizeLabel.value, label: t('shell.apps.statSize'), highlight: false },
170
+ ])
171
+
172
+ /** 列表副标题:版本 · 权限项数 · 数据占用 */
173
+ function appMeta(app: ShellApp): string {
174
+ const parts = [app.version ? `v${app.version}` : '']
175
+ parts.push(t('shell.apps.permissionCount', { count: app.permissions.length }))
176
+ parts.push(formatBytes(app.sizeBytes))
177
+ return parts.filter(Boolean).join(' · ')
178
+ }
179
+
180
+ async function handleInstall(): Promise<void> {
181
+ installing.value = true
182
+ try {
183
+ const installedId = await installFromLocalPackage()
184
+ // 取消选包不是失败,不弹错误
185
+ if (installedId !== null) {
186
+ toast.success(t('shell.apps.installSuccess'))
187
+ await refresh()
188
+ }
189
+ } catch (e) {
190
+ toast.error(t('shell.apps.installFailed', { error: e instanceof Error ? e.message : String(e) }))
191
+ } finally {
192
+ installing.value = false
193
+ }
194
+ }
195
+ </script>