@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,376 @@
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 flex-shrink-0">
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
+ <h1 class="flex-1 min-w-0 text-[var(--font-size-lg)] font-semibold text-[var(--mobile-text-primary)] truncate">
16
+ {{ t('shell.settings.permissions') }}
17
+ </h1>
18
+ </header>
19
+
20
+ <!-- ==================== 视图切换(按应用 / 按权限) ====================
21
+ 两个视图是同一份权限真源的两个投影方向:
22
+ · 按应用(默认):一行一应用,跨权限组不重复——这是「审计」主视图
23
+ · 按权限:反查「哪些应用持有某权限」,行尾带授予状态 -->
24
+ <div class="flex items-center px-4 pt-1 pb-1 flex-shrink-0">
25
+ <div class="shell-segmented" role="group" :aria-label="t('shell.permissions.viewSwitch')">
26
+ <button
27
+ type="button"
28
+ :aria-pressed="view === 'apps'"
29
+ @click="view = 'apps'"
30
+ >
31
+ {{ t('shell.permissions.viewApps') }}
32
+ </button>
33
+ <button
34
+ type="button"
35
+ :aria-pressed="view === 'groups'"
36
+ @click="view = 'groups'"
37
+ >
38
+ {{ t('shell.permissions.viewGroups') }}
39
+ </button>
40
+ </div>
41
+ </div>
42
+
43
+ <div class="flex-1 min-h-0 overflow-y-auto pb-6">
44
+ <!-- ==================== 视图:按应用 ==================== -->
45
+ <template v-if="view === 'apps'">
46
+ <!-- 待审批(需要用户动作,置顶)。审批是整单的(后端 plugin_approve:全部
47
+ 声明权限 + 内容哈希钉扎),因此这里不做逐项勾选。 -->
48
+ <template v-if="pendingApps.length > 0">
49
+ <ShellSection
50
+ :title="t('shell.permissions.pending')"
51
+ :note="t('shell.permissions.pendingNote')"
52
+ class="shell-reveal"
53
+ />
54
+ <div class="px-4 pb-1 flex flex-col gap-2">
55
+ <div
56
+ v-for="app in pendingApps"
57
+ :key="app.id"
58
+ class="flex items-center gap-3 rounded-[12px] border px-3 py-3"
59
+ :style="{
60
+ background: 'var(--mobile-warning-muted)',
61
+ borderColor: 'var(--mobile-warning)',
62
+ }"
63
+ >
64
+ <ShellAppIcon :app="app" :size="32" />
65
+ <div class="flex-1 min-w-0">
66
+ <div class="text-[var(--font-size-base)] font-medium text-[var(--mobile-text-primary)] truncate">
67
+ {{ app.name }}
68
+ </div>
69
+ <div class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
70
+ {{ t('shell.permissions.pendingBody', { count: app.permissions.length }) }}
71
+ </div>
72
+ </div>
73
+ <ShellChip
74
+ :label="t('shell.permissions.approveStart')"
75
+ tone="accent"
76
+ clickable
77
+ @click="approveAndStart(app.id)"
78
+ />
79
+ </div>
80
+ </div>
81
+ </template>
82
+
83
+ <!-- 应用权限清单:每行一个应用,摘要一行说清授予情况;完整的勾选与审计
84
+ 在详情页(openDetail),总览不复制明细——明细两份必然漂移 -->
85
+ <ShellSection
86
+ v-if="appRows.length > 0"
87
+ :title="t('shell.permissions.appSection')"
88
+ class="shell-reveal"
89
+ />
90
+ <div class="px-4">
91
+ <ShellGroupCard v-if="appRows.length > 0">
92
+ <button
93
+ v-for="app in appRows"
94
+ :key="app.id"
95
+ type="button"
96
+ 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)]"
97
+ @click="nav.openDetail(app.id)"
98
+ >
99
+ <ShellAppIcon :app="app" :size="32" />
100
+ <span class="flex-1 min-w-0">
101
+ <span class="block text-[var(--font-size-base)] text-[var(--mobile-text-primary)] truncate">
102
+ {{ app.name }}
103
+ </span>
104
+ <span class="block text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
105
+ {{ permissionSummary(app) }}
106
+ </span>
107
+ </span>
108
+ <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)' }">
109
+ <path d="M9 6l6 6-6 6" />
110
+ </svg>
111
+ </button>
112
+ </ShellGroupCard>
113
+
114
+ <!-- 全无应用才给整体空态;全待审批时审批卡已占位,列表不重复解释 -->
115
+ <p
116
+ v-if="appRows.length === 0 && apps.length === 0"
117
+ class="rounded-[12px] border border-dashed border-[var(--mobile-border-hover)] px-3 py-6 text-center text-[var(--font-size-sm)] text-[var(--mobile-text-secondary)]"
118
+ >
119
+ {{ t('mobile.plugin.noPermissions') }}
120
+ </p>
121
+ </div>
122
+ </template>
123
+
124
+ <!-- ==================== 视图:按权限(反查) ==================== -->
125
+ <template v-else>
126
+ <template v-if="domainRows.length > 0">
127
+ <!-- 能力域分组(顺序 = SHELL_PERMISSION_GROUPS;未归类词进「其他」)
128
+ 域内权限词一行:词名 + code + 持有应用徽章流。徽章比长列表紧凑:
129
+ 一眼扫到「谁持有什么、授予还是默认」,点徽章直达应用详情 -->
130
+ <div v-for="row in domainRows" :key="row.id">
131
+ <ShellSection
132
+ :title="t(row.titleKey)"
133
+ :note="t('shell.apps.permissionCount', { count: row.items.length })"
134
+ class="shell-reveal"
135
+ />
136
+ <div class="px-4 pb-1">
137
+ <ShellGroupCard>
138
+ <div v-for="word in row.items" :key="word.key" class="px-3 py-2.5">
139
+ <div class="flex items-center gap-2 min-w-0">
140
+ <span class="flex-1 min-w-0 text-[var(--font-size-sm)] font-medium text-[var(--mobile-text-primary)] truncate">
141
+ {{ permissionTitle(word.key) }}
142
+ </span>
143
+ <code class="flex-shrink-0 text-xs font-medium text-[var(--mobile-text-secondary)]">{{ word.key }}</code>
144
+ </div>
145
+ <div class="mt-2 flex flex-wrap gap-1.5">
146
+ <button
147
+ v-for="g in word.apps"
148
+ :key="g.app.id"
149
+ type="button"
150
+ class="flex items-center gap-1.5 rounded-full border px-2.5 h-8 min-w-0 transition-colors duration-200 active:opacity-70"
151
+ :class="grantChipClass(g)"
152
+ :aria-label="grantChipLabel(g)"
153
+ @click="nav.openDetail(g.app.id)"
154
+ >
155
+ <ShellAppIcon :app="g.app" :size="20" />
156
+ <span class="text-[var(--font-size-xs)] text-[var(--mobile-text-primary)] truncate">{{ g.app.name }}</span>
157
+ <!-- 状态尾缀:点(实心/空心)+ 文字双通道,非纯色传态 -->
158
+ <span class="flex items-center gap-1 flex-shrink-0 text-[var(--font-size-xs)]" :style="{ color: g.state.color }">
159
+ <span
160
+ class="w-1.5 h-1.5 rounded-full flex-shrink-0"
161
+ :style="
162
+ g.state.filled
163
+ ? { background: 'currentColor' }
164
+ : { border: '1.5px solid currentColor', background: 'transparent' }
165
+ "
166
+ aria-hidden="true"
167
+ />
168
+ {{ g.state.label }}
169
+ </span>
170
+ </button>
171
+ </div>
172
+ </div>
173
+ </ShellGroupCard>
174
+ </div>
175
+ </div>
176
+ </template>
177
+
178
+ <div v-else class="px-4 pt-6">
179
+ <p class="rounded-[12px] border border-dashed border-[var(--mobile-border-hover)] px-3 py-6 text-center text-[var(--font-size-sm)] text-[var(--mobile-text-secondary)]">
180
+ {{ t('mobile.plugin.noPermissions') }}
181
+ </p>
182
+ </div>
183
+ </template>
184
+ </div>
185
+ </div>
186
+ </template>
187
+
188
+ <script setup lang="ts">
189
+ /**
190
+ * 权限总览
191
+ *
192
+ * 与详情页的「按应用看权限」共用同一份权限授予真源,只是投影方向相反。
193
+ * 不新增任何权限状态——反查视图如果自己维护一份状态,两处迟早不一致。
194
+ *
195
+ * 2026-10-15 重设计(消除跨组重复):原页面按权限词分组,同一应用会在多个
196
+ * 权限组下反复出现(实测 WasmNest 3 次 / File Transfer 5 次),页面充满同名
197
+ * 重复行。改为双视图:
198
+ * · 按应用(默认)= 审计主视图,一行一应用,只给摘要行;勾选/审计去详情页
199
+ * · 按权限 = 反查「哪些应用持有某权限」,行尾带授予状态(点 + 文字双通道)
200
+ * 两者由同一份 apps.permissions 派生,视图切换不产生新状态。
201
+ */
202
+ import { computed, ref } from 'vue'
203
+ import { useI18n } from 'vue-i18n'
204
+ import { useToast } from '../../composables/useToast'
205
+ import { useShellApps } from '../../composables/useShellApps'
206
+ import { useShellNavigation } from '../../composables/useShellNavigation'
207
+ import { permissionTitleKey, SHELL_PERMISSION_GROUPS } from '../../permissions'
208
+ import type { ShellApp } from '../../types'
209
+ import ShellAppIcon from '../ShellAppIcon.vue'
210
+ import ShellChip from '../ShellChip.vue'
211
+ import ShellGroupCard from '../ShellGroupCard.vue'
212
+ import ShellSection from '../ShellSection.vue'
213
+
214
+ /** 能力域分组(顺序 = SHELL_PERMISSION_GROUPS,未归类词进「其他」) */
215
+ interface DomainRow {
216
+ id: string
217
+ titleKey: string
218
+ items: PermissionWordRow[]
219
+ }
220
+
221
+ /** 一个权限词的持有应用(带授予状态,用于徽章展示) */
222
+ interface PermissionWordRow {
223
+ key: string
224
+ apps: GrantApp[]
225
+ }
226
+
227
+ /** 应用 × 该权限词的授予状态 */
228
+ interface GrantApp {
229
+ app: ShellApp
230
+ state: GrantState
231
+ }
232
+
233
+ /** 授予状态展示(点 + 文案,不依赖单一颜色通道) */
234
+ interface GrantState {
235
+ label: string
236
+ color: string
237
+ /** true = 实心点(已授予),false = 空心点(默认 / 未授予) */
238
+ filled: boolean
239
+ /** 默认授予且不可关闭(storage 等底座能力,徽章用灰底而非绿底区分) */
240
+ locked: boolean
241
+ }
242
+
243
+ const { t } = useI18n()
244
+ const toast = useToast()
245
+ const nav = useShellNavigation()
246
+ const { apps, approveApp, launch } = useShellApps()
247
+
248
+ /** 当前视图:按应用(审计主视图,默认)|按权限(反查) */
249
+ const view = ref<'apps' | 'groups'>('apps')
250
+
251
+ /** 待审批应用:审批入口的置顶分区(批准后状态变化,卡片自然消失) */
252
+ const pendingApps = computed(() => apps.value.filter((a) => a.state === 'approval'))
253
+
254
+ /**
255
+ * 应用权限清单(按应用视图)
256
+ *
257
+ * 名称序而非 sortedApps 的运行优先:审计面要求顺序稳定,运行状态变化不应
258
+ * 让整页重新排。待审批应用由上方审批卡承担展示位,列表不重复出现。
259
+ */
260
+ const appRows = computed<ShellApp[]>(() =>
261
+ [...apps.value]
262
+ .filter((a) => a.state !== 'approval')
263
+ .sort((a, b) => a.name.localeCompare(b.name, 'zh-Hans-CN')),
264
+ )
265
+
266
+ /** 行尾摘要:授予/默认计数与详情页同一口径(granted/locked 双 filter) */
267
+ function permissionSummary(app: ShellApp): string {
268
+ const granted = app.permissions.filter((p) => p.granted).length
269
+ const locked = app.permissions.filter((p) => p.locked).length
270
+ if (granted === 0) return t('shell.permissions.appNone')
271
+ return locked > 0
272
+ ? t('shell.permissions.appSummaryLocked', { granted, locked })
273
+ : t('shell.permissions.appSummary', { granted })
274
+ }
275
+
276
+ /** 某应用对某权限词的授予状态(徽章尾缀与状态点) */
277
+ function grantStateOf(app: ShellApp, key: string): GrantState {
278
+ const grant = app.permissions.find((p) => p.key === key)
279
+ if (!grant || !grant.granted) {
280
+ return {
281
+ label: t('shell.permissions.ungranted'),
282
+ color: 'var(--mobile-text-disabled)',
283
+ filled: false,
284
+ locked: false,
285
+ }
286
+ }
287
+ if (grant.locked) {
288
+ return {
289
+ label: t('shell.permissions.locked'),
290
+ color: 'var(--mobile-text-secondary)',
291
+ filled: false,
292
+ locked: true,
293
+ }
294
+ }
295
+ return {
296
+ label: t('shell.permissions.granted'),
297
+ color: 'var(--mobile-success)',
298
+ filled: true,
299
+ locked: false,
300
+ }
301
+ }
302
+
303
+ /** 徽章容器样式:授予=绿底实描边 / 默认=灰底 / 未授予=透明虚线(形态区分,不只靠颜色) */
304
+ function grantChipClass(g: GrantApp): string {
305
+ if (g.state.filled) return 'border-[var(--mobile-success-connected-border)] bg-[var(--mobile-success-muted)]'
306
+ if (g.state.locked) return 'border-[var(--mobile-border)] bg-[var(--mobile-bg-elevated)]'
307
+ return 'border-dashed border-[var(--mobile-border-hover)] bg-transparent'
308
+ }
309
+
310
+ /** 徽章可访问名:应用名 + 授予状态(读屏用户看不到点与颜色) */
311
+ function grantChipLabel(g: GrantApp): string {
312
+ return `${g.app.name} · ${g.state.label}`
313
+ }
314
+
315
+ /**
316
+ * 批准并启动
317
+ *
318
+ * 批准失败(后端拒绝)时不继续启动——半途而废的「已批准」假象比直接报错更危险。
319
+ */
320
+ async function approveAndStart(appId: string): Promise<void> {
321
+ const approved = await approveApp(appId)
322
+ if (!approved) {
323
+ toast.error(t('shell.permissions.approveFailed'))
324
+ return
325
+ }
326
+ const started = await launch(appId)
327
+ if (started) nav.openApp(appId)
328
+ }
329
+
330
+ /** 权限标题:复用既有本地化文案,未知权限回退原始权限词 */
331
+ function permissionTitle(key: string): string {
332
+ const i18nKey = permissionTitleKey(key)
333
+ return i18nKey ? t(i18nKey) : key
334
+ }
335
+
336
+ /**
337
+ * 能力域 → 权限词 → 持有应用(按权限视图)
338
+ *
339
+ * 聚合自同一份 apps.permissions;域顺序与词库分组一致,未归类的词进「其他」
340
+ * 底部兜底(新权限不该因为没归类就消失)。应用的授予状态在聚合时快照,
341
+ * 徽章直接读,避免在模板里反复 find。
342
+ */
343
+ const domainRows = computed<DomainRow[]>(() => {
344
+ const byKey = new Map<string, GrantApp[]>()
345
+ for (const app of apps.value) {
346
+ for (const grant of app.permissions) {
347
+ const list = byKey.get(grant.key) ?? []
348
+ list.push({
349
+ app,
350
+ state: grantStateOf(app, grant.key),
351
+ })
352
+ byKey.set(grant.key, list)
353
+ }
354
+ }
355
+
356
+ const byDomain = new Map<string, DomainRow>(
357
+ SHELL_PERMISSION_GROUPS.map((g) => [g.id, { id: g.id, titleKey: g.titleKey, items: [] }]),
358
+ )
359
+ const rest: PermissionWordRow[] = []
360
+ for (const [key, grants] of byKey) {
361
+ const group = SHELL_PERMISSION_GROUPS.find((g) => g.keys.includes(key))
362
+ const row: PermissionWordRow = {
363
+ key,
364
+ apps: grants.sort((a, b) => a.app.name.localeCompare(b.app.name, 'zh-Hans-CN')),
365
+ }
366
+ if (group) byDomain.get(group.id)?.items.push(row)
367
+ else rest.push(row)
368
+ }
369
+
370
+ const nonEmpty = [...byDomain.values()].filter((g) => g.items.length > 0)
371
+ if (rest.length > 0) {
372
+ nonEmpty.push({ id: 'other', titleKey: 'shell.permission.group.other', items: rest })
373
+ }
374
+ return nonEmpty
375
+ })
376
+ </script>
@@ -0,0 +1,240 @@
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 flex-shrink-0">
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" aria-hidden="true">
12
+ <path d="M15 6l-6 6 6 6" />
13
+ </svg>
14
+ </button>
15
+ <h1 class="flex-1 min-w-0 text-[var(--font-size-lg)] font-semibold text-[var(--mobile-text-primary)] truncate">
16
+ {{ t('shell.settings.title') }}
17
+ </h1>
18
+ </header>
19
+
20
+ <div class="flex-1 min-h-0 overflow-y-auto pb-6">
21
+ <!-- ==================== 调试环境 ==================== -->
22
+ <div class="px-4 pb-1">
23
+ <div
24
+ class="flex items-center gap-3.5 rounded-[12px] border border-[var(--mobile-group-border)] bg-[var(--mobile-bg-card)] p-4"
25
+ :style="{ boxShadow: 'var(--mobile-card-shadow)' }"
26
+ >
27
+ <ShellBrandTile :size="48" />
28
+ <div class="flex-1 min-w-0">
29
+ <b class="block text-[var(--font-size-lg)] text-[var(--mobile-text-primary)] truncate">
30
+ WasmNest Dev Shell
31
+ </b>
32
+ <div class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] truncate">
33
+ {{ t('shell.settings.devShellHint') }}
34
+ </div>
35
+ </div>
36
+ </div>
37
+ </div>
38
+
39
+ <!-- ==================== 平台项 ==================== -->
40
+ <ShellSection :title="t('shell.settings.platform')" />
41
+ <div class="px-4 pb-1">
42
+ <ShellGroupCard>
43
+ <button
44
+ v-for="entry in platformEntries"
45
+ :key="entry.id"
46
+ type="button"
47
+ 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)]"
48
+ @click="entry.onSelect()"
49
+ >
50
+ <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)' }">
51
+ <path :d="entry.icon" />
52
+ </svg>
53
+ <span class="flex-1 min-w-0 text-[var(--font-size-base)] text-[var(--mobile-text-primary)] truncate">
54
+ {{ entry.label }}
55
+ </span>
56
+ <span v-if="entry.hint" class="flex-shrink-0 text-[var(--font-size-sm)] text-[var(--mobile-text-secondary)] truncate">
57
+ {{ entry.hint }}
58
+ </span>
59
+ </button>
60
+ </ShellGroupCard>
61
+ </div>
62
+
63
+ <!-- ==================== 外观(主题三档) ==================== -->
64
+ <ShellSection :title="t('shell.settings.appearance')" :note="t('shell.settings.appearanceHint')" />
65
+ <div class="px-4 pb-1">
66
+ <ShellGroupCard>
67
+ <button
68
+ v-for="option in themeOptions"
69
+ :key="option.value"
70
+ type="button"
71
+ 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)]"
72
+ @click="setTheme(option.value)"
73
+ >
74
+ <span class="flex-1 min-w-0 text-[var(--font-size-base)] text-[var(--mobile-text-primary)]">
75
+ {{ option.label }}
76
+ </span>
77
+ <ShellChip
78
+ v-if="theme === option.value"
79
+ :label="t('shell.common.active')"
80
+ tone="accent"
81
+ />
82
+ </button>
83
+ </ShellGroupCard>
84
+ </div>
85
+
86
+ <!-- ==================== 语言 ==================== -->
87
+ <ShellSection :title="t('shell.settings.language')" />
88
+ <div class="px-4 pb-1">
89
+ <ShellGroupCard>
90
+ <button
91
+ v-for="option in localeOptions"
92
+ :key="option.value"
93
+ type="button"
94
+ 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)]"
95
+ @click="setLocale(option.value)"
96
+ >
97
+ <span class="flex-1 min-w-0 text-[var(--font-size-base)] text-[var(--mobile-text-primary)]">
98
+ {{ option.label }}
99
+ </span>
100
+ <ShellChip v-if="locale === option.value" :label="t('shell.common.active')" tone="accent" />
101
+ </button>
102
+ </ShellGroupCard>
103
+ </div>
104
+
105
+ <!-- ==================== 调试数据 ==================== -->
106
+ <!-- 替代宿主的「危险操作 · 擦除本机数据」:dev-shell 的本机数据只有 localStorage
107
+ 里的调试键(插件 storage / 最近使用 / 语言),清掉即回到首次打开的状态。 -->
108
+ <ShellSection :title="t('shell.settings.devData')" />
109
+ <div class="px-4 pb-1">
110
+ <button
111
+ type="button"
112
+ class="w-full flex items-center gap-3 px-3 py-3 text-left rounded-[12px] border transition-colors duration-200 active:opacity-80 min-h-[var(--mobile-touch-target-min)]"
113
+ :style="{
114
+ background: 'var(--mobile-error-muted)',
115
+ border: '1px solid var(--mobile-error)',
116
+ color: 'var(--mobile-error)',
117
+ }"
118
+ @click="clearDevData"
119
+ >
120
+ <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">
121
+ <path d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
122
+ </svg>
123
+ <span class="flex-1 min-w-0 text-[var(--font-size-base)] truncate">
124
+ {{ t('shell.settings.clearDevData') }}
125
+ </span>
126
+ </button>
127
+ <p class="text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)] px-1 mt-1.5">
128
+ {{ t('shell.settings.clearDevDataHint') }}
129
+ </p>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ </template>
134
+
135
+ <script setup lang="ts">
136
+ /**
137
+ * 我的 / 平台设置(宿主 ShellSettingsScreen.vue 的 dev-shell 同形实现)
138
+ * -----------------------------------------------------------------------------
139
+ * 结构与宿主一致:调试环境标识 + 平台项。差异只在「平台项」的内容——
140
+ * 宿主那一版是链路加密 / 生物凭证 / 出站授权 / 连接 / 认证(都是真机安全闸门,
141
+ * 浏览器里没有),这里换成预览环境真正能改的面:权限总览、调试对象清单、清理调试数据。
142
+ *
143
+ * 外观 / 语言两项在宿主是「跳既有设置页」,在 dev-shell 直接就地切换(工具条里也有,
144
+ * 两处同源:同一个 theme.ts / locale.ts)。
145
+ *
146
+ */
147
+ import { computed } from 'vue'
148
+ import { useI18n } from 'vue-i18n'
149
+ import { saveLocale, type DevLocale } from '../../../locale'
150
+ import { useDevTheme, type ThemeMode } from '../../../theme'
151
+ import { useShellApps } from '../../composables/useShellApps'
152
+ import { useShellNavigation } from '../../composables/useShellNavigation'
153
+ import { useToast } from '../../composables/useToast'
154
+ import ShellBrandTile from '../ShellBrandTile.vue'
155
+ import ShellChip from '../ShellChip.vue'
156
+ import ShellGroupCard from '../ShellGroupCard.vue'
157
+ import ShellSection from '../ShellSection.vue'
158
+
159
+ interface PlatformEntry {
160
+ id: string
161
+ label: string
162
+ hint?: string
163
+ icon: string
164
+ onSelect: () => void
165
+ }
166
+
167
+ const { t, locale } = useI18n()
168
+ const nav = useShellNavigation()
169
+ const toast = useToast()
170
+ const { sortedApps } = useShellApps()
171
+ const { theme, setTheme } = useDevTheme()
172
+
173
+ const platformEntries = computed<PlatformEntry[]>(() => [
174
+ {
175
+ id: 'permissions',
176
+ label: t('shell.settings.permissions'),
177
+ hint: t('shell.settings.permissionsHint'),
178
+ icon: 'M12 3l8 3v6c0 4.5-3.2 7.6-8 9-4.8-1.4-8-4.5-8-9V6l8-3z M9 12l2 2 4-4',
179
+ onSelect: () => nav.openPermissions(),
180
+ },
181
+ {
182
+ id: 'objects',
183
+ label: t('shell.settings.debugObjects'),
184
+ hint: t('shell.settings.debugObjectsHint', {
185
+ count: sortedApps.value.length,
186
+ running: sortedApps.value.filter((a) => a.state === 'running').length,
187
+ }),
188
+ icon: 'M9.5 3a6.5 6.5 0 100 13 6.5 6.5 0 000-13z M14.5 12.5l6 6',
189
+ onSelect: () => nav.switchTab('apps'),
190
+ },
191
+ ])
192
+
193
+ const themeOptions = computed(() => [
194
+ { value: 'dark' as ThemeMode, label: t('devshell.theme.dark') },
195
+ { value: 'light' as ThemeMode, label: t('devshell.theme.light') },
196
+ { value: 'system' as ThemeMode, label: t('devshell.theme.system') },
197
+ ])
198
+
199
+ // 语言名用自身文字展示,无需翻译
200
+ const localeOptions: { value: DevLocale; label: string }[] = [
201
+ { value: 'zh-CN', label: '简体中文' },
202
+ { value: 'en', label: 'English' },
203
+ ]
204
+
205
+ function setLocale(next: DevLocale): void {
206
+ locale.value = next
207
+ saveLocale(next)
208
+ }
209
+
210
+ /**
211
+ * 清理调试数据
212
+ *
213
+ * 二次确认走平台对话框(不可撤销,误触代价是重新跑一遍全部 activate)。
214
+ * 只删 dev-shell 自己写下的键(`wasmnest-dev-shell:*` / `wasmnest.devshell.*`),
215
+ * 不碰同域下其他应用的数据。
216
+ */
217
+ async function clearDevData(): Promise<void> {
218
+ const { dialogService } = await import('../../../mock/dialog-service')
219
+ const confirmed = await dialogService.showConfirm({
220
+ title: t('shell.settings.clearDevData'),
221
+ message: t('shell.settings.clearDevDataHint'),
222
+ variant: 'warning',
223
+ confirmText: t('shell.settings.clearDevData'),
224
+ cancelText: t('shell.common.cancel'),
225
+ })
226
+ if (!confirmed) return
227
+
228
+ const removable: string[] = []
229
+ for (let i = 0; i < localStorage.length; i += 1) {
230
+ const key = localStorage.key(i)
231
+ if (key && (key.startsWith('wasmnest-dev-shell:') || key.startsWith('wasmnest.devshell.'))) {
232
+ removable.push(key)
233
+ }
234
+ }
235
+ for (const key of removable) localStorage.removeItem(key)
236
+ toast.success(t('shell.settings.clearDevDataDone', { count: removable.length }))
237
+ // 数据已清:整页重载让插件从干净状态重新 activate(不重载就会留着旧内存态)
238
+ window.location.reload()
239
+ }
240
+ </script>