@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.
- package/README.md +363 -2
- package/README_en.md +353 -0
- package/bin/build.js +269 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +324 -0
- package/bin/package.js +150 -0
- package/bin/scaffold.js +285 -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 +51 -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 +328 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +328 -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 +351 -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 +155 -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 +496 -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 +378 -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 +316 -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 +415 -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 +35 -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/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/styles/shell.css +841 -0
- package/dev-shell/src/shell/types.ts +137 -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 +884 -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 +84 -0
- package/dist/index.js +161 -0
- package/dist/types.d.ts +637 -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 +80 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +87 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +715 -0
- package/src/ui/PluginGlobalDialog.vue +388 -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/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
package/bin/scaffold.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wasmnest-plugin 脚手架与校验命令:create / manifest / validate(自 cli.js 拆出)
|
|
3
|
+
*/
|
|
4
|
+
import { cpSync, existsSync, readFileSync, rmSync } from "node:fs"
|
|
5
|
+
import { join, relative, resolve } from "node:path"
|
|
6
|
+
import { generateManifest } from "./manifest-gen.js"
|
|
7
|
+
import { SDK_ROOT, TEMPLATE_DIR, readJson, walk, fillPlaceholders, toPosix } from "./lib.js"
|
|
8
|
+
|
|
9
|
+
// ==================== 命令:create ====================
|
|
10
|
+
|
|
11
|
+
function cmdCreate(positional, flags) {
|
|
12
|
+
const [id, name] = positional
|
|
13
|
+
if (!id || !name) {
|
|
14
|
+
console.error('用法: wasmnest-plugin create <id> <name> [--author <author>] [--dir <dir>]')
|
|
15
|
+
console.error('示例: wasmnest-plugin create com.example.my-plugin "My Plugin" --author "me"')
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
if (!/^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*$/.test(id)) {
|
|
19
|
+
console.error(`非法插件 id: "${id}" — 使用反域名风格,如 com.example.my-plugin`)
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
if (!id.includes('.')) {
|
|
23
|
+
console.error(`插件 id 应包含域名段(反域名风格): "${id}"`)
|
|
24
|
+
process.exit(1)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const author = flags.author || ''
|
|
28
|
+
const last = id.split('.').pop()
|
|
29
|
+
const outDir = resolve(process.cwd(), flags.dir || last)
|
|
30
|
+
if (existsSync(outDir)) {
|
|
31
|
+
console.error(`目标目录已存在: ${outDir}`)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 派生身份:crate 名 / 结构体名 / npm 包名
|
|
36
|
+
const crate = `wasmnest_plugin_${last.replace(/[^a-zA-Z0-9_]/g, '_').replace(/^_+|_+$/g, '')}`
|
|
37
|
+
const struct = `${last
|
|
38
|
+
.split(/[^a-zA-Z0-9]/)
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1))
|
|
41
|
+
.join('')}Plugin`
|
|
42
|
+
const pkgName = `@wasmnest/plugin-${last}`
|
|
43
|
+
|
|
44
|
+
// 插件类型:默认 wasm(前端 + WASM 后端);--ts-only 生成纯前端插件
|
|
45
|
+
const tsOnly = flags['ts-only'] === true
|
|
46
|
+
const pluginType = tsOnly ? 'ts-only' : 'wasm'
|
|
47
|
+
// 注意:值内直接嵌入实际 crate 名(fillPlaceholders 按序替换,不能引用占位符本身)
|
|
48
|
+
const rustLibraryLine = tsOnly ? '' : ` "rustLibrary": "${crate}",\n`
|
|
49
|
+
|
|
50
|
+
// SDK 依赖标识:--registry 引用已发布版本(npm + crates.io),默认引用本地 SDK 相对路径
|
|
51
|
+
const sdkPkg = readJson(join(SDK_ROOT, 'package.json'), 'SDK package.json')
|
|
52
|
+
const sdkJs =
|
|
53
|
+
flags.registry === true ? `^${sdkPkg.version}` : `file:${toPosix(relative(outDir, SDK_ROOT))}`
|
|
54
|
+
const sdkRust =
|
|
55
|
+
flags.registry === true
|
|
56
|
+
? `"${sdkPkg.version}"`
|
|
57
|
+
: `{ path = "${toPosix(relative(join(outDir, 'rust'), join(SDK_ROOT, 'rust')))}" }`
|
|
58
|
+
|
|
59
|
+
// 复制模板并填充占位符
|
|
60
|
+
cpSync(TEMPLATE_DIR, outDir, { recursive: true })
|
|
61
|
+
if (tsOnly) {
|
|
62
|
+
rmSync(join(outDir, 'rust'), { recursive: true, force: true })
|
|
63
|
+
}
|
|
64
|
+
fillPlaceholders(walk(outDir), {
|
|
65
|
+
'{{ID}}': id,
|
|
66
|
+
'{{NAME}}': name,
|
|
67
|
+
'{{AUTHOR}}': author,
|
|
68
|
+
'{{CRATE}}': crate,
|
|
69
|
+
'{{STRUCT}}': struct,
|
|
70
|
+
'{{PKG_NAME}}': pkgName,
|
|
71
|
+
'{{SDK_JS}}': sdkJs,
|
|
72
|
+
'{{SDK_RUST}}': sdkRust,
|
|
73
|
+
'{{PLUGIN_TYPE}}': pluginType,
|
|
74
|
+
'{{RUST_LIBRARY_LINE}}': rustLibraryLine,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
console.log(`\n[wasmnest-plugin] 已生成插件工程: ${outDir}`)
|
|
78
|
+
console.log(` id: ${id}`)
|
|
79
|
+
console.log(` name: ${name}`)
|
|
80
|
+
console.log(` pluginType: ${pluginType}${tsOnly ? '' : ` (crate: ${crate})`}`)
|
|
81
|
+
console.log(`\n下一步:`)
|
|
82
|
+
console.log(` cd ${toPosix(relative(process.cwd(), outDir)) || '.'}`)
|
|
83
|
+
console.log(` pnpm install`)
|
|
84
|
+
console.log(` pnpm run dev # 浏览器开发环境(HMR,无需真机)`)
|
|
85
|
+
console.log(` pnpm run build # 构建(vite + WASM)`)
|
|
86
|
+
console.log(` pnpm run package # 打包 dist/${id}.zip 插件包`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
// ==================== 命令:manifest(自动填充) ====================
|
|
91
|
+
|
|
92
|
+
function cmdManifest(flags) {
|
|
93
|
+
const cwd = process.cwd()
|
|
94
|
+
const check = flags.check === true
|
|
95
|
+
try {
|
|
96
|
+
const { changed, report } = generateManifest(cwd, { check })
|
|
97
|
+
if (!changed) {
|
|
98
|
+
console.log('[wasmnest-plugin] plugin.json 已是最新,无需更新')
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
for (const line of report) console.log(`[wasmnest-plugin] ${line}`)
|
|
102
|
+
if (check) {
|
|
103
|
+
console.log('[wasmnest-plugin] --check 模式:plugin.json 与源码不一致(未写入)')
|
|
104
|
+
process.exit(1)
|
|
105
|
+
}
|
|
106
|
+
console.log('[wasmnest-plugin] plugin.json 已根据源码自动填充')
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error(`[wasmnest-plugin] manifest 生成失败: ${e.message}`)
|
|
109
|
+
process.exit(1)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 从目录向上查找 vite 可执行文件(兼容 npm workspace 依赖 hoist 到仓库根的场景) */
|
|
114
|
+
|
|
115
|
+
// ==================== 命令:validate(清单校验) ====================
|
|
116
|
+
|
|
117
|
+
/** 合法权限列表(与宿主 src/plugin/permission.ts 权限映射键同步) */
|
|
118
|
+
const VALID_PERMISSIONS = new Set([
|
|
119
|
+
'terminal:output',
|
|
120
|
+
'session:read',
|
|
121
|
+
'ui:settings',
|
|
122
|
+
'ui:route',
|
|
123
|
+
'ui:dialog',
|
|
124
|
+
'ui:back',
|
|
125
|
+
'network:http',
|
|
126
|
+
'storage',
|
|
127
|
+
'fs:read',
|
|
128
|
+
'fs:write',
|
|
129
|
+
'bus',
|
|
130
|
+
'system:open',
|
|
131
|
+
'peer',
|
|
132
|
+
'mdns',
|
|
133
|
+
'ws:client',
|
|
134
|
+
'auth',
|
|
135
|
+
'notify',
|
|
136
|
+
'metrics:read',
|
|
137
|
+
])
|
|
138
|
+
|
|
139
|
+
const VALID_PLUGIN_TYPES = new Set(['wasm', 'ts-only', 'rust', 'rust-ts'])
|
|
140
|
+
// 装配角色(manifest `type`,ADR 0032):真源 = wasm-core `PluginKind`。
|
|
141
|
+
// `system` / `application` 是历史拼写,宿主反序列化仍按别名接受,这里只告警。
|
|
142
|
+
const VALID_PLUGIN_KINDS = new Set(['basic-service', 'internal-business', 'business-app'])
|
|
143
|
+
const LEGACY_PLUGIN_KINDS = new Map([
|
|
144
|
+
['system', 'basic-service'],
|
|
145
|
+
['application', 'business-app'],
|
|
146
|
+
])
|
|
147
|
+
const WASM_HASH_RE = /^sha256-[0-9a-f]{64}$/i
|
|
148
|
+
|
|
149
|
+
// 适配平台取值域(manifest `platform`,必填,与 id/name/version 同档)。
|
|
150
|
+
// 真源是 SDK rust/src/types.rs::PluginPlatform(serde rename_all = "lowercase");
|
|
151
|
+
// 宿主加载 / 安装期按本端校验:移动拒 desktop、桌面拒 mobile,both 两端均可。
|
|
152
|
+
const VALID_PLATFORMS = new Set(['desktop', 'mobile', 'both'])
|
|
153
|
+
|
|
154
|
+
function cmdValidate(flags) {
|
|
155
|
+
const dir = resolve(process.cwd(), flags.dir || '.')
|
|
156
|
+
const manifestPath = join(dir, 'plugin.json')
|
|
157
|
+
const errors = []
|
|
158
|
+
const warnings = []
|
|
159
|
+
|
|
160
|
+
if (!existsSync(manifestPath)) {
|
|
161
|
+
console.error(`[wasmnest-plugin] 缺少 plugin.json: ${dir}`)
|
|
162
|
+
process.exit(1)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let manifest
|
|
166
|
+
try {
|
|
167
|
+
manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'))
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.error(`[wasmnest-plugin] plugin.json 不是合法 JSON: ${e.message}`)
|
|
170
|
+
process.exit(1)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// id:反域名风格
|
|
174
|
+
if (
|
|
175
|
+
typeof manifest.id !== 'string' ||
|
|
176
|
+
!/^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*$/.test(manifest.id) ||
|
|
177
|
+
!manifest.id.includes('.')
|
|
178
|
+
) {
|
|
179
|
+
errors.push(`id 非法: "${manifest.id}" — 使用反域名风格,如 com.example.my-plugin`)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 必填字段(platform 与 id/name/version 同档:宿主反序列化无缺省,缺失即拒装)
|
|
183
|
+
for (const field of ['name', 'version', 'platform', 'main', 'pluginType', 'permissions', 'contributes']) {
|
|
184
|
+
if (manifest[field] === undefined || manifest[field] === null || manifest[field] === '') {
|
|
185
|
+
errors.push(`缺少必填字段: ${field}`)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// platform 取值域(拼写与宿主端门禁词汇同源;未知取值在宿主反序列化即拒)
|
|
190
|
+
if (manifest.platform && !VALID_PLATFORMS.has(manifest.platform)) {
|
|
191
|
+
errors.push(
|
|
192
|
+
`platform 非法: "${manifest.platform}"(允许: ${[...VALID_PLATFORMS].join(' / ')})`,
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// pluginType / rustLibrary / wasmHash
|
|
197
|
+
if (manifest.pluginType && !VALID_PLUGIN_TYPES.has(manifest.pluginType)) {
|
|
198
|
+
errors.push(
|
|
199
|
+
`pluginType 非法: "${manifest.pluginType}"(允许: ${[...VALID_PLUGIN_TYPES].join(' / ')})`,
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
// type(装配角色):非法取值构建期拒;历史拼写只告警(宿主仍按别名接受)
|
|
203
|
+
if (manifest.type !== undefined && manifest.type !== null && manifest.type !== '') {
|
|
204
|
+
if (!VALID_PLUGIN_KINDS.has(manifest.type) && !LEGACY_PLUGIN_KINDS.has(manifest.type)) {
|
|
205
|
+
errors.push(
|
|
206
|
+
`type 非法: "${manifest.type}"(允许: ${[...VALID_PLUGIN_KINDS].join(' / ')})`,
|
|
207
|
+
)
|
|
208
|
+
} else if (LEGACY_PLUGIN_KINDS.has(manifest.type)) {
|
|
209
|
+
warnings.push(
|
|
210
|
+
`type="${manifest.type}" 是历史拼写,改写为 "${LEGACY_PLUGIN_KINDS.get(manifest.type)}"`,
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (manifest.pluginType === 'wasm' && !manifest.rustLibrary) {
|
|
215
|
+
errors.push('pluginType=wasm 时必须提供 rustLibrary(与 Cargo.toml 包名一致)')
|
|
216
|
+
}
|
|
217
|
+
if (manifest.wasmHash !== undefined && !WASM_HASH_RE.test(manifest.wasmHash)) {
|
|
218
|
+
errors.push(`wasmHash 格式非法: "${manifest.wasmHash}"(应为 sha256-<64位hex>)`)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 权限
|
|
222
|
+
if (Array.isArray(manifest.permissions)) {
|
|
223
|
+
const unknown = manifest.permissions.filter((p) => !VALID_PERMISSIONS.has(p))
|
|
224
|
+
if (unknown.length) {
|
|
225
|
+
errors.push(`未知权限: ${unknown.join(', ')}(合法列表见宿主 permission.ts)`)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// main 产物存在性(未构建仅警告)
|
|
230
|
+
const distMain = join(dir, 'dist', manifest.main || 'index.js')
|
|
231
|
+
if (!existsSync(distMain)) {
|
|
232
|
+
warnings.push(`dist/${manifest.main || 'index.js'} 不存在 — 尚未构建(pnpm run build)`)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// contributes 结构
|
|
236
|
+
if (manifest.contributes && typeof manifest.contributes !== 'object') {
|
|
237
|
+
errors.push('contributes 必须是对象')
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// contributes.monitorPanels(monitor 统一壳的自定义面板注册元数据)
|
|
241
|
+
// 只登记 id / title / order;面板实现住提供方应用工程(mountMonitorPanel),
|
|
242
|
+
// 因此这里不校验组件路径。非法条目会让面板「列得出来、挂不上」,构建期判死。
|
|
243
|
+
const monitorPanels = manifest.contributes?.monitorPanels
|
|
244
|
+
if (monitorPanels !== undefined && monitorPanels !== null) {
|
|
245
|
+
if (!Array.isArray(monitorPanels)) {
|
|
246
|
+
errors.push('contributes.monitorPanels 必须是数组')
|
|
247
|
+
} else {
|
|
248
|
+
const panelIds = new Set()
|
|
249
|
+
for (const entry of monitorPanels) {
|
|
250
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
251
|
+
errors.push(`contributes.monitorPanels 条目形态非法: ${JSON.stringify(entry)}`)
|
|
252
|
+
continue
|
|
253
|
+
}
|
|
254
|
+
if (typeof entry.id !== 'string' || entry.id.trim() === '') {
|
|
255
|
+
errors.push(`contributes.monitorPanels 条目缺非空 id: ${JSON.stringify(entry)}`)
|
|
256
|
+
} else if (panelIds.has(entry.id)) {
|
|
257
|
+
errors.push(`contributes.monitorPanels 重复 id: ${entry.id}`)
|
|
258
|
+
} else {
|
|
259
|
+
panelIds.add(entry.id)
|
|
260
|
+
}
|
|
261
|
+
if (typeof entry.title !== 'string' || entry.title.trim() === '') {
|
|
262
|
+
errors.push(`contributes.monitorPanels 条目缺非空 title: ${JSON.stringify(entry)}`)
|
|
263
|
+
}
|
|
264
|
+
if (entry.order !== undefined && !Number.isFinite(entry.order)) {
|
|
265
|
+
errors.push(`contributes.monitorPanels 条目 order 非法(须为数字): ${JSON.stringify(entry)}`)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
for (const w of warnings) console.log(` ⚠ ${w}`)
|
|
273
|
+
for (const e of errors) console.error(` ✗ ${e}`)
|
|
274
|
+
|
|
275
|
+
if (errors.length) {
|
|
276
|
+
console.error(`\n[wasmnest-plugin] validate 失败: ${errors.length} 个错误`)
|
|
277
|
+
process.exit(1)
|
|
278
|
+
}
|
|
279
|
+
console.log(
|
|
280
|
+
`\n[wasmnest-plugin] validate 通过${warnings.length ? `(${warnings.length} 个警告)` : ''}`,
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
export { cmdCreate, cmdManifest, cmdValidate }
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# WasmNest Dev Shell(移动端插件浏览器开发环境)
|
|
2
|
+
|
|
3
|
+
浏览器里的**宿主壳**:在浏览器中运行插件前端源码,支持 HMR,
|
|
4
|
+
无需构建、打包、真机安装即可迭代 UI 与前端逻辑。
|
|
5
|
+
|
|
6
|
+
## 形态:与真机宿主壳同构
|
|
7
|
+
|
|
8
|
+
调试壳内置一层 mini 宿主壳(`src/shell/**`),与真机
|
|
9
|
+
`wasmnest-mobile/src/shell/**` 同构——同样的屏幕栈(首页 / 应用 / 详情 / 运行面 /
|
|
10
|
+
多任务 / 权限总览 / 我的)、同样的「只认 `registerSurface` 一种运行面形态」、同样的
|
|
11
|
+
胶囊与平台覆盖层。因此:
|
|
12
|
+
|
|
13
|
+
- 插件在 dev-shell 里看到的挂载方式、导航层级与真机一致,不会出现
|
|
14
|
+
「浏览器里好好的、装到手机上白屏」。
|
|
15
|
+
- npm 包必须自包含(外部用户装不到 app 源码),所以这里是**同构实现**而非共享组件;
|
|
16
|
+
契约漂移由 `__tests__/shell/contractDrift.test.ts` 钉住(字段集 / 状态集 /
|
|
17
|
+
屏幕集与宿主逐项比对)。
|
|
18
|
+
- 内置页(模拟终端)已降为**内置应用**(`src/apps/mock-terminal/`),与被调试插件
|
|
19
|
+
走同一条加载与渲染路径——预览环境里始终有一个形态正确的应用在场。
|
|
20
|
+
|
|
21
|
+
## 使用
|
|
22
|
+
|
|
23
|
+
在插件工程目录运行:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm run dev # 推荐:脚本自动解析 node_modules/.bin(Windows 必需)
|
|
27
|
+
pnpm exec wasmnest-plugin dev # 或 pnpm exec 方式(等效)
|
|
28
|
+
wasmnest-plugin dev # 仅 macOS/Linux(PATH 含 .bin 时)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
> **Windows**:cmd / PowerShell 直接输入 `wasmnest-plugin` 会报"不是内部或外部命令",
|
|
32
|
+
> 因为 Windows 不把 `node_modules/.bin` 加入 PATH——请用 `pnpm run dev` 或 `pnpm exec`。
|
|
33
|
+
|
|
34
|
+
带参数示例:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm exec wasmnest-plugin dev --entry src/custom-entry.ts
|
|
38
|
+
pnpm exec wasmnest-plugin dev --port 5180 --open
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
浏览器打开 `http://localhost:5173`(--open 自动打开)。
|
|
42
|
+
|
|
43
|
+
### 在手机上查看页面
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
wasmnest-plugin dev --host # 监听局域网(默认 0.0.0.0)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
手机与电脑连同一 WiFi,手机浏览器打开 `http://<电脑IP>:5173/` 即可在真机浏览器中
|
|
50
|
+
查看页面(真实触控、真实视口)。建议:
|
|
51
|
+
|
|
52
|
+
- 点工具条「手机框:关」切换全宽渲染,去掉模拟手机框后的布局即真实移动端布局
|
|
53
|
+
- 查看电脑 IP:`ipconfig`(Windows)或 `ifconfig`(macOS/Linux);也可用手机扫码
|
|
54
|
+
工具条无二维码,需手动输入
|
|
55
|
+
- 手机与电脑不在同一网段、或公司防火墙限制时可能连不上,改用真机安装验证
|
|
56
|
+
|
|
57
|
+
> 注意:手机上运行的仍是 mock 宿主(WASM 后端命令、真实 WS 等依然不可用),
|
|
58
|
+
> 适合快速看布局/交互;完整能力验证仍需安装到 WasmNest Mobile。
|
|
59
|
+
|
|
60
|
+
### 手动启动(不走 CLI)
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
WASMNEST_DEV_PLUGINS="<插件目录>[::<入口文件>]" pnpm exec vite --config <dev-shell>/vite.config.ts
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
多个插件用逗号分隔(如 `a::a/src/index.ts,b::b/src/index.ts`),
|
|
67
|
+
骨架的「工具箱」会并列展示所有插件的注册项。
|
|
68
|
+
|
|
69
|
+
## 骨架提供的能力
|
|
70
|
+
|
|
71
|
+
| 区域 | 说明 |
|
|
72
|
+
|---|---|
|
|
73
|
+
| 手机框 | 390×844 手机尺寸(工作台右上角开关),关闭后全宽便于 DevTools 模拟 |
|
|
74
|
+
| 壳 · 首页 | 品牌区 + 应用贡献的快捷卡片(`registerSlot`,未贡献则平台兜底卡)+ 应用宫格 + 最近使用 |
|
|
75
|
+
| 壳 · 应用 | 内置应用与被调试插件并列;启动/停用、错误原因、权限项数、数据占用 |
|
|
76
|
+
| 壳 · 应用详情 | Hero + 状态 + 权限(按能力域分组,storage 锁定)+ 存储 + 授权记录空态 + 待审批(整单批准) + 停用/卸载 |
|
|
77
|
+
| 壳 · 运行面 | 胶囊(菜单 / 多任务 / 回主屏)+ 应用自持界面;**未注册运行面时显式空态**,不回退其它形态 |
|
|
78
|
+
| 壳 · 多任务 | 卡片轨道(Android recents 同形:并排不叠放,横向切卡 / 上滑关闭 / 点卡进入)+ 空态回主屏 |
|
|
79
|
+
| 壳 · 权限总览 | 双视图:按应用(审计主视图)/ 按权限反查(徽章流带授予状态) |
|
|
80
|
+
| 壳 · 通知栏 | 状态条 / 主屏铃铛入口;待审批(审批派生)+ 壳动作通知(启动/停止/审批/安装/卸载)+ 滑动删除 / 清除全部 |
|
|
81
|
+
| 壳 · 我的 | 权限总览入口、调试对象概览、外观(主题三档)、语言、应用贡献的设置项、清理调试数据 |
|
|
82
|
+
| 模拟终端(内置应用) | 输入发送(记录到会话输入行)、模拟输出(触发 `terminal:output` 事件,供 `openTerminalStream` mock 消费)、新建/停止会话、连接/断开、认证成功(触发对应 lifecycle);底部展示 mobileApi 任务队列 mock;并贡献一张首页快捷卡片 |
|
|
83
|
+
| 插件动态路由 | `registerRoute` + `openPage` 走 vue-router 整页跳转(`/plugin/{pluginId}/{id}`),页头由 `header` 描述符决定 |
|
|
84
|
+
| 日志面板 | `context.logger` + 生命周期 + 加载错误,右下角浮层,warn/error 过滤 |
|
|
85
|
+
| 对话框 | `context.dialogs` 全量实现(dialog/confirm/prompt/toast),移动端样式 |
|
|
86
|
+
|
|
87
|
+
## Mock 边界(与真机差异)
|
|
88
|
+
|
|
89
|
+
| API | 浏览器行为 |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `commands.execute` | 仅执行插件内 `register` 的前端 handler;**WASM 后端命令不可用**(记 warn 日志),需真机验证 |
|
|
92
|
+
| `session` / `lifecycle` | 由模拟终端页面驱动,事件名与宿主一致(`terminal` API 已随票 15 阶段 B 退役) |
|
|
93
|
+
| `storage` | localStorage 持久化(`wasmnest-dev-shell:{pluginId}:{key}`) |
|
|
94
|
+
| `fileService` | mount 为内存注册表(插件页可见);pick 系列弹输入框返回模拟路径;`getPeerInfo` 返回 null |
|
|
95
|
+
| `notifications` | 浏览器 Notification(未授权时降级 toast) |
|
|
96
|
+
| `getMobileApi()` | 完整实现,队列数据持久化到 localStorage |
|
|
97
|
+
| `getPresetTasks()` | tasks 本地持久化;`sendTask`/`executeTask` 需对端桌面端,浏览器不可用(记 warn) |
|
|
98
|
+
| 权限检查 | dev-shell 跳过(视为全部授予),权限逻辑需在真机复核 |
|
|
99
|
+
|
|
100
|
+
## 插件领域数据(devMock 协议)
|
|
101
|
+
|
|
102
|
+
上表中的 mock 都是**宿主能力**(会话/对话框/事件/HTTP 接口,固定在 dev-shell 内实现);
|
|
103
|
+
各插件自己的**业务演示数据**(队列种子、SAF 目录树、目录浏览条目)由插件入口导出 `devMock`
|
|
104
|
+
(SDK 类型 `PluginDevMock`),dev-shell 加载插件时按 pluginId 注册、`createMockContext` 按需合并:
|
|
105
|
+
|
|
106
|
+
| 字段 | 消费方 | 插件 |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| `queueSeed` | `mobileApi` 初始任务队列(localStorage 无缓存时) | wasmnest(任务域) |
|
|
109
|
+
| `safTree` | `fileService.saf.listTree` 目录树 | file-transfer |
|
|
110
|
+
| `listDirEntries` | `fileService.listDir` 返回条目(uri 由 mock 宿主拼装) | file-transfer |
|
|
111
|
+
|
|
112
|
+
- 未注册 devMock 的插件访问对应能力时返回空列表/空树(不报错),适合仅调试单插件
|
|
113
|
+
- 真实宿主忽略 `devMock` 导出(`PluginModule` 多余字段对 `activate` 无影响),无需条件编译
|
|
114
|
+
- 停用插件时 devMock 随 `registerDevMock` 的 Disposable 一并清理
|
|
115
|
+
|
|
116
|
+
## 目录结构
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
dev-shell/src/
|
|
120
|
+
├── App.vue # 舞台(工作台 + 手机框);插件路由页与壳二选一渲染
|
|
121
|
+
├── main.ts # 入口:pinia → router → i18n → 共享运行时 → 加载 → mount
|
|
122
|
+
├── loader.ts # 调试对象加载器:内置应用 + 被调试插件同一条路径
|
|
123
|
+
├── registry.ts # 调试记录 / 日志 / 插件路由注册表(壳贡献项不在这里)
|
|
124
|
+
├── mock-context.ts # mock PluginContext(UI 注册面写进壳注册表)
|
|
125
|
+
├── apps/mock-terminal/ # 内置应用「模拟终端」(自持运行面 + 首页卡片)
|
|
126
|
+
├── locales/ # devshell.* 工作台文案 + shell.* 宿主壳文案(双语)
|
|
127
|
+
└── shell/ # 与宿主壳同构的 mini 壳
|
|
128
|
+
├── types.ts # 契约(贡献描述符复用 SDK types,不重定义)
|
|
129
|
+
├── registry.ts # 应用清单 + 贡献合并 + 响应式发布
|
|
130
|
+
├── permissions.ts utils.ts logger.ts
|
|
131
|
+
├── composables/ # useShellApps / Navigation / Overlays(含通知栏) / Recent / Open / Toast / Notifications / Preferences
|
|
132
|
+
├── components/ # ShellHost · Statusbar · Capsule · PermissionPrompt · NotificationShade · 屏幕栈
|
|
133
|
+
├── adapters/ # devAppSource:调试记录 → 壳应用(数据源)
|
|
134
|
+
└── styles/shell.css # 宿主 shell.css 逐字副本(visualParity 锁)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 常见问题
|
|
138
|
+
|
|
139
|
+
- **插件样式缺失**:插件 SFC 使用宿主 Tailwind 工具类,dev-shell 的
|
|
140
|
+
tailwind.config.js 已按 `WASMNEST_DEV_PLUGINS` 动态扫描插件源码,
|
|
141
|
+
新加类名会自动生效(无需重启)。
|
|
142
|
+
- **`window.__WASMNEST_SHARED__` 未初始化**:确认经由 `wasmnest-plugin dev` 或
|
|
143
|
+
dev-shell 的 main.ts 启动,且未在入口前直接 import 插件模块。
|
|
144
|
+
- **SDK 报找不到模块**:插件工程的 `@binblink/wasmnest-plugin-sdk-mobile` 依赖指向
|
|
145
|
+
SDK 包(file: 或 npm),其 `dist` 需存在(`pnpm run build` 一次)。
|
|
146
|
+
- **真机专属能力**(WASM 命令、真实 WS、SAF 文件选择、系统通知)无法在
|
|
147
|
+
浏览器模拟,发布前仍按 `../../../docs/wasm-app-dev-mobile.md` 验证清单过真机。
|
|
148
|
+
- **应用在「应用」页点启动没反应**:dev-shell 的启动即重新跑一次插件 `activate()`;
|
|
149
|
+
若插件在 activate 期抛错,详情页会显示错误原因,日志面板同步记 error。
|
|
150
|
+
- **权限开关是灰的**:预览环境没有可写的权限真源(`setPermissionGrant` 恒返回 false),
|
|
151
|
+
权限逻辑请到真机验证。
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN" class="dark">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
6
|
+
<title>WasmNest Dev Shell</title>
|
|
7
|
+
<script>
|
|
8
|
+
// 首帧无闪烁主题:按持久化偏好 / 系统偏好预置 html.dark(默认深色)
|
|
9
|
+
;(function () {
|
|
10
|
+
try {
|
|
11
|
+
var t = localStorage.getItem('wasmnest-dev-shell:theme')
|
|
12
|
+
var dark
|
|
13
|
+
if (t === 'dark' || t === 'light') {
|
|
14
|
+
dark = t === 'dark'
|
|
15
|
+
} else {
|
|
16
|
+
dark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
17
|
+
}
|
|
18
|
+
document.documentElement.classList.toggle('dark', dark)
|
|
19
|
+
} catch (e) {}
|
|
20
|
+
})()
|
|
21
|
+
</script>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<div id="app"></div>
|
|
25
|
+
<script type="module" src="/src/main.ts"></script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@binblink/wasmnest-plugin-sdk-mobile-dev-shell",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"description": "WasmNest 移动端插件浏览器开发环境(空壳宿主 + 移动端页面骨架 + mock PluginContext)",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"preview": "vite preview"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
|
15
|
+
"autoprefixer": "^10.4.19",
|
|
16
|
+
"pinia": "^2.1.7",
|
|
17
|
+
"postcss": "^8.4.38",
|
|
18
|
+
"tailwindcss": "^3.4.1",
|
|
19
|
+
"vite": "^8.0.0",
|
|
20
|
+
"vue": "^3.4.21",
|
|
21
|
+
"vue-i18n": "^9.14.0",
|
|
22
|
+
"vue-router": "^4.3.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# 独立工程声明为最小 pnpm workspace:使 `pnpm install` 锚定本目录(不被上层/相邻
|
|
2
|
+
# workspace 吸附),并按需放行依赖构建脚本。pnpm 12 用 allowBuilds 白名单
|
|
3
|
+
# (旧 onlyBuiltDependencies 已改名);esbuild 为 vite/tsup 原生二进制所需。
|
|
4
|
+
# 本文件同时被 SDK 的 files 白名单携带,发布后支撑外部脚手架 dev-shell 独立安装。
|
|
5
|
+
packages:
|
|
6
|
+
- .
|
|
7
|
+
allowBuilds:
|
|
8
|
+
esbuild: true
|
|
9
|
+
vue-demi: true
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Dev Shell 舞台
|
|
4
|
+
*
|
|
5
|
+
* 外框(深色工作台 + 工具条)+ 手机骨架(宿主壳)。frame 开启时以 390×844 手机框
|
|
6
|
+
* 呈现(与真机尺寸一致),关闭时全宽渲染便于 DevTools 模拟。
|
|
7
|
+
*
|
|
8
|
+
* 内容区按「当前是不是插件动态路由页」二选一:
|
|
9
|
+
* · 常规(/)→ 宿主壳 `ShellView`(屏幕栈 + 底栏 + 胶囊)
|
|
10
|
+
* · 插件路由(/plugin/:pluginId/*)→ `RouterView`(插件声明的整页跳转,与宿主同构:
|
|
11
|
+
* 走 vue-router 而不是塞进壳的屏幕栈)
|
|
12
|
+
* 两者共用同一个手机视口容器,保证插件路由页的宽度/安全区表现与运行面一致。
|
|
13
|
+
*/
|
|
14
|
+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
15
|
+
import { useRoute } from 'vue-router'
|
|
16
|
+
import DevToolbar from './components/DevToolbar.vue'
|
|
17
|
+
import DialogHost from './components/DialogHost.vue'
|
|
18
|
+
import PluginGlobalDialog from '../../src/ui/PluginGlobalDialog.vue'
|
|
19
|
+
import LogPanel from './components/LogPanel.vue'
|
|
20
|
+
import ShellView from './shell/ShellView.vue'
|
|
21
|
+
import './shell/styles/shell.css'
|
|
22
|
+
import { deactivateAll } from './loader'
|
|
23
|
+
|
|
24
|
+
const frame = ref(true)
|
|
25
|
+
const logOpen = ref(false)
|
|
26
|
+
|
|
27
|
+
const route = useRoute()
|
|
28
|
+
/** 是否处于插件动态路由页(meta.pluginRoute 由 mock-context 的 registerRoute 写入) */
|
|
29
|
+
const isPluginRoute = computed(() => Boolean(route.meta.pluginRoute))
|
|
30
|
+
|
|
31
|
+
// 插件在停用/停机时注册的事件监听必须回收;浏览器关页面前没有可靠钩子,
|
|
32
|
+
// 因此在组件卸载与页面隐藏两处各撤一次(幂等)
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
window.addEventListener('beforeunload', onBeforeUnload)
|
|
35
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
onBeforeUnmount(() => {
|
|
39
|
+
window.removeEventListener('beforeunload', onBeforeUnload)
|
|
40
|
+
document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
function onBeforeUnload(): void {
|
|
44
|
+
void deactivateAll()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function onVisibilityChange(): void {
|
|
48
|
+
if (document.visibilityState === 'hidden') void deactivateAll()
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<div class="h-screen w-screen bg-[#14141a] flex flex-col overflow-hidden dev-stage">
|
|
54
|
+
<DevToolbar v-model:log-open="logOpen" :frame="frame" @toggle-frame="frame = !frame" />
|
|
55
|
+
<div class="flex-1 min-h-0 w-full flex overflow-auto p-3">
|
|
56
|
+
<div
|
|
57
|
+
v-if="frame"
|
|
58
|
+
class="phone-frame m-auto flex-shrink-0 rounded-[42px] border-[10px] border-[#2a2a33] shadow-2xl overflow-hidden"
|
|
59
|
+
:style="{ height: 'var(--dev-shell-frame-h)' }"
|
|
60
|
+
>
|
|
61
|
+
<div class="phone-screen h-full w-[390px] mobile-app mobile-ui">
|
|
62
|
+
<RouterView v-if="isPluginRoute" />
|
|
63
|
+
<ShellView v-else />
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
<div v-else class="dev-shell-app h-full w-full max-w-2xl m-auto mobile-app mobile-ui">
|
|
67
|
+
<RouterView v-if="isPluginRoute" />
|
|
68
|
+
<ShellView v-else />
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<!-- 全局浮层(Teleport to body) -->
|
|
74
|
+
<DialogHost />
|
|
75
|
+
<PluginGlobalDialog />
|
|
76
|
+
<LogPanel v-model:log-open="logOpen" />
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<style scoped>
|
|
80
|
+
.dev-stage {
|
|
81
|
+
user-select: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* 手机框内 / 全宽模式:压过宿主 mobile-app 的 min-height:100dvh,否则显式高度被撑破,
|
|
85
|
+
底部(导航栏)超出舞台被裁切 */
|
|
86
|
+
.phone-screen,
|
|
87
|
+
.dev-shell-app {
|
|
88
|
+
min-height: 0 !important;
|
|
89
|
+
}
|
|
90
|
+
</style>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* 会话状态磁贴(内置应用贡献给平台首页的快捷卡片)
|
|
4
|
+
*
|
|
5
|
+
* 用来在预览环境里真实跑通 `registerSlot` 这条路径:壳的首页会渲染应用注册的卡片
|
|
6
|
+
* 组件,插件开发者在这里能确认自己的 slot 组件在壳的布局里表现如何(而不是自己
|
|
7
|
+
* 搭一个假首页去验)。
|
|
8
|
+
*
|
|
9
|
+
* 卡片内容由应用自持(壳只传 app 上下文,不解释「N 个会话」是什么);
|
|
10
|
+
* 应用自带的卡片也不负责打开应用——打开由壳的宫格 / 列表承担。
|
|
11
|
+
*/
|
|
12
|
+
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
13
|
+
import { sessions } from '../../mock/session'
|
|
14
|
+
|
|
15
|
+
/** 壳透传的应用上下文(本卡不消费,留着是为了与 slot 契约一致) */
|
|
16
|
+
defineProps<{ app?: { id: string; name: string } }>()
|
|
17
|
+
|
|
18
|
+
const running = ref(0)
|
|
19
|
+
|
|
20
|
+
function refresh(): void {
|
|
21
|
+
running.value = sessions.value.filter((s) => s.status === 'running').length
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const timer = setInterval(refresh, 1000)
|
|
25
|
+
onMounted(refresh)
|
|
26
|
+
onUnmounted(() => clearInterval(timer))
|
|
27
|
+
|
|
28
|
+
const hint = computed(() => `mock · ${running.value} running`)
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<div
|
|
33
|
+
class="w-full text-left rounded-[12px] border border-[var(--mobile-border)] bg-[var(--mobile-bg-card)] p-3.5"
|
|
34
|
+
:style="{ boxShadow: 'var(--mobile-card-shadow)' }"
|
|
35
|
+
>
|
|
36
|
+
<span class="flex items-center gap-1.5 text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]">
|
|
37
|
+
<span
|
|
38
|
+
class="w-1.5 h-1.5 rounded-full flex-shrink-0"
|
|
39
|
+
style="background: var(--mobile-success)"
|
|
40
|
+
aria-hidden="true"
|
|
41
|
+
/>
|
|
42
|
+
mock-terminal
|
|
43
|
+
</span>
|
|
44
|
+
<span class="mt-1.5 block text-[var(--font-size-base)] font-semibold text-[var(--mobile-text-primary)]">
|
|
45
|
+
{{ running }} sessions
|
|
46
|
+
</span>
|
|
47
|
+
<span class="mt-1 block text-[var(--font-size-xs)] text-[var(--mobile-text-secondary)]">
|
|
48
|
+
{{ hint }}
|
|
49
|
+
</span>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|