@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.
- package/README.md +439 -2
- package/README_en.md +415 -0
- package/bin/build.js +271 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +327 -0
- package/bin/package.js +151 -0
- package/bin/scaffold.js +299 -0
- package/dev-shell/README.md +151 -0
- package/dev-shell/index.html +27 -0
- package/dev-shell/package.json +27 -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/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
- package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
- package/dev-shell/src/components/DevToolbar.vue +100 -0
- package/dev-shell/src/components/DialogHost.vue +119 -0
- package/dev-shell/src/components/LogPanel.vue +80 -0
- package/dev-shell/src/i18n.ts +22 -0
- package/dev-shell/src/loader.ts +239 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales/en-shell.ts +332 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +331 -0
- package/dev-shell/src/main.ts +58 -0
- package/dev-shell/src/mock/dialog-service.ts +58 -0
- package/dev-shell/src/mock/file-transfer.ts +390 -0
- package/dev-shell/src/mock/mobile-api.ts +369 -0
- package/dev-shell/src/mock/preset-tasks.ts +186 -0
- package/dev-shell/src/mock/session.ts +121 -0
- package/dev-shell/src/mock-context.ts +374 -0
- package/dev-shell/src/registry.ts +151 -0
- package/dev-shell/src/shared-runtime.ts +44 -0
- package/dev-shell/src/shell/ShellView.vue +52 -0
- package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
- package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
- package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
- package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
- package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
- package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
- package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
- package/dev-shell/src/shell/components/ShellChip.vue +49 -0
- package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
- package/dev-shell/src/shell/components/ShellHost.vue +75 -0
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
- package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
- package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
- package/dev-shell/src/shell/components/ShellSection.vue +27 -0
- package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
- package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
- package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
- package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
- package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
- package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
- package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
- package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
- package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
- package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
- package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
- package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
- package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
- package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
- package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
- package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
- package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/composables/useToast.ts +33 -0
- package/dev-shell/src/shell/index.ts +88 -0
- package/dev-shell/src/shell/logger.ts +45 -0
- package/dev-shell/src/shell/permissions.ts +145 -0
- package/dev-shell/src/shell/registry.ts +220 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +1155 -0
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +152 -0
- package/dev-shell/src/shell/utils.ts +54 -0
- package/dev-shell/src/styles/main.css +153 -0
- package/dev-shell/src/styles/mobile.css +981 -0
- package/dev-shell/src/styles/wallpaper.css +130 -0
- package/dev-shell/src/theme.ts +71 -0
- package/dev-shell/src/vite-env.d.ts +20 -0
- package/dev-shell/tailwind.config.js +101 -0
- package/dev-shell/tsconfig.json +16 -0
- package/dev-shell/vite.config.ts +130 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +229 -0
- package/dist/types.d.ts +738 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +95 -0
- package/package.json +88 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +96 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +822 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/PluginGlobalDialog.vue +388 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/ui/Select.d.ts +37 -0
- package/src/ui/Select.vue +307 -0
- package/src/ui/plugin-global-dialog.d.ts +11 -0
- package/src/ui/useSwipeTabs.d.ts +20 -0
- package/src/ui/useSwipeTabs.ts +53 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +132 -0
- package/template/.gitignore +4 -0
- package/template/README.md +46 -0
- package/template/package.json +23 -0
- package/template/plugin.json +13 -0
- package/template/rust/Cargo.toml +19 -0
- package/template/rust/src/lib.rs +33 -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
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 首页快捷卡片轮播
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 轨道本身是原生 scroll-snap(一张一拍屏),本组合式只负责「自动往前走」:
|
|
5
|
+
* - 间隔 5s 推进一张,到末尾回到第一张;
|
|
6
|
+
* - 用户触摸 / 滚轮 / 键盘聚焦时停表,停手 8s 后恢复(不改变用户显式暂停);
|
|
7
|
+
* - 系统「减少动效」开启时默认不自动播放,且不渲染暂停 / 播放控件
|
|
8
|
+
* (否则就是一个点了没反应的按钮);
|
|
9
|
+
* - 页面不可见(切后台 / 打开其它应用)时停表。
|
|
10
|
+
*
|
|
11
|
+
* 动效判据:ui-ux-pro-max `--domain ux / Auto-Rotating Content Controls`——
|
|
12
|
+
* 自动轮播必须给用户暂停控制,并在 reduced motion 下停走;滚动定位在
|
|
13
|
+
* reduced motion 下降级为瞬时跳转。
|
|
14
|
+
*/
|
|
15
|
+
import { onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
|
|
16
|
+
|
|
17
|
+
/** 自动轮播步进间隔 */
|
|
18
|
+
export const SLOT_AUTOPLAY_INTERVAL_MS = 5000
|
|
19
|
+
/** 用户操作后恢复自动轮播的空闲等待 */
|
|
20
|
+
export const SLOT_AUTOPLAY_RESUME_MS = 8000
|
|
21
|
+
|
|
22
|
+
/** 系统是否要求减少动效(真机 / dev-shell 统一口径;取不到按不需要处理) */
|
|
23
|
+
export function prefersReducedMotion(): boolean {
|
|
24
|
+
return (
|
|
25
|
+
typeof window !== 'undefined' &&
|
|
26
|
+
typeof window.matchMedia === 'function' &&
|
|
27
|
+
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 首页快捷卡片轮播句柄 */
|
|
32
|
+
export interface SlotCarousel {
|
|
33
|
+
/** 当前定格卡序号(0 起;用户滑动时随滚动同步) */
|
|
34
|
+
activeIndex: Ref<number>
|
|
35
|
+
/** 用户是否开启自动轮播(暂停按钮状态;临时触摸暂停不改变它) */
|
|
36
|
+
playing: Ref<boolean>
|
|
37
|
+
/** 系统要求减少动效时为 true,此时不自动播放也不提供播放控件 */
|
|
38
|
+
reducedMotion: Ref<boolean>
|
|
39
|
+
/** 暂停 / 恢复自动轮播 */
|
|
40
|
+
toggle(): void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param track 横向轨道元素(子元素 = 卡片 item,顺序与卡片一致)
|
|
45
|
+
* @param count 当前卡片数(清单异步到达时自动起表 / 停表)
|
|
46
|
+
*/
|
|
47
|
+
export function useSlotCarousel(
|
|
48
|
+
track: Ref<HTMLElement | null>,
|
|
49
|
+
count: Ref<number>,
|
|
50
|
+
): SlotCarousel {
|
|
51
|
+
const activeIndex = ref(0)
|
|
52
|
+
const reducedMotion = ref(prefersReducedMotion())
|
|
53
|
+
const playing = ref(!reducedMotion.value)
|
|
54
|
+
/** 触摸 / 聚焦期间的临时停表(不写回 playing) */
|
|
55
|
+
let holding = false
|
|
56
|
+
|
|
57
|
+
let timer: ReturnType<typeof setInterval> | null = null
|
|
58
|
+
let resumeTimer: ReturnType<typeof setTimeout> | null = null
|
|
59
|
+
let scrollFrame = 0
|
|
60
|
+
let media: MediaQueryList | null = null
|
|
61
|
+
|
|
62
|
+
function total(): number {
|
|
63
|
+
return Math.max(0, count.value)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function stopTimer(): void {
|
|
67
|
+
if (timer !== null) {
|
|
68
|
+
clearInterval(timer)
|
|
69
|
+
timer = null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function canPlay(): boolean {
|
|
74
|
+
return (
|
|
75
|
+
playing.value &&
|
|
76
|
+
!holding &&
|
|
77
|
+
!reducedMotion.value &&
|
|
78
|
+
total() > 1 &&
|
|
79
|
+
!(typeof document !== 'undefined' && document.hidden)
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function startTimer(): void {
|
|
84
|
+
stopTimer()
|
|
85
|
+
if (canPlay()) timer = setInterval(advance, SLOT_AUTOPLAY_INTERVAL_MS)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function cardElement(index: number): HTMLElement | null {
|
|
89
|
+
const el = track.value
|
|
90
|
+
const child = el?.children[index]
|
|
91
|
+
return child instanceof HTMLElement ? child : null
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function paddingStart(el: HTMLElement): number {
|
|
95
|
+
const value = parseFloat(getComputedStyle(el).paddingInlineStart)
|
|
96
|
+
return Number.isFinite(value) ? value : 0
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 定位到某张卡:对齐 scroll-snap 的 start 锚点(扣除轨道起始内边距) */
|
|
100
|
+
function goTo(index: number): void {
|
|
101
|
+
const limit = total()
|
|
102
|
+
if (limit === 0) return
|
|
103
|
+
const next = Math.min(Math.max(index, 0), limit - 1)
|
|
104
|
+
activeIndex.value = next
|
|
105
|
+
|
|
106
|
+
const el = track.value
|
|
107
|
+
const item = cardElement(next)
|
|
108
|
+
if (!el || !item) return
|
|
109
|
+
const left = Math.max(
|
|
110
|
+
0,
|
|
111
|
+
item.getBoundingClientRect().left - el.getBoundingClientRect().left + el.scrollLeft - paddingStart(el),
|
|
112
|
+
)
|
|
113
|
+
const behavior: ScrollBehavior = reducedMotion.value ? 'auto' : 'smooth'
|
|
114
|
+
if (typeof el.scrollTo === 'function') el.scrollTo({ left, behavior })
|
|
115
|
+
else el.scrollLeft = left
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function advance(): void {
|
|
119
|
+
const limit = total()
|
|
120
|
+
if (limit <= 1) return
|
|
121
|
+
goTo((activeIndex.value + 1) % limit)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 用户滑动后把序号对齐到最近一张(自动轮播从可见卡继续) */
|
|
125
|
+
function syncActiveIndex(): void {
|
|
126
|
+
const el = track.value
|
|
127
|
+
if (!el || el.children.length === 0) return
|
|
128
|
+
const base = el.getBoundingClientRect().left + paddingStart(el)
|
|
129
|
+
let nearest = 0
|
|
130
|
+
let best = Number.POSITIVE_INFINITY
|
|
131
|
+
for (let i = 0; i < el.children.length; i += 1) {
|
|
132
|
+
const child = el.children[i]
|
|
133
|
+
if (!(child instanceof HTMLElement)) continue
|
|
134
|
+
const distance = Math.abs(child.getBoundingClientRect().left - base)
|
|
135
|
+
if (distance < best) {
|
|
136
|
+
best = distance
|
|
137
|
+
nearest = i
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (nearest !== activeIndex.value) activeIndex.value = nearest
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function onScroll(): void {
|
|
144
|
+
if (scrollFrame) return
|
|
145
|
+
scrollFrame = requestAnimationFrame(() => {
|
|
146
|
+
scrollFrame = 0
|
|
147
|
+
syncActiveIndex()
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 用户开始操作:临时停表,停手一段时间后自动恢复 */
|
|
152
|
+
function holdTemporarily(): void {
|
|
153
|
+
holding = true
|
|
154
|
+
stopTimer()
|
|
155
|
+
if (resumeTimer !== null) clearTimeout(resumeTimer)
|
|
156
|
+
resumeTimer = setTimeout(() => {
|
|
157
|
+
resumeTimer = null
|
|
158
|
+
holding = false
|
|
159
|
+
startTimer()
|
|
160
|
+
}, SLOT_AUTOPLAY_RESUME_MS)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 焦点离开轨道:立刻恢复(键盘用户不该等空闲计时) */
|
|
164
|
+
function releaseHold(): void {
|
|
165
|
+
if (resumeTimer !== null) {
|
|
166
|
+
clearTimeout(resumeTimer)
|
|
167
|
+
resumeTimer = null
|
|
168
|
+
}
|
|
169
|
+
holding = false
|
|
170
|
+
startTimer()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function toggle(): void {
|
|
174
|
+
if (reducedMotion.value) return
|
|
175
|
+
playing.value = !playing.value
|
|
176
|
+
if (playing.value) startTimer()
|
|
177
|
+
else stopTimer()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function onVisibilityChange(): void {
|
|
181
|
+
if (document.hidden) stopTimer()
|
|
182
|
+
else startTimer()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function onMotionPreferenceChange(event: MediaQueryListEvent): void {
|
|
186
|
+
reducedMotion.value = event.matches
|
|
187
|
+
if (event.matches) stopTimer()
|
|
188
|
+
else startTimer()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
watch(count, () => {
|
|
192
|
+
const last = Math.max(0, total() - 1)
|
|
193
|
+
if (activeIndex.value > last) activeIndex.value = last
|
|
194
|
+
startTimer()
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
onMounted(() => {
|
|
198
|
+
const el = track.value
|
|
199
|
+
el?.addEventListener('pointerdown', holdTemporarily, { passive: true })
|
|
200
|
+
el?.addEventListener('wheel', holdTemporarily, { passive: true })
|
|
201
|
+
el?.addEventListener('focusin', holdTemporarily)
|
|
202
|
+
el?.addEventListener('focusout', releaseHold)
|
|
203
|
+
el?.addEventListener('scroll', onScroll, { passive: true })
|
|
204
|
+
if (typeof document !== 'undefined') {
|
|
205
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
206
|
+
}
|
|
207
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
208
|
+
media = window.matchMedia('(prefers-reduced-motion: reduce)')
|
|
209
|
+
media.addEventListener?.('change', onMotionPreferenceChange)
|
|
210
|
+
}
|
|
211
|
+
startTimer()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
onBeforeUnmount(() => {
|
|
215
|
+
stopTimer()
|
|
216
|
+
if (resumeTimer !== null) {
|
|
217
|
+
clearTimeout(resumeTimer)
|
|
218
|
+
resumeTimer = null
|
|
219
|
+
}
|
|
220
|
+
if (scrollFrame) {
|
|
221
|
+
cancelAnimationFrame(scrollFrame)
|
|
222
|
+
scrollFrame = 0
|
|
223
|
+
}
|
|
224
|
+
const el = track.value
|
|
225
|
+
el?.removeEventListener('pointerdown', holdTemporarily)
|
|
226
|
+
el?.removeEventListener('wheel', holdTemporarily)
|
|
227
|
+
el?.removeEventListener('focusin', holdTemporarily)
|
|
228
|
+
el?.removeEventListener('focusout', releaseHold)
|
|
229
|
+
el?.removeEventListener('scroll', onScroll)
|
|
230
|
+
if (typeof document !== 'undefined') {
|
|
231
|
+
document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
232
|
+
}
|
|
233
|
+
media?.removeEventListener?.('change', onMotionPreferenceChange)
|
|
234
|
+
media = null
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
return { activeIndex, playing, reducedMotion, toggle }
|
|
238
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 壳内 Toast 反馈(与宿主 shell/composables/useToast.ts 同款 API)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 宿主用 vue-sonner 渲染 toast,dev-shell 没有该依赖,且已有自己的对话框宿主
|
|
5
|
+
* (`mock/dialog-service.ts` + `components/DialogHost.vue`)在渲染同款队列与 toast。
|
|
6
|
+
* 因此这里只做一层薄适配:壳内组件用宿主同款 API 调用,落点换成 dev-shell 的
|
|
7
|
+
* DialogHost——不为预览环境引入第二套 toast 实现。
|
|
8
|
+
*
|
|
9
|
+
* API 形状(show / success / error / warning / info / dismiss)保持一致,便于
|
|
10
|
+
* 「同款代码在两边跑」。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { dialogService } from '../../mock/dialog-service'
|
|
14
|
+
|
|
15
|
+
/** Toast 选项(与宿主 useToast 的 ToastOptions 同形) */
|
|
16
|
+
export interface ToastOptions {
|
|
17
|
+
message: string
|
|
18
|
+
type?: 'success' | 'error' | 'warning' | 'info'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useToast() {
|
|
22
|
+
function show(options: ToastOptions) {
|
|
23
|
+
dialogService.showToast(options.message, options.type ?? 'info')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
show,
|
|
28
|
+
success: (message: string) => show({ message, type: 'success' }),
|
|
29
|
+
error: (message: string) => show({ message, type: 'error' }),
|
|
30
|
+
warning: (message: string) => show({ message, type: 'warning' }),
|
|
31
|
+
info: (message: string) => show({ message, type: 'info' }),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 宿主壳公共入口
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 对外暴露三类东西:契约类型、注册表、以及给内置应用 / 调试代码用的注册 API。
|
|
5
|
+
*
|
|
6
|
+
* 内置应用接入只需这里的注册 API:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { registerSurface, registerSlot } from './shell'
|
|
10
|
+
*
|
|
11
|
+
* registerSurface('dev.my-app', { component: MyAppView }) // 运行面
|
|
12
|
+
* registerSlot('dev.my-app', { id: 'status', component: MyCard }) // 首页快捷卡片
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* 被调试插件走的是 `context.ui.*`(mock-context 内的同款实现),appId 由插件 id 代填。
|
|
16
|
+
*
|
|
17
|
+
* 返回值都是 Disposable:应用停用时 dispose 即摘除,不留残桩。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export type {
|
|
21
|
+
Disposable,
|
|
22
|
+
ShellApp,
|
|
23
|
+
ShellAppState,
|
|
24
|
+
ShellAppContributions,
|
|
25
|
+
ShellAppSource,
|
|
26
|
+
ShellCapsuleItem,
|
|
27
|
+
ShellPermissionGrant,
|
|
28
|
+
ShellSlotContribution,
|
|
29
|
+
ShellSurfaceContribution,
|
|
30
|
+
} from './types'
|
|
31
|
+
|
|
32
|
+
export { getShellRegistry, type ShellRegistryClass } from './registry'
|
|
33
|
+
export {
|
|
34
|
+
SHELL_PERMISSION_GROUPS,
|
|
35
|
+
isLockedPermission,
|
|
36
|
+
permissionTitleKey,
|
|
37
|
+
groupPermissions,
|
|
38
|
+
} from './permissions'
|
|
39
|
+
export { formatBytes, initialOf, iconKindOf, type IconKind } from './utils'
|
|
40
|
+
export { logger } from './logger'
|
|
41
|
+
|
|
42
|
+
export { useShellApps, type ShellApps, type ShellStats } from './composables/useShellApps'
|
|
43
|
+
export {
|
|
44
|
+
useShellNavigation,
|
|
45
|
+
resetShellNavigation,
|
|
46
|
+
type ShellNavigation,
|
|
47
|
+
type ShellScreenId,
|
|
48
|
+
type ShellScreenEntry,
|
|
49
|
+
type ShellNavDirection,
|
|
50
|
+
} from './composables/useShellNavigation'
|
|
51
|
+
export {
|
|
52
|
+
useShellOverlays,
|
|
53
|
+
type ShellOverlays,
|
|
54
|
+
type ShellPermissionRequest,
|
|
55
|
+
} from './composables/useShellOverlays'
|
|
56
|
+
export { useShellRecent, pushRecent, clearRecent } from './composables/useShellRecent'
|
|
57
|
+
export { useShellOpen, openShellApp } from './composables/useShellOpen'
|
|
58
|
+
export { useToast, type ToastOptions } from './composables/useToast'
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
createDevAppSource,
|
|
62
|
+
DEV_APP_SOURCE_ID,
|
|
63
|
+
toShellApp,
|
|
64
|
+
type DevAppSourceDeps,
|
|
65
|
+
} from './adapters/devAppSource'
|
|
66
|
+
|
|
67
|
+
import type {
|
|
68
|
+
Disposable,
|
|
69
|
+
ShellCapsuleItem,
|
|
70
|
+
ShellSlotContribution,
|
|
71
|
+
ShellSurfaceContribution,
|
|
72
|
+
} from './types'
|
|
73
|
+
import { getShellRegistry } from './registry'
|
|
74
|
+
|
|
75
|
+
/** 注册应用运行面 */
|
|
76
|
+
export function registerSurface(appId: string, surface: ShellSurfaceContribution): Disposable {
|
|
77
|
+
return getShellRegistry().registerSurface(appId, surface)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 注册首页快捷卡片 */
|
|
81
|
+
export function registerSlot(appId: string, slot: ShellSlotContribution): Disposable {
|
|
82
|
+
return getShellRegistry().registerSlot(appId, slot)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 注册胶囊菜单附加项 */
|
|
86
|
+
export function registerCapsuleItem(appId: string, item: ShellCapsuleItem): Disposable {
|
|
87
|
+
return getShellRegistry().registerCapsuleItem(appId, item)
|
|
88
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 壳层日志桥
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* dev-shell 的壳复用宿主的 `src/utils/frontendLogger` 同款职责(带上下文的统一日志),
|
|
5
|
+
* 但落到 dev-shell 自己的日志通道——即 `registry.ts` 的 `pushLog`,它同时写
|
|
6
|
+
* 浏览器 console 与右下角日志面板。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不直接用 console:壳内出问题时,用户的第一现场是那个日志面板;
|
|
9
|
+
* 只进 console 等于把最需要被看见的错误藏起来。
|
|
10
|
+
*
|
|
11
|
+
* 与宿主 frontendLogger 的差异:宿主的实参是 (message, error?),这里同样接受可选
|
|
12
|
+
* 错误对象并拼进 message(日志面板只显示一条 message 字段)——这样从宿主移植过来的
|
|
13
|
+
* 两参调用无需逐个改写,且错误细节不丢。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { pushLog } from '../registry'
|
|
17
|
+
|
|
18
|
+
/** 壳层日志级别(与 DevLogEntry 对齐) */
|
|
19
|
+
type Level = 'debug' | 'info' | 'warn' | 'error'
|
|
20
|
+
|
|
21
|
+
/** 稳定低熵的错误折叠:Error 取 message,其他取 String,避免大对象污染日志 */
|
|
22
|
+
function foldError(error: unknown): string {
|
|
23
|
+
if (error === undefined) return ''
|
|
24
|
+
if (error instanceof Error) return error.message
|
|
25
|
+
return String(error)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 壳层 logger
|
|
30
|
+
*
|
|
31
|
+
* `scope` 是壳自身的固定标识(`Shell`),插件侧日志仍走 `context.logger`,
|
|
32
|
+
* 两条通道在日志面板里可区分。
|
|
33
|
+
*/
|
|
34
|
+
export const logger = {
|
|
35
|
+
debug: (message: string, error?: unknown) =>
|
|
36
|
+
pushLog('debug', 'Shell', error === undefined ? message : `${message} :: ${foldError(error)}`),
|
|
37
|
+
info: (message: string, error?: unknown) =>
|
|
38
|
+
pushLog('info', 'Shell', error === undefined ? message : `${message} :: ${foldError(error)}`),
|
|
39
|
+
warn: (message: string, error?: unknown) =>
|
|
40
|
+
pushLog('warn', 'Shell', error === undefined ? message : `${message} :: ${foldError(error)}`),
|
|
41
|
+
error: (message: string, error?: unknown) =>
|
|
42
|
+
pushLog('error', 'Shell', error === undefined ? message : `${message} :: ${foldError(error)}`),
|
|
43
|
+
} satisfies Record<Level, (message: string, error?: unknown) => void>
|
|
44
|
+
|
|
45
|
+
export type { Level }
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 权限展示元数据(与宿主 shell/permissions.ts 逐字同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 权限词汇显示层两件事:
|
|
5
|
+
* 1. 把权限词映射成 i18n 文案 key(dev-shell 自有 `shell.permission.*` 命名空间)
|
|
6
|
+
* 2. 按能力域分组,让「应用详情 → 权限」是可读清单而不是一串冒号字符串
|
|
7
|
+
*
|
|
8
|
+
* 授权裁决在插件侧 / 宿主后端执行,前端开关只是 UX(docs/security.md §1)——因此这里
|
|
9
|
+
* 的分组与文案不参与任何安全判定。
|
|
10
|
+
*
|
|
11
|
+
* 同构纪律:词表与分组与宿主 `wasmnest-mobile/src/shell/permissions.ts` 保持一致;
|
|
12
|
+
* 新增权限词时两端要同步补词表与双语 locale(缺一条的代价是「权限总览」页直接
|
|
13
|
+
* 裸显英文 code)。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ShellPermissionGrant } from './types'
|
|
17
|
+
|
|
18
|
+
/** 权限分组定义(展示顺序即数组顺序) */
|
|
19
|
+
export interface ShellPermissionGroup {
|
|
20
|
+
id: string
|
|
21
|
+
/** 分组标题的 i18n key */
|
|
22
|
+
titleKey: string
|
|
23
|
+
keys: string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 权限词 → 本地化文案 key 的后缀(前缀统一 shell.permission.perm.;
|
|
27
|
+
* terminal:input 已随票 15 阶段 B 整面退役,不在展示词表) */
|
|
28
|
+
const PERMISSION_I18N_KEY: Record<string, string> = {
|
|
29
|
+
storage: 'storage',
|
|
30
|
+
'terminal:output': 'terminalOutput',
|
|
31
|
+
'session:read': 'sessionRead',
|
|
32
|
+
'session:write': 'sessionWrite',
|
|
33
|
+
'ui:toolbox': 'uiToolbox',
|
|
34
|
+
'ui:navtab': 'uiNavtab',
|
|
35
|
+
'ui:settings': 'uiSettings',
|
|
36
|
+
'ui:input': 'uiInput',
|
|
37
|
+
'ui:route': 'uiRoute',
|
|
38
|
+
'ui:dialog': 'uiDialog',
|
|
39
|
+
'ui:back': 'uiBack',
|
|
40
|
+
'network:http': 'networkHttp',
|
|
41
|
+
'fs:read': 'fsRead',
|
|
42
|
+
'fs:write': 'fsWrite',
|
|
43
|
+
'fs:pick': 'fsPick',
|
|
44
|
+
fileservice: 'fileservice',
|
|
45
|
+
'system:open': 'systemOpen',
|
|
46
|
+
bus: 'bus',
|
|
47
|
+
broadcast: 'broadcast',
|
|
48
|
+
transfer: 'transfer',
|
|
49
|
+
mdns: 'mdns',
|
|
50
|
+
peer: 'peer',
|
|
51
|
+
'ws:client': 'wsClient',
|
|
52
|
+
auth: 'auth',
|
|
53
|
+
notify: 'notify',
|
|
54
|
+
'metrics:read': 'metricsRead',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 能力域分组:与移动端权限词汇的能力域划分一致 */
|
|
58
|
+
export const SHELL_PERMISSION_GROUPS: ShellPermissionGroup[] = [
|
|
59
|
+
{
|
|
60
|
+
id: 'terminal',
|
|
61
|
+
titleKey: 'shell.permission.group.terminal',
|
|
62
|
+
keys: ['terminal:output', 'session:read', 'session:write'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'data',
|
|
66
|
+
titleKey: 'shell.permission.group.data',
|
|
67
|
+
keys: ['fs:read', 'fs:write', 'fs:pick', 'fileservice', 'transfer', 'network:http'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'device',
|
|
71
|
+
titleKey: 'shell.permission.group.device',
|
|
72
|
+
keys: ['peer', 'mdns', 'ws:client', 'auth', 'notify'],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'system',
|
|
76
|
+
titleKey: 'shell.permission.group.system',
|
|
77
|
+
keys: ['metrics:read'],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'interface',
|
|
81
|
+
titleKey: 'shell.permission.group.interface',
|
|
82
|
+
keys: [
|
|
83
|
+
'ui:toolbox',
|
|
84
|
+
'ui:navtab',
|
|
85
|
+
'ui:settings',
|
|
86
|
+
'ui:input',
|
|
87
|
+
'ui:route',
|
|
88
|
+
'ui:dialog',
|
|
89
|
+
'ui:back',
|
|
90
|
+
'bus',
|
|
91
|
+
'broadcast',
|
|
92
|
+
'system:open',
|
|
93
|
+
'storage',
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 默认授予且不可关闭的权限。
|
|
100
|
+
* storage 是插件底座能力(私有库 / KV),关掉等于让应用无法工作,因此不给开关。
|
|
101
|
+
*/
|
|
102
|
+
export const SHELL_LOCKED_PERMISSIONS: ReadonlySet<string> = new Set(['storage'])
|
|
103
|
+
|
|
104
|
+
/** 权限标题的 i18n key(未知权限返回 undefined,由调用方回退原始权限词) */
|
|
105
|
+
export function permissionTitleKey(key: string): string | undefined {
|
|
106
|
+
const suffix = PERMISSION_I18N_KEY[key]
|
|
107
|
+
return suffix ? `shell.permission.perm.${suffix}.title` : undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 权限说明的 i18n key(未知权限返回 undefined) */
|
|
111
|
+
export function permissionDescKey(key: string): string | undefined {
|
|
112
|
+
const suffix = PERMISSION_I18N_KEY[key]
|
|
113
|
+
return suffix ? `shell.permission.perm.${suffix}.desc` : undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 权限是否默认授予且不可关闭 */
|
|
117
|
+
export function isLockedPermission(key: string): boolean {
|
|
118
|
+
return SHELL_LOCKED_PERMISSIONS.has(key)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 按能力域分组权限授予项
|
|
123
|
+
*
|
|
124
|
+
* 分组外的权限(新增词表尚未归类)归入末尾的「其他」组,保证新权限不会因
|
|
125
|
+
* 未归类而从 UI 上消失——消失比归类难看更危险。
|
|
126
|
+
*/
|
|
127
|
+
export function groupPermissions(
|
|
128
|
+
grants: ShellPermissionGrant[],
|
|
129
|
+
fallbackTitleKey: string,
|
|
130
|
+
): Array<ShellPermissionGroup & { items: ShellPermissionGrant[] }> {
|
|
131
|
+
const grouped = SHELL_PERMISSION_GROUPS.map((g) => ({ ...g, items: [] as ShellPermissionGrant[] }))
|
|
132
|
+
const rest: ShellPermissionGrant[] = []
|
|
133
|
+
|
|
134
|
+
for (const grant of grants) {
|
|
135
|
+
const target = grouped.find((g) => g.keys.includes(grant.key))
|
|
136
|
+
if (target) target.items.push(grant)
|
|
137
|
+
else rest.push(grant)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const nonEmpty = grouped.filter((g) => g.items.length > 0)
|
|
141
|
+
if (rest.length > 0) {
|
|
142
|
+
nonEmpty.push({ id: 'other', titleKey: fallbackTitleKey, keys: [], items: rest })
|
|
143
|
+
}
|
|
144
|
+
return nonEmpty
|
|
145
|
+
}
|