@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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 宿主壳屏幕栈导航(与宿主 shell/composables/useShellNavigation.ts 同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 为什么壳内不用 vue-router 子路由:
|
|
5
|
+
* 壳是一层「应用运行平台」,屏幕栈要支持三件路由表不擅长的事——
|
|
6
|
+
* ① 应用运行面覆盖在栈上、退出即回落到上一个屏幕(不是 URL 前进后退语义);
|
|
7
|
+
* ② 多任务页是临时浮层,进出都不该留下历史;
|
|
8
|
+
* ③ 屏幕栈要能整体重置(底部 Tab 切换 = 回到该 Tab 的根,而不是 push)。
|
|
9
|
+
*
|
|
10
|
+
* 插件动态路由(registerRoute / openPage)是另一层:宿主用 vue-router 承载整页
|
|
11
|
+
* 跳转,dev-shell 同款(见 main.ts 的 dynamicPluginRoute),不在本栈内。
|
|
12
|
+
*
|
|
13
|
+
* 状态是模块级单例:壳同时只有一份导航栈。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { computed, ref, type ComputedRef, type Ref } from 'vue'
|
|
17
|
+
|
|
18
|
+
/** 壳内屏幕标识(与宿主同集合) */
|
|
19
|
+
export type ShellScreenId =
|
|
20
|
+
/** 平台首页(快捷卡片 + 应用宫格 + 最近使用) */
|
|
21
|
+
| 'home'
|
|
22
|
+
/** 应用管理 */
|
|
23
|
+
| 'apps'
|
|
24
|
+
/** 应用详情与权限 */
|
|
25
|
+
| 'app-detail'
|
|
26
|
+
/** 应用运行面 */
|
|
27
|
+
| 'app-run'
|
|
28
|
+
/** 多任务(运行中应用) */
|
|
29
|
+
| 'switcher'
|
|
30
|
+
/** 权限总览(按权限看应用) */
|
|
31
|
+
| 'permissions'
|
|
32
|
+
/** 我的 / 平台设置 */
|
|
33
|
+
| 'settings'
|
|
34
|
+
|
|
35
|
+
/** 栈中的一屏 */
|
|
36
|
+
export interface ShellScreenEntry {
|
|
37
|
+
id: ShellScreenId
|
|
38
|
+
/** 屏幕参数(目前仅 appId;后续扩展按契约新增字段即可) */
|
|
39
|
+
params: Record<string, string>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 屏幕切换方向(驱动横向滑动过渡) */
|
|
43
|
+
export type ShellNavDirection = 'forward' | 'backward'
|
|
44
|
+
|
|
45
|
+
const stack: Ref<ShellScreenEntry[]> = ref<ShellScreenEntry[]>([{ id: 'home', params: {} }])
|
|
46
|
+
const direction: Ref<ShellNavDirection> = ref('forward')
|
|
47
|
+
|
|
48
|
+
/** 当前屏 */
|
|
49
|
+
const current: ComputedRef<ShellScreenEntry> = computed(
|
|
50
|
+
() => stack.value[stack.value.length - 1] ?? { id: 'home', params: {} },
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
/** 当前屏参数 */
|
|
54
|
+
const params: ComputedRef<Record<string, string>> = computed(() => current.value.params)
|
|
55
|
+
|
|
56
|
+
/** 是否可回退(栈深度 > 1) */
|
|
57
|
+
const canBack: ComputedRef<boolean> = computed(() => stack.value.length > 1)
|
|
58
|
+
|
|
59
|
+
/** 参数是否一致(避免同一应用重复入栈) */
|
|
60
|
+
function sameParams(a: Record<string, string>, b: Record<string, string>): boolean {
|
|
61
|
+
const ka = Object.keys(a)
|
|
62
|
+
const kb = Object.keys(b)
|
|
63
|
+
if (ka.length !== kb.length) return false
|
|
64
|
+
return ka.every((k) => a[k] === b[k])
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 压入一屏
|
|
69
|
+
*
|
|
70
|
+
* 若该屏已在栈中且参数一致,则回退到该层(多次点同一入口不会堆出重复栈)。
|
|
71
|
+
*/
|
|
72
|
+
function navigate(id: ShellScreenId, nextParams: Record<string, string> = {}): void {
|
|
73
|
+
const top = stack.value[stack.value.length - 1]
|
|
74
|
+
if (top && top.id === id && sameParams(top.params, nextParams)) return
|
|
75
|
+
|
|
76
|
+
const index = stack.value.findIndex((s) => s.id === id && sameParams(s.params, nextParams))
|
|
77
|
+
if (index >= 0) {
|
|
78
|
+
direction.value = 'backward'
|
|
79
|
+
stack.value = stack.value.slice(0, index + 1)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
direction.value = 'forward'
|
|
84
|
+
stack.value = [...stack.value, { id, params: nextParams }]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 回退一屏;已在根时无操作 */
|
|
88
|
+
function back(): void {
|
|
89
|
+
if (stack.value.length <= 1) return
|
|
90
|
+
direction.value = 'backward'
|
|
91
|
+
stack.value = stack.value.slice(0, -1)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 回到某个 Tab 的根屏(底部导航语义:不叠加历史)
|
|
96
|
+
*
|
|
97
|
+
* 首页是平台根,始终重置为单屏栈;其余 Tab 同理,避免 Tab 之间来回切出深栈。
|
|
98
|
+
*/
|
|
99
|
+
function switchTab(id: ShellScreenId): void {
|
|
100
|
+
direction.value = 'forward'
|
|
101
|
+
stack.value = [{ id, params: {} }]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 回到平台首页(等价于退出所有应用与浮层) */
|
|
105
|
+
function goHome(): void {
|
|
106
|
+
switchTab('home')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 摘掉某应用的运行面(应用已被停用 / 卸载时用)
|
|
111
|
+
*
|
|
112
|
+
* 运行面由应用自己注册(`registerSurface`),应用一停用该注册即随前端模块的
|
|
113
|
+
* Disposable 一起被回收——运行屏若还留在栈里,用户「退出」之后看到的就是
|
|
114
|
+
* 「应用暂无可用界面」空态。因此这里把该应用的运行屏连同叠在它上面的浮层
|
|
115
|
+
* (详情 / 多任务)一起摘掉,回落到它下面那一屏;栈里没有该应用的运行屏时无操作
|
|
116
|
+
* (从主屏或多任务页停用走的就是这条)。
|
|
117
|
+
*/
|
|
118
|
+
function closeAppRun(appId: string): void {
|
|
119
|
+
const index = stack.value.findIndex((s) => s.id === 'app-run' && s.params.appId === appId)
|
|
120
|
+
if (index < 0) return
|
|
121
|
+
direction.value = 'backward'
|
|
122
|
+
// 命中必在 home 之后(app-run 只由 openApp 压入),slice 后至少留 home 一层
|
|
123
|
+
stack.value = stack.value.slice(0, index)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 打开应用运行面 */
|
|
127
|
+
function openApp(appId: string): void {
|
|
128
|
+
navigate('app-run', { appId })
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 打开应用详情 */
|
|
132
|
+
function openDetail(appId: string): void {
|
|
133
|
+
navigate('app-detail', { appId })
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 打开多任务浮层(临时屏,回退即消失,不留在历史里) */
|
|
137
|
+
function openSwitcher(): void {
|
|
138
|
+
navigate('switcher')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 打开权限总览 */
|
|
142
|
+
function openPermissions(): void {
|
|
143
|
+
navigate('permissions')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** 供测试与 Hot Reload 复位 */
|
|
147
|
+
function resetShellNavigation(): void {
|
|
148
|
+
direction.value = 'forward'
|
|
149
|
+
stack.value = [{ id: 'home', params: {} }]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 宿主壳导航句柄
|
|
154
|
+
*
|
|
155
|
+
* 所有返回值都是只读视图:屏幕栈只能经本文件的方法变更,避免组件直接改栈导致
|
|
156
|
+
* 方向与栈深不一致(表现为滑动动画反向、回退失效)。
|
|
157
|
+
*/
|
|
158
|
+
export interface ShellNavigation {
|
|
159
|
+
stack: ComputedRef<ShellScreenEntry[]>
|
|
160
|
+
current: ComputedRef<ShellScreenEntry>
|
|
161
|
+
params: ComputedRef<Record<string, string>>
|
|
162
|
+
direction: ComputedRef<ShellNavDirection>
|
|
163
|
+
canBack: ComputedRef<boolean>
|
|
164
|
+
navigate: typeof navigate
|
|
165
|
+
back: typeof back
|
|
166
|
+
switchTab: typeof switchTab
|
|
167
|
+
goHome: typeof goHome
|
|
168
|
+
closeAppRun: typeof closeAppRun
|
|
169
|
+
openApp: typeof openApp
|
|
170
|
+
openDetail: typeof openDetail
|
|
171
|
+
openSwitcher: typeof openSwitcher
|
|
172
|
+
openPermissions: typeof openPermissions
|
|
173
|
+
reset: typeof resetShellNavigation
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** 获取宿主壳导航句柄(单例) */
|
|
177
|
+
export function useShellNavigation(): ShellNavigation {
|
|
178
|
+
return {
|
|
179
|
+
stack: computed(() => stack.value),
|
|
180
|
+
current,
|
|
181
|
+
params,
|
|
182
|
+
direction: computed(() => direction.value),
|
|
183
|
+
canBack,
|
|
184
|
+
navigate,
|
|
185
|
+
back,
|
|
186
|
+
switchTab,
|
|
187
|
+
goHome,
|
|
188
|
+
closeAppRun,
|
|
189
|
+
openApp,
|
|
190
|
+
openDetail,
|
|
191
|
+
openSwitcher,
|
|
192
|
+
openPermissions,
|
|
193
|
+
reset: resetShellNavigation,
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { resetShellNavigation }
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 壳通知中心(与宿主 shell/composables/useShellNotifications.ts 同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 归属(AGENTS §5.1):壳只承载**机制面**——来源 / 图标 / 关联应用 / 时间 / 驻留 /
|
|
5
|
+
* 动作,标题与正文由来源方给出;壳不解析任何业务内容(B4 不命中),也不把通知
|
|
6
|
+
* 落库成真源(B3 不命中,刷新即清空)。
|
|
7
|
+
*
|
|
8
|
+
* 数据来源:壳的动作结果(启动 / 停止 / 审批 / 安装 / 卸载 / 启动失败)——
|
|
9
|
+
* dev-shell 没有宿主引擎事件(连接 / 重连),因此来源比宿主少一条,列表结构不变。
|
|
10
|
+
* 待审批条目**不在这里**:它由应用状态 `needsApproval` 动态派生(批准后自然消失,
|
|
11
|
+
* 无独立生命周期),派生点在通知栏组件里。
|
|
12
|
+
*
|
|
13
|
+
* 与「授权弹窗」的区别:弹窗是**必须当场裁决**的安全闸门(fail-closed),
|
|
14
|
+
* 通知只是事后可见面,二者不互相替代。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { computed, ref, type ComputedRef, type Ref } from 'vue'
|
|
18
|
+
|
|
19
|
+
/** 通知种类:进度类带进度条,其余为普通卡片 */
|
|
20
|
+
export type ShellNotificationKind = 'event' | 'info' | 'progress'
|
|
21
|
+
|
|
22
|
+
/** 一条平台通知 */
|
|
23
|
+
export interface ShellNotification {
|
|
24
|
+
id: string
|
|
25
|
+
kind: ShellNotificationKind
|
|
26
|
+
/** 来源方给出的图标(SVG path d,24×24 stroke 视框) */
|
|
27
|
+
icon: string
|
|
28
|
+
/** 来源名(已翻译) */
|
|
29
|
+
source: string
|
|
30
|
+
title: string
|
|
31
|
+
body?: string
|
|
32
|
+
/** 产生时刻(epoch ms,UI 侧换算相对时间) */
|
|
33
|
+
at: number
|
|
34
|
+
/** 关联应用 id:有值时提供「打开」动作 */
|
|
35
|
+
appId?: string
|
|
36
|
+
/** 进度 0–100(kind === 'progress') */
|
|
37
|
+
progress?: number
|
|
38
|
+
/** 驻留项:清除全部时保留 */
|
|
39
|
+
sticky?: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** push 入参:id 与时间由本模块生成,调用方不必关心 */
|
|
43
|
+
export type ShellNotificationInput = Omit<ShellNotification, 'id' | 'at' | 'sticky'> & {
|
|
44
|
+
sticky?: boolean
|
|
45
|
+
at?: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 列表上限:通知是可见面而非日志,超出后丢弃最旧的非驻留条目。
|
|
50
|
+
* 没有上限的话,长时间运行的会话会把内存与渲染成本都拖起来。
|
|
51
|
+
*/
|
|
52
|
+
const MAX_NOTIFICATIONS = 50
|
|
53
|
+
|
|
54
|
+
let seq = 0
|
|
55
|
+
|
|
56
|
+
const notifications: Ref<ShellNotification[]> = ref([])
|
|
57
|
+
|
|
58
|
+
/** 最新在前(通知中心自上而下按时间倒序) */
|
|
59
|
+
function pushNotification(input: ShellNotificationInput): ShellNotification {
|
|
60
|
+
const entry: ShellNotification = {
|
|
61
|
+
id: `shell-n${++seq}`,
|
|
62
|
+
at: input.at ?? Date.now(),
|
|
63
|
+
sticky: input.sticky ?? false,
|
|
64
|
+
kind: input.kind,
|
|
65
|
+
icon: input.icon,
|
|
66
|
+
source: input.source,
|
|
67
|
+
title: input.title,
|
|
68
|
+
body: input.body,
|
|
69
|
+
appId: input.appId,
|
|
70
|
+
progress: input.progress,
|
|
71
|
+
}
|
|
72
|
+
const next = [entry, ...notifications.value]
|
|
73
|
+
notifications.value =
|
|
74
|
+
next.length > MAX_NOTIFICATIONS
|
|
75
|
+
? [...next.filter((n) => n.sticky), ...next.filter((n) => !n.sticky)].slice(0, MAX_NOTIFICATIONS)
|
|
76
|
+
: next
|
|
77
|
+
return entry
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function dismissNotification(id: string): void {
|
|
81
|
+
notifications.value = notifications.value.filter((n) => n.id !== id)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 清除全部:驻留项保留(与桌面壳通知中心同口径) */
|
|
85
|
+
function clearNotifications(): void {
|
|
86
|
+
notifications.value = notifications.value.filter((n) => n.sticky)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 通知条数(角标基数;待审批数由调用方另行相加) */
|
|
90
|
+
const notificationCount: ComputedRef<number> = computed(() => notifications.value.length)
|
|
91
|
+
|
|
92
|
+
export interface ShellNotifications {
|
|
93
|
+
notifications: ComputedRef<ShellNotification[]>
|
|
94
|
+
notificationCount: ComputedRef<number>
|
|
95
|
+
pushNotification: typeof pushNotification
|
|
96
|
+
dismissNotification: typeof dismissNotification
|
|
97
|
+
clearNotifications: typeof clearNotifications
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 获取壳通知中心句柄(模块级单例:全壳一份列表,任何屏幕都能推) */
|
|
101
|
+
export function useShellNotifications(): ShellNotifications {
|
|
102
|
+
return {
|
|
103
|
+
notifications: computed(() => notifications.value),
|
|
104
|
+
notificationCount,
|
|
105
|
+
pushNotification,
|
|
106
|
+
dismissNotification,
|
|
107
|
+
clearNotifications,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 供测试复位(模块级单例需要显式清空) */
|
|
112
|
+
export function resetShellNotifications(): void {
|
|
113
|
+
notifications.value = []
|
|
114
|
+
seq = 0
|
|
115
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「打开应用」动作(与宿主 shell/composables/useShellOpen.ts 同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 首页宫格、应用列表、多任务卡、详情页入口都要「先确保应用在跑,再进运行面」。
|
|
5
|
+
* 这个两步动作在每个屏各写一遍就会出现口径分叉(有的先导航后启动、有的反过来),
|
|
6
|
+
* 因此收口到一处:启动失败不进运行面,让错误留在应用列表上可见。
|
|
7
|
+
*
|
|
8
|
+
* 待审批应用是例外:它**不能启动**,点击直接进详情页走审批(那里有「批准并启动」),
|
|
9
|
+
* 否则用户只会看到一条启动失败。
|
|
10
|
+
*
|
|
11
|
+
* 入口意图:快捷卡片可以在打开时带一个应用自定义的入口意图;意图在启动成功后
|
|
12
|
+
* 才入队,投递与消费都由应用自持(`context.ui.onSurfaceIntent`)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { ShellSurfaceIntent } from '../../../../src/types'
|
|
16
|
+
import { useShellApps } from './useShellApps'
|
|
17
|
+
import { useShellNavigation } from './useShellNavigation'
|
|
18
|
+
import { queueSurfaceIntent } from '../surfaceIntent'
|
|
19
|
+
|
|
20
|
+
/** 启动并进入运行面;启动失败返回 false(由调用方决定是否提示) */
|
|
21
|
+
export async function openShellApp(
|
|
22
|
+
appId: string,
|
|
23
|
+
intent?: ShellSurfaceIntent | null,
|
|
24
|
+
): Promise<boolean> {
|
|
25
|
+
const { launch, getApp } = useShellApps()
|
|
26
|
+
const nav = useShellNavigation()
|
|
27
|
+
|
|
28
|
+
// 待审批:进详情页审批,不尝试启动(启动必被后端拒绝);此时也无从进入应用内部
|
|
29
|
+
if (getApp(appId)?.state === 'approval') {
|
|
30
|
+
nav.openDetail(appId)
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ok = await launch(appId)
|
|
35
|
+
if (!ok) return false
|
|
36
|
+
queueSurfaceIntent(appId, intent)
|
|
37
|
+
nav.openApp(appId)
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 组合式入口(组件内使用) */
|
|
42
|
+
export function useShellOpen(): { open: typeof openShellApp } {
|
|
43
|
+
return { open: openShellApp }
|
|
44
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 宿主壳覆盖层状态(与宿主 shell/composables/useShellOverlays.ts 同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 三类平台级覆盖层都由壳统一渲染,不由各应用自己弹:
|
|
5
|
+
* ① 胶囊菜单:平台叠加在应用之上的控制项(与小程序胶囊同构)
|
|
6
|
+
* ② 运行时授权弹窗:应用临时申请权限时的统一裁决界面
|
|
7
|
+
* ③ 通知栏(Android 式独立面):自顶部滑下的平台通知中心
|
|
8
|
+
*
|
|
9
|
+
* 统一渲染的原因是这些界面必须与平台视觉和安全口径一致(拒绝即不可用、
|
|
10
|
+
* fail-closed)。状态走模块级单例,任何屏幕都能打开,渲染位置固定在壳根。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { computed, ref, type ComputedRef, type Ref } from 'vue'
|
|
14
|
+
|
|
15
|
+
/** 一次运行时权限申请 */
|
|
16
|
+
export interface ShellPermissionRequest {
|
|
17
|
+
/** 申请方应用 id */
|
|
18
|
+
appId: string
|
|
19
|
+
/** 申请的权限词 */
|
|
20
|
+
keys: string[]
|
|
21
|
+
/** 应用自述用途(键为权限词) */
|
|
22
|
+
reasons?: Record<string, string>
|
|
23
|
+
/** 申请目标(如域名 / 目录),键为权限词;缺省不展示 */
|
|
24
|
+
targets?: Record<string, string>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const capsuleAppId: Ref<string | null> = ref(null)
|
|
28
|
+
const permissionRequest: Ref<ShellPermissionRequest | null> = ref(null)
|
|
29
|
+
const shadeOpen: Ref<boolean> = ref(false)
|
|
30
|
+
|
|
31
|
+
/** 打开胶囊菜单 */
|
|
32
|
+
function openCapsule(appId: string): void {
|
|
33
|
+
capsuleAppId.value = appId
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 关闭胶囊菜单 */
|
|
37
|
+
function closeCapsule(): void {
|
|
38
|
+
capsuleAppId.value = null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 发起一次运行时授权请求
|
|
43
|
+
*
|
|
44
|
+
* 由「应用详情 → 演示授权弹窗」驱动;后续接入真授权事件后,事件侧同样调这里,
|
|
45
|
+
* UI 与裁决口径复用同一份实现。
|
|
46
|
+
*/
|
|
47
|
+
function requestPermissions(request: ShellPermissionRequest): void {
|
|
48
|
+
permissionRequest.value = request
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 关闭授权弹窗(同时清空请求,避免残留状态影响下一次) */
|
|
52
|
+
function closePermissionRequest(): void {
|
|
53
|
+
permissionRequest.value = null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 打开通知栏 */
|
|
57
|
+
function openShade(): void {
|
|
58
|
+
shadeOpen.value = true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 关闭通知栏 */
|
|
62
|
+
function closeShade(): void {
|
|
63
|
+
shadeOpen.value = false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 切换通知栏(状态条 / 铃铛入口用:同一个按钮开与关) */
|
|
67
|
+
function toggleShade(): void {
|
|
68
|
+
shadeOpen.value = !shadeOpen.value
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 宿主壳覆盖层句柄 */
|
|
72
|
+
export interface ShellOverlays {
|
|
73
|
+
capsuleAppId: ComputedRef<string | null>
|
|
74
|
+
permissionRequest: ComputedRef<ShellPermissionRequest | null>
|
|
75
|
+
shadeOpen: ComputedRef<boolean>
|
|
76
|
+
openCapsule: typeof openCapsule
|
|
77
|
+
closeCapsule: typeof closeCapsule
|
|
78
|
+
requestPermissions: typeof requestPermissions
|
|
79
|
+
closePermissionRequest: typeof closePermissionRequest
|
|
80
|
+
openShade: typeof openShade
|
|
81
|
+
closeShade: typeof closeShade
|
|
82
|
+
toggleShade: typeof toggleShade
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 获取宿主壳覆盖层句柄(单例) */
|
|
86
|
+
export function useShellOverlays(): ShellOverlays {
|
|
87
|
+
return {
|
|
88
|
+
capsuleAppId: computed(() => capsuleAppId.value),
|
|
89
|
+
permissionRequest: computed(() => permissionRequest.value),
|
|
90
|
+
shadeOpen: computed(() => shadeOpen.value),
|
|
91
|
+
openCapsule,
|
|
92
|
+
closeCapsule,
|
|
93
|
+
requestPermissions,
|
|
94
|
+
closePermissionRequest,
|
|
95
|
+
openShade,
|
|
96
|
+
closeShade,
|
|
97
|
+
toggleShade,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { openCapsule, closeCapsule, requestPermissions, closePermissionRequest, openShade, closeShade, toggleShade }
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 壳 UI 偏好(与宿主 shell/composables/useShellPreferences.ts 同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 归属:这是**壳的视觉偏好**(纯机制词汇,不含任何业务语义),因此不写宿主
|
|
5
|
+
* AppConfig。持久化走 localStorage,与宿主同键同构:丢失只影响观感,不影响功能。
|
|
6
|
+
*
|
|
7
|
+
* 壁纸 id 是**稳定标识**而非样式值:渐变真源在 `styles/wallpaper.css` 的 --wall-*,
|
|
8
|
+
* 这里只存 id。新增内置壁纸 = 加一条 id + 一条 token + 一条 i18n,三处同步。
|
|
9
|
+
*
|
|
10
|
+
* 与宿主的差异:宿主支持「自定义壁纸」档(用户经宿主命令选图并落盘,壳不能自行
|
|
11
|
+
* 读盘);dev-shell 没有宿主文件通道,`custom` 档恒定不可达——这里保留档位与
|
|
12
|
+
* 校验逻辑只为了与宿主契约同构,落点由「从未写入过 path」天然挡住。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { computed, ref, watch, type ComputedRef, type Ref } from 'vue'
|
|
16
|
+
import { logger } from '../logger'
|
|
17
|
+
|
|
18
|
+
/** 壁纸档位(前四档与 wallpaper.css 的 --wall-* 一一对应;custom 保留为宿主契约对齐) */
|
|
19
|
+
export const SHELL_WALLPAPERS = ['none', 'aurora', 'dune', 'reef', 'custom'] as const
|
|
20
|
+
export type ShellWallpaper = (typeof SHELL_WALLPAPERS)[number]
|
|
21
|
+
|
|
22
|
+
/** 自定义档位的内部标识(与 i18n / token 无关,只用于分支) */
|
|
23
|
+
export const WALLPAPER_CUSTOM: ShellWallpaper = 'custom'
|
|
24
|
+
|
|
25
|
+
export const WALLPAPER_DEFAULT: ShellWallpaper = 'aurora'
|
|
26
|
+
/** 遮罩强度上限:超过 70% 壁纸几乎不可见,留着只是让用户白调 */
|
|
27
|
+
export const WALL_DIM_MAX = 70
|
|
28
|
+
export const WALL_DIM_DEFAULT = 30
|
|
29
|
+
|
|
30
|
+
interface ShellUiPrefs {
|
|
31
|
+
wallpaper: ShellWallpaper
|
|
32
|
+
/** 自定义壁纸的本地绝对路径;dev-shell 无宿主文件通道,恒为 null */
|
|
33
|
+
wallpaperImage: string | null
|
|
34
|
+
/** 壁纸之上的页面色遮罩强度(%,护文字对比度) */
|
|
35
|
+
wallDim: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const STORAGE_KEY = 'wasmnest.shell-ui-prefs.v1'
|
|
39
|
+
|
|
40
|
+
function isWallpaper(value: unknown): value is ShellWallpaper {
|
|
41
|
+
return typeof value === 'string' && (SHELL_WALLPAPERS as readonly string[]).includes(value)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function load(): ShellUiPrefs {
|
|
45
|
+
const fallback: ShellUiPrefs = {
|
|
46
|
+
wallpaper: WALLPAPER_DEFAULT,
|
|
47
|
+
wallpaperImage: null,
|
|
48
|
+
wallDim: WALL_DIM_DEFAULT,
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const raw = localStorage.getItem(STORAGE_KEY)
|
|
52
|
+
if (!raw) return fallback
|
|
53
|
+
const parsed = JSON.parse(raw) as Partial<ShellUiPrefs>
|
|
54
|
+
// 只取已知键、逐项校验:损坏 / 旧版本 / 手改数据一律回落默认,不把脏值带进渲染
|
|
55
|
+
const wallpaper = isWallpaper(parsed.wallpaper) ? parsed.wallpaper : fallback.wallpaper
|
|
56
|
+
const wallpaperImage =
|
|
57
|
+
typeof parsed.wallpaperImage === 'string' && parsed.wallpaperImage.length > 0
|
|
58
|
+
? parsed.wallpaperImage
|
|
59
|
+
: null
|
|
60
|
+
return {
|
|
61
|
+
// custom 档没有图就等于没选:回落到默认渐变,而不是渲染一层空背景
|
|
62
|
+
wallpaper: wallpaper === WALLPAPER_CUSTOM && wallpaperImage === null ? fallback.wallpaper : wallpaper,
|
|
63
|
+
wallpaperImage,
|
|
64
|
+
wallDim:
|
|
65
|
+
typeof parsed.wallDim === 'number' && parsed.wallDim >= 0 && parsed.wallDim <= WALL_DIM_MAX
|
|
66
|
+
? Math.round(parsed.wallDim)
|
|
67
|
+
: fallback.wallDim,
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
logger.warn('[Shell] shell ui prefs unreadable; falling back to defaults', e)
|
|
71
|
+
return fallback
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const prefs: Ref<ShellUiPrefs> = ref(load())
|
|
76
|
+
|
|
77
|
+
watch(
|
|
78
|
+
prefs,
|
|
79
|
+
(value) => {
|
|
80
|
+
try {
|
|
81
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(value))
|
|
82
|
+
} catch (e) {
|
|
83
|
+
// localStorage 不可用(隐私模式 / 配额满):偏好仅本次会话生效,不打断主流程
|
|
84
|
+
logger.warn('[Shell] shell ui prefs not persisted', e)
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{ deep: true },
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
/** 当前壁纸 id */
|
|
91
|
+
const wallpaper: ComputedRef<ShellWallpaper> = computed(() => prefs.value.wallpaper)
|
|
92
|
+
/** 当前自定义壁纸路径(dev-shell 恒为 null) */
|
|
93
|
+
const wallpaperImage: ComputedRef<string | null> = computed(() => prefs.value.wallpaperImage)
|
|
94
|
+
/** 当前遮罩强度(0–70) */
|
|
95
|
+
const wallDim: ComputedRef<number> = computed(() => prefs.value.wallDim)
|
|
96
|
+
|
|
97
|
+
function setWallpaper(next: ShellWallpaper): void {
|
|
98
|
+
prefs.value = { ...prefs.value, wallpaper: next }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 记下自定义壁纸路径并切到 custom 档
|
|
103
|
+
*
|
|
104
|
+
* 路径由宿主命令(选图 + 落盘)给出;dev-shell 没有该通道,此函数仅保持宿主
|
|
105
|
+
* 契约形状,不被任何 dev 界面调用。
|
|
106
|
+
*/
|
|
107
|
+
function setWallpaperImage(next: string | null): void {
|
|
108
|
+
const image = next && next.length > 0 ? next : null
|
|
109
|
+
if (image !== null) {
|
|
110
|
+
prefs.value = { ...prefs.value, wallpaperImage: image, wallpaper: WALLPAPER_CUSTOM }
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
// 移除自定义图:正停在 custom 档时回落到默认内置壁纸,避免「选了自定义却没有图」的空档
|
|
114
|
+
prefs.value = {
|
|
115
|
+
...prefs.value,
|
|
116
|
+
wallpaperImage: null,
|
|
117
|
+
wallpaper:
|
|
118
|
+
prefs.value.wallpaper === WALLPAPER_CUSTOM ? WALLPAPER_DEFAULT : prefs.value.wallpaper,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 设置遮罩强度;越界值钳制到 [0, WALL_DIM_MAX],不抛错(滑杆可能给出小数) */
|
|
123
|
+
function setWallDim(next: number): void {
|
|
124
|
+
const clamped = Math.min(WALL_DIM_MAX, Math.max(0, Math.round(next)))
|
|
125
|
+
prefs.value = { ...prefs.value, wallDim: clamped }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 壁纸选择器直接消费的档位清单(id + i18n key 由调用方拼) */
|
|
129
|
+
export const SHELL_WALLPAPER_IDS: readonly ShellWallpaper[] = SHELL_WALLPAPERS
|
|
130
|
+
|
|
131
|
+
export interface ShellPreferences {
|
|
132
|
+
wallpaper: ComputedRef<ShellWallpaper>
|
|
133
|
+
wallpaperImage: ComputedRef<string | null>
|
|
134
|
+
wallDim: ComputedRef<number>
|
|
135
|
+
setWallpaper: typeof setWallpaper
|
|
136
|
+
setWallpaperImage: typeof setWallpaperImage
|
|
137
|
+
setWallDim: typeof setWallDim
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 获取壳 UI 偏好句柄(模块级单例,与壳内其它机制一致) */
|
|
141
|
+
export function useShellPreferences(): ShellPreferences {
|
|
142
|
+
return { wallpaper, wallpaperImage, wallDim, setWallpaper, setWallpaperImage, setWallDim }
|
|
143
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Shell 宿主壳「最近使用」(与宿主 shell/composables/useShellRecent.ts 同构)
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* 最近使用是平台侧的排序信号(首页「最近使用」区消费它),不是应用自己的状态,
|
|
5
|
+
* 因此由壳持有。
|
|
6
|
+
*
|
|
7
|
+
* 持久化落在 localStorage:这是纯 UI 偏好,丢失只影响排序;隐私模式下写入失败
|
|
8
|
+
* 按 warn 处理(不静默吞掉)。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { computed, ref, type ComputedRef } from 'vue'
|
|
12
|
+
import { logger } from '../logger'
|
|
13
|
+
|
|
14
|
+
const STORAGE_KEY = 'wasmnest.devshell.shell.recentApps'
|
|
15
|
+
/** 保留上限:再多也不会被展示,留着只会让写入无限增长 */
|
|
16
|
+
const MAX_RECENT = 12
|
|
17
|
+
|
|
18
|
+
const recentIds = ref<string[]>(load())
|
|
19
|
+
|
|
20
|
+
function load(): string[] {
|
|
21
|
+
try {
|
|
22
|
+
const raw = localStorage.getItem(STORAGE_KEY)
|
|
23
|
+
if (!raw) return []
|
|
24
|
+
const parsed: unknown = JSON.parse(raw)
|
|
25
|
+
if (!Array.isArray(parsed)) return []
|
|
26
|
+
return parsed.filter((v): v is string => typeof v === 'string').slice(0, MAX_RECENT)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
// 首次启动 / 隐私模式 / 旧格式损坏都不是故障,按空列表继续
|
|
29
|
+
logger.warn(`recent apps load failed, fallback to empty: ${String(e)}`)
|
|
30
|
+
return []
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function persist(ids: string[]): void {
|
|
35
|
+
try {
|
|
36
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(ids))
|
|
37
|
+
} catch (e) {
|
|
38
|
+
logger.warn(`recent apps persist failed (order may be lost): ${String(e)}`)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 记录一次使用(同 id 提到最前,去重) */
|
|
43
|
+
function pushRecent(appId: string): void {
|
|
44
|
+
if (!appId) return
|
|
45
|
+
const next = [appId, ...recentIds.value.filter((id) => id !== appId)].slice(0, MAX_RECENT)
|
|
46
|
+
recentIds.value = next
|
|
47
|
+
persist(next)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 清空最近使用 */
|
|
51
|
+
function clearRecent(): void {
|
|
52
|
+
recentIds.value = []
|
|
53
|
+
persist([])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 移除单条最近使用
|
|
58
|
+
*
|
|
59
|
+
* 多任务卡片「上滑关闭 / 点 ×」时需要:关闭一个应用后它的卡片不能换个身份
|
|
60
|
+
* (运行中 → 未运行)再回来——那在用户看来就是「关不掉」。
|
|
61
|
+
*/
|
|
62
|
+
function removeRecent(appId: string): void {
|
|
63
|
+
const next = recentIds.value.filter((id) => id !== appId)
|
|
64
|
+
if (next.length === recentIds.value.length) return
|
|
65
|
+
recentIds.value = next
|
|
66
|
+
persist(next)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 最近使用(新 → 旧) */
|
|
70
|
+
export function useShellRecent(): {
|
|
71
|
+
recentIds: ComputedRef<string[]>
|
|
72
|
+
pushRecent: typeof pushRecent
|
|
73
|
+
removeRecent: typeof removeRecent
|
|
74
|
+
clearRecent: typeof clearRecent
|
|
75
|
+
} {
|
|
76
|
+
return {
|
|
77
|
+
recentIds: computed(() => recentIds.value),
|
|
78
|
+
pushRecent,
|
|
79
|
+
removeRecent,
|
|
80
|
+
clearRecent,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { pushRecent, removeRecent, clearRecent }
|