@binblink/wasmnest-plugin-sdk-mobile 0.0.1 → 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 +78 -2
- package/README_en.md +64 -2
- package/bin/build.js +4 -2
- package/bin/manifest-gen.js +3 -0
- package/bin/package.js +2 -1
- package/bin/scaffold.js +22 -8
- package/dev-shell/README.md +1 -1
- package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +13 -21
- package/dev-shell/src/locales/en-shell.ts +6 -2
- package/dev-shell/src/locales/shell.ts +5 -2
- package/dev-shell/src/mock-context.ts +28 -5
- package/dev-shell/src/shell/adapters/devAppSource.ts +2 -13
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +22 -17
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +16 -35
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +58 -17
- package/dev-shell/src/shell/composables/useShellApps.ts +5 -3
- package/dev-shell/src/shell/composables/useShellOpen.ts +12 -3
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +340 -26
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +17 -2
- package/dev-shell/src/styles/mobile.css +981 -884
- package/dist/index.d.ts +44 -4
- package/dist/index.js +69 -1
- package/dist/types.d.ts +107 -6
- package/package.json +9 -1
- package/src/index.ts +9 -0
- package/src/types.ts +822 -715
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/update.ts +123 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
import type { AppUpdateCheckResult } from '../types'
|
|
3
|
+
|
|
4
|
+
/** 默认更新卡片文案(应用可覆盖任意字段;`{version}` 由组件替换) */
|
|
5
|
+
export interface AppUpdateLabels {
|
|
6
|
+
title: string
|
|
7
|
+
check: string
|
|
8
|
+
checking: string
|
|
9
|
+
upToDate: string
|
|
10
|
+
available: string
|
|
11
|
+
incompatible: string
|
|
12
|
+
failed: string
|
|
13
|
+
unsupported: string
|
|
14
|
+
reasonNoCompat: string
|
|
15
|
+
reasonMountContract: string
|
|
16
|
+
reasonHostRuntime: string
|
|
17
|
+
reasonHostRuntimeInvalid: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** AppUpdateSection 组件 props */
|
|
21
|
+
export interface AppUpdateSectionProps {
|
|
22
|
+
/** 当前版本(可选;不传时用检查结果的 currentVersion) */
|
|
23
|
+
currentVersion?: string
|
|
24
|
+
/** 自定义检查器;缺省使用宿主 `PluginContext.appUpdate.check` */
|
|
25
|
+
check?: () => Promise<AppUpdateCheckResult>
|
|
26
|
+
/** 文案覆盖(缺省按系统语言内置中 / 英) */
|
|
27
|
+
labels?: Partial<AppUpdateLabels>
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 应用更新检查卡片(SDK 默认实现)
|
|
33
|
+
*
|
|
34
|
+
* 用法(应用设置页直接嵌入):
|
|
35
|
+
* ```vue
|
|
36
|
+
* <AppUpdateSection />
|
|
37
|
+
* ```
|
|
38
|
+
* - 数据面 = 宿主 `PluginContext.appUpdate.check`(GitHub Release 统一判定)
|
|
39
|
+
* - 应用自实现更新检查时传 `check` 覆盖,或完全不用本组件
|
|
40
|
+
* - 更新动作统一在宿主应用管理页执行(需停用应用 + 换目录 + 重新审批)
|
|
41
|
+
*/
|
|
42
|
+
export declare const AppUpdateSection: DefineComponent<AppUpdateSectionProps>
|
|
43
|
+
|
|
44
|
+
export default AppUpdateSection
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
应用更新检查(SDK 默认实现)
|
|
4
|
+
|
|
5
|
+
应用设置页直接嵌入即可:宿主提供 GitHub Release 判定,本组件只负责状态与
|
|
6
|
+
展示。应用想自实现时不必使用本组件(或传 `check` 覆盖数据面)。
|
|
7
|
+
-->
|
|
8
|
+
<section class="wasmnest-update" data-testid="sdk-app-update">
|
|
9
|
+
<div class="wasmnest-update__row">
|
|
10
|
+
<div class="wasmnest-update__main">
|
|
11
|
+
<span v-if="text.title" class="wasmnest-update__title">{{ text.title }}</span>
|
|
12
|
+
<span v-if="versionLabel" class="wasmnest-update__version">{{ versionLabel }}</span>
|
|
13
|
+
</div>
|
|
14
|
+
<button
|
|
15
|
+
type="button"
|
|
16
|
+
class="wasmnest-update__button"
|
|
17
|
+
:disabled="disabled || checking || !supported"
|
|
18
|
+
:aria-busy="checking"
|
|
19
|
+
data-testid="sdk-app-update-check"
|
|
20
|
+
@click="onCheck"
|
|
21
|
+
>
|
|
22
|
+
{{ checking ? text.checking : text.check }}
|
|
23
|
+
</button>
|
|
24
|
+
</div>
|
|
25
|
+
<p
|
|
26
|
+
v-if="statusLabel"
|
|
27
|
+
class="wasmnest-update__status"
|
|
28
|
+
:class="{ 'is-error': isBad, 'is-available': status === 'available' }"
|
|
29
|
+
data-testid="sdk-app-update-status"
|
|
30
|
+
>
|
|
31
|
+
{{ statusLabel }}
|
|
32
|
+
</p>
|
|
33
|
+
<p
|
|
34
|
+
v-if="reasonLabel"
|
|
35
|
+
class="wasmnest-update__status is-error"
|
|
36
|
+
data-testid="sdk-app-update-reason"
|
|
37
|
+
>
|
|
38
|
+
{{ reasonLabel }}
|
|
39
|
+
</p>
|
|
40
|
+
</section>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
/**
|
|
45
|
+
* AppUpdateSection — SDK 默认应用更新卡片(双端同形)
|
|
46
|
+
*
|
|
47
|
+
* 数据面:`PluginContext.appUpdate.check`(宿主统一实现)或调用方传入的 `check`
|
|
48
|
+
* (应用自实现)。状态机在 `useAppUpdate`;本组件只做展示,不发起安装——
|
|
49
|
+
* 更新动作统一收口在宿主应用管理页(需要先停用应用、替换插件目录并重新审批)。
|
|
50
|
+
*
|
|
51
|
+
* 视觉:只依赖 `--mobile-*` / 桌面 `--bg-card` 等 token 的回退组合,不引入
|
|
52
|
+
* 任何一端专属组件;应用可在外层继续套自己的卡片样式。
|
|
53
|
+
*/
|
|
54
|
+
import { computed } from 'vue'
|
|
55
|
+
import { useAppUpdate } from '../update'
|
|
56
|
+
import type { AppUpdateCheckResult } from '../types'
|
|
57
|
+
|
|
58
|
+
/** 文案包(应用可覆盖任意字段;`{version}` 由组件替换) */
|
|
59
|
+
export interface AppUpdateLabels {
|
|
60
|
+
title: string
|
|
61
|
+
check: string
|
|
62
|
+
checking: string
|
|
63
|
+
upToDate: string
|
|
64
|
+
available: string
|
|
65
|
+
incompatible: string
|
|
66
|
+
failed: string
|
|
67
|
+
unsupported: string
|
|
68
|
+
reasonNoCompat: string
|
|
69
|
+
reasonMountContract: string
|
|
70
|
+
reasonHostRuntime: string
|
|
71
|
+
reasonHostRuntimeInvalid: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const props = withDefaults(
|
|
75
|
+
defineProps<{
|
|
76
|
+
/** 当前版本(可选;不传时用检查结果的 currentVersion) */
|
|
77
|
+
currentVersion?: string
|
|
78
|
+
/** 自定义检查器;缺省使用宿主 `PluginContext.appUpdate.check` */
|
|
79
|
+
check?: () => Promise<AppUpdateCheckResult>
|
|
80
|
+
/** 文案覆盖(缺省按系统语言内置中 / 英) */
|
|
81
|
+
labels?: Partial<AppUpdateLabels>
|
|
82
|
+
disabled?: boolean
|
|
83
|
+
}>(),
|
|
84
|
+
{ currentVersion: '', check: undefined, labels: undefined, disabled: false },
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const ZH: AppUpdateLabels = {
|
|
88
|
+
title: '版本更新',
|
|
89
|
+
check: '检查更新',
|
|
90
|
+
checking: '正在检查…',
|
|
91
|
+
upToDate: '已是最新版本(v{version})',
|
|
92
|
+
available: '发现新版本 v{version};请在应用管理中更新',
|
|
93
|
+
incompatible: '发现新版本 v{version},但与当前平台不兼容',
|
|
94
|
+
failed: '检查失败,请稍后重试',
|
|
95
|
+
unsupported: '当前平台不提供更新检查',
|
|
96
|
+
reasonNoCompat: '该发布物缺少兼容声明(旧版发布格式),无法确认与当前平台兼容',
|
|
97
|
+
reasonMountContract: '要求挂载契约 {required},当前平台为 {current}',
|
|
98
|
+
reasonHostRuntime: '要求宿主运行时 {required},当前为 {current};请先升级平台',
|
|
99
|
+
reasonHostRuntimeInvalid: '兼容声明版本形态异常({required}),已拒绝',
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const EN: AppUpdateLabels = {
|
|
103
|
+
title: 'Version update',
|
|
104
|
+
check: 'Check for updates',
|
|
105
|
+
checking: 'Checking…',
|
|
106
|
+
upToDate: 'Up to date (v{version})',
|
|
107
|
+
available: 'v{version} available; update it in App Management',
|
|
108
|
+
incompatible: 'v{version} found, but it is incompatible with this platform',
|
|
109
|
+
failed: 'Update check failed, try again later',
|
|
110
|
+
unsupported: 'Update check is not available on this platform',
|
|
111
|
+
reasonNoCompat:
|
|
112
|
+
'The release lacks a compatibility declaration (legacy format); compatibility cannot be confirmed',
|
|
113
|
+
reasonMountContract: 'Requires mount contract {required}; this platform is {current}',
|
|
114
|
+
reasonHostRuntime:
|
|
115
|
+
'Requires host runtime {required}; this platform is {current}. Upgrade the platform first',
|
|
116
|
+
reasonHostRuntimeInvalid: 'Malformed compatibility version ({required}); refused',
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const text = computed<AppUpdateLabels>(() => {
|
|
120
|
+
const isZh = typeof navigator !== 'undefined' && navigator.language.toLowerCase().startsWith('zh')
|
|
121
|
+
return { ...(isZh ? ZH : EN), ...(props.labels ?? {}) }
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const {
|
|
125
|
+
status,
|
|
126
|
+
latestVersion,
|
|
127
|
+
currentVersion,
|
|
128
|
+
reason,
|
|
129
|
+
checking,
|
|
130
|
+
supported,
|
|
131
|
+
check: runCheck,
|
|
132
|
+
} = useAppUpdate({ check: props.check })
|
|
133
|
+
|
|
134
|
+
const versionLabel = computed(() => {
|
|
135
|
+
const v = props.currentVersion || currentVersion.value
|
|
136
|
+
return v ? `v${v}` : ''
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
function fill(template: string, params: Record<string, string | undefined>): string {
|
|
140
|
+
return template.replace(/\{(\w+)\}/g, (_, key: string) => params[key] ?? '')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const statusLabel = computed(() => {
|
|
144
|
+
if (!supported.value) return text.value.unsupported
|
|
145
|
+
switch (status.value) {
|
|
146
|
+
case 'checking':
|
|
147
|
+
return text.value.checking
|
|
148
|
+
case 'up-to-date':
|
|
149
|
+
return fill(text.value.upToDate, {
|
|
150
|
+
version: latestVersion.value || currentVersion.value || '',
|
|
151
|
+
})
|
|
152
|
+
case 'available':
|
|
153
|
+
return fill(text.value.available, { version: latestVersion.value || '' })
|
|
154
|
+
case 'incompatible':
|
|
155
|
+
return fill(text.value.incompatible, { version: latestVersion.value || '' })
|
|
156
|
+
case 'error':
|
|
157
|
+
return text.value.failed
|
|
158
|
+
default:
|
|
159
|
+
return ''
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const isBad = computed(() => status.value === 'error' || status.value === 'incompatible')
|
|
164
|
+
|
|
165
|
+
const reasonLabel = computed(() => {
|
|
166
|
+
const r = reason.value
|
|
167
|
+
if (!r) return ''
|
|
168
|
+
const params = { ...(r.params ?? {}), version: latestVersion.value }
|
|
169
|
+
if (r.key.endsWith('noCompat')) return text.value.reasonNoCompat
|
|
170
|
+
if (r.key.endsWith('mountContract')) return fill(text.value.reasonMountContract, params)
|
|
171
|
+
if (r.key.endsWith('hostRuntimeInvalid')) return fill(text.value.reasonHostRuntimeInvalid, params)
|
|
172
|
+
if (r.key.endsWith('hostRuntime')) return fill(text.value.reasonHostRuntime, params)
|
|
173
|
+
return ''
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
function onCheck(): void {
|
|
177
|
+
void runCheck()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
defineExpose({ check: runCheck })
|
|
181
|
+
</script>
|
|
182
|
+
|
|
183
|
+
<style scoped>
|
|
184
|
+
.wasmnest-update {
|
|
185
|
+
border: 1px solid var(--mobile-border, var(--border, rgba(127, 127, 127, 0.28)));
|
|
186
|
+
background: var(--mobile-bg-card, var(--bg-card, transparent));
|
|
187
|
+
border-radius: var(--mobile-radius-lg, 12px);
|
|
188
|
+
padding: 10px 12px;
|
|
189
|
+
display: flex;
|
|
190
|
+
flex-direction: column;
|
|
191
|
+
gap: 6px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.wasmnest-update__row {
|
|
195
|
+
display: flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
gap: 10px;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.wasmnest-update__main {
|
|
201
|
+
flex: 1;
|
|
202
|
+
min-width: 0;
|
|
203
|
+
display: flex;
|
|
204
|
+
align-items: baseline;
|
|
205
|
+
gap: 8px;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.wasmnest-update__title {
|
|
209
|
+
font-size: 14px;
|
|
210
|
+
font-weight: 600;
|
|
211
|
+
color: var(--mobile-text-primary, var(--text-primary, inherit));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.wasmnest-update__version {
|
|
215
|
+
font-size: 12px;
|
|
216
|
+
color: var(--mobile-text-secondary, var(--text-secondary, #888));
|
|
217
|
+
font-variant-numeric: tabular-nums;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.wasmnest-update__button {
|
|
221
|
+
flex-shrink: 0;
|
|
222
|
+
min-height: var(--mobile-touch-target-min, 32px);
|
|
223
|
+
padding: 0 12px;
|
|
224
|
+
border-radius: var(--mobile-radius-md, 8px);
|
|
225
|
+
border: 1px solid var(--mobile-border, var(--border, rgba(127, 127, 127, 0.28)));
|
|
226
|
+
background: transparent;
|
|
227
|
+
color: var(--mobile-accent, var(--brand, #4f8cff));
|
|
228
|
+
font-size: 12px;
|
|
229
|
+
font-weight: 600;
|
|
230
|
+
cursor: pointer;
|
|
231
|
+
transition: opacity 0.2s ease;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.wasmnest-update__button:disabled {
|
|
235
|
+
opacity: 0.5;
|
|
236
|
+
cursor: not-allowed;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.wasmnest-update__status {
|
|
240
|
+
margin: 0;
|
|
241
|
+
font-size: 12px;
|
|
242
|
+
line-height: 1.5;
|
|
243
|
+
color: var(--mobile-text-secondary, var(--text-secondary, #888));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.wasmnest-update__status.is-available {
|
|
247
|
+
color: var(--mobile-accent, var(--brand, #4f8cff));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.wasmnest-update__status.is-error {
|
|
251
|
+
color: var(--mobile-error, var(--danger, #e5484d));
|
|
252
|
+
}
|
|
253
|
+
</style>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** 卡片状态点语义(neutral 不显示) */
|
|
4
|
+
export type QuickCardTone = 'neutral' | 'success' | 'warning' | 'danger'
|
|
5
|
+
|
|
6
|
+
/** QuickCard 组件 props */
|
|
7
|
+
export interface QuickCardProps {
|
|
8
|
+
/** 顶部标签(如「活跃会话」);留空则只显示主体 */
|
|
9
|
+
label?: string
|
|
10
|
+
/** 主体数值 / 主文案(等宽数字排版) */
|
|
11
|
+
value?: string | number
|
|
12
|
+
/** 数值下方的一行状态说明(零值提示、补充信息等) */
|
|
13
|
+
hint?: string
|
|
14
|
+
/** 右上角装饰图标:24×24 视框的 SVG path d,可多条 */
|
|
15
|
+
iconPath?: string | string[]
|
|
16
|
+
/** 状态点语义:neutral 不显示;其余取对应语义色 */
|
|
17
|
+
tone?: QuickCardTone
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 移动端公共快捷卡片(宿主壳首页)
|
|
22
|
+
*
|
|
23
|
+
* 用法(应用 activate 期注册,宿主壳首页渲染并负责点击跳转):
|
|
24
|
+
* ```vue
|
|
25
|
+
* <QuickCard label="活跃会话" :value="count" :hint="count ? '正在运行' : '暂无会话'" />
|
|
26
|
+
* ```
|
|
27
|
+
* - 卡片内容由应用自持;宿主管布局、滚动与点击打开本应用,应用不处理导航
|
|
28
|
+
* - 卡片内不得再放按钮 / 链接(整卡已是宿主按钮,嵌套交互会互相抢点击)
|
|
29
|
+
* - 外观由 --mobile-* / --shell-radius-* token 驱动,跟随宿主主题与字号偏好
|
|
30
|
+
*/
|
|
31
|
+
export declare const QuickCard: DefineComponent<QuickCardProps>
|
|
32
|
+
|
|
33
|
+
export default QuickCard
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
快捷卡片(应用贡献给宿主壳首页的公共卡片外观)
|
|
4
|
+
|
|
5
|
+
只负责「卡片长什么样」:应用填内容(label / value / hint 或默认插槽),
|
|
6
|
+
点击与跳转由宿主壳接管——宿主把整张卡渲染成按钮并打开贡献方应用。
|
|
7
|
+
因此卡片内不得再放按钮 / 链接等交互控件(会与宿主按钮形成嵌套交互)。
|
|
8
|
+
-->
|
|
9
|
+
<article class="quick-card" :data-tone="tone">
|
|
10
|
+
<header v-if="label || iconPaths.length > 0 || tone !== 'neutral'" class="quick-card__head">
|
|
11
|
+
<span
|
|
12
|
+
v-if="tone !== 'neutral'"
|
|
13
|
+
class="quick-card__tone"
|
|
14
|
+
:data-tone="tone"
|
|
15
|
+
aria-hidden="true"
|
|
16
|
+
/>
|
|
17
|
+
<span v-if="label" class="quick-card__label">{{ label }}</span>
|
|
18
|
+
<span v-if="iconPaths.length > 0" class="quick-card__icon" aria-hidden="true">
|
|
19
|
+
<svg
|
|
20
|
+
width="18"
|
|
21
|
+
height="18"
|
|
22
|
+
viewBox="0 0 24 24"
|
|
23
|
+
fill="none"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
stroke-width="1.7"
|
|
26
|
+
stroke-linecap="round"
|
|
27
|
+
stroke-linejoin="round"
|
|
28
|
+
>
|
|
29
|
+
<path v-for="d in iconPaths" :key="d" :d="d" />
|
|
30
|
+
</svg>
|
|
31
|
+
</span>
|
|
32
|
+
</header>
|
|
33
|
+
|
|
34
|
+
<div class="quick-card__body">
|
|
35
|
+
<slot>
|
|
36
|
+
<span v-if="hasValue" class="quick-card__value">{{ value }}</span>
|
|
37
|
+
<span v-if="hint" class="quick-card__hint">{{ hint }}</span>
|
|
38
|
+
</slot>
|
|
39
|
+
</div>
|
|
40
|
+
</article>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
/**
|
|
45
|
+
* QuickCard — SDK 公共快捷卡片
|
|
46
|
+
*
|
|
47
|
+
* 内容由应用自持(活跃会话数 / 传输任务数 / 最近对话……),宿主不解释字段语义;
|
|
48
|
+
* 卡片固定外观由 --mobile-* + --shell-radius-* token 驱动,随宿主主题 / 明暗 /
|
|
49
|
+
* 用户字号偏好自动适配。跨应用等宽靠宿主轨道 item 的定宽约束,本组件铺满 item。
|
|
50
|
+
*/
|
|
51
|
+
import { computed } from 'vue'
|
|
52
|
+
|
|
53
|
+
type QuickCardTone = 'neutral' | 'success' | 'warning' | 'danger'
|
|
54
|
+
|
|
55
|
+
const props = withDefaults(
|
|
56
|
+
defineProps<{
|
|
57
|
+
/** 顶部标签(如「活跃会话」);留空则只显示主体 */
|
|
58
|
+
label?: string
|
|
59
|
+
/** 主体数值 / 主文案(等宽数字排版) */
|
|
60
|
+
value?: string | number
|
|
61
|
+
/** 数值下方的一行状态说明(零值提示、补充信息等) */
|
|
62
|
+
hint?: string
|
|
63
|
+
/** 右上角装饰图标:24×24 视框的 SVG path d,可多条 */
|
|
64
|
+
iconPath?: string | string[]
|
|
65
|
+
/** 状态点语义:neutral 不显示;其余取对应语义色 */
|
|
66
|
+
tone?: QuickCardTone
|
|
67
|
+
}>(),
|
|
68
|
+
{ tone: 'neutral', label: '', value: '', hint: '', iconPath: '' },
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const iconPaths = computed(() => {
|
|
72
|
+
const raw = props.iconPath
|
|
73
|
+
if (!raw) return []
|
|
74
|
+
return Array.isArray(raw) ? raw : [raw]
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const hasValue = computed(() => props.value !== undefined && props.value !== null && props.value !== '')
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<style scoped>
|
|
81
|
+
.quick-card {
|
|
82
|
+
box-sizing: border-box;
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
gap: 8px;
|
|
86
|
+
width: 100%;
|
|
87
|
+
height: 100%;
|
|
88
|
+
min-width: 0;
|
|
89
|
+
padding: 14px;
|
|
90
|
+
border: 1px solid var(--mobile-border);
|
|
91
|
+
border-radius: var(--shell-radius-card, 12px);
|
|
92
|
+
background: var(--mobile-bg-card);
|
|
93
|
+
box-shadow: var(--mobile-card-shadow);
|
|
94
|
+
color: var(--mobile-text-primary);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.quick-card__head {
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
gap: 6px;
|
|
101
|
+
min-width: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.quick-card__label {
|
|
105
|
+
min-width: 0;
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
color: var(--mobile-text-secondary);
|
|
108
|
+
font-size: var(--font-size-xs);
|
|
109
|
+
line-height: 1.4;
|
|
110
|
+
text-overflow: ellipsis;
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.quick-card__icon {
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-shrink: 0;
|
|
117
|
+
margin-left: auto;
|
|
118
|
+
color: var(--mobile-accent);
|
|
119
|
+
opacity: 0.85;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.quick-card__tone {
|
|
123
|
+
flex-shrink: 0;
|
|
124
|
+
width: 6px;
|
|
125
|
+
height: 6px;
|
|
126
|
+
border-radius: 999px;
|
|
127
|
+
background: var(--mobile-text-secondary);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.quick-card__tone[data-tone='success'] {
|
|
131
|
+
background: var(--mobile-success);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.quick-card__tone[data-tone='warning'] {
|
|
135
|
+
background: var(--mobile-warning);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.quick-card__tone[data-tone='danger'] {
|
|
139
|
+
background: var(--mobile-error);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.quick-card__body {
|
|
143
|
+
display: flex;
|
|
144
|
+
flex-direction: column;
|
|
145
|
+
gap: 4px;
|
|
146
|
+
min-width: 0;
|
|
147
|
+
margin-top: auto;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.quick-card__value {
|
|
151
|
+
font-size: var(--font-size-2xl);
|
|
152
|
+
font-variant-numeric: tabular-nums;
|
|
153
|
+
font-weight: 600;
|
|
154
|
+
line-height: 1.15;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.quick-card__hint {
|
|
158
|
+
display: -webkit-box;
|
|
159
|
+
overflow: hidden;
|
|
160
|
+
color: var(--mobile-text-secondary);
|
|
161
|
+
font-size: var(--font-size-xs);
|
|
162
|
+
line-height: 1.45;
|
|
163
|
+
overflow-wrap: anywhere;
|
|
164
|
+
-webkit-box-orient: vertical;
|
|
165
|
+
-webkit-line-clamp: 2;
|
|
166
|
+
}
|
|
167
|
+
</style>
|
package/src/update.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用更新检查(SDK 默认实现;宿主统一提供 GitHub Release 判定)
|
|
3
|
+
*
|
|
4
|
+
* 数据面由宿主给出(`PluginContext.appUpdate.check`):宿主负责查 Release、校验
|
|
5
|
+
* 身份 / 完整性、做平台兼容裁决;本模块只做状态机与展示口径,供应用设置页复用。
|
|
6
|
+
*
|
|
7
|
+
* 应用可以选择:
|
|
8
|
+
* - **默认实现**:`useAppUpdate()` / `<AppUpdateSection />`(宿主能力 + 本模块状态);
|
|
9
|
+
* - **自实现**:自己查更新 / 自己画界面,不消费本模块。
|
|
10
|
+
*
|
|
11
|
+
* 失败口径:检查是被动动作,不向用户抛技术错误——状态落 `error`,技术详情由宿主
|
|
12
|
+
* 日志承载(应用可自行决定是否提示)。
|
|
13
|
+
*/
|
|
14
|
+
import { computed, getCurrentInstance, inject, ref, type ComputedRef, type Ref } from 'vue'
|
|
15
|
+
import type { AppUpdateAPI, AppUpdateCheckResult, AppUpdateReason, PluginContext } from './types'
|
|
16
|
+
|
|
17
|
+
/** 状态机的展示态(与宿主返回的 status 子集一致) */
|
|
18
|
+
export type AppUpdateStatus =
|
|
19
|
+
'idle' | 'checking' | 'up-to-date' | 'available' | 'incompatible' | 'error'
|
|
20
|
+
|
|
21
|
+
export interface UseAppUpdateOptions {
|
|
22
|
+
/**
|
|
23
|
+
* 自定义检查器(缺省 = 宿主 `PluginContext.appUpdate.check`)
|
|
24
|
+
*
|
|
25
|
+
* 应用自实现更新检查时传入;返回形状与宿主默认实现一致,SDK 默认卡片即可复用。
|
|
26
|
+
*/
|
|
27
|
+
check?: () => Promise<AppUpdateCheckResult>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UseAppUpdate {
|
|
31
|
+
status: Ref<AppUpdateStatus>
|
|
32
|
+
latestVersion: Ref<string | undefined>
|
|
33
|
+
currentVersion: Ref<string | undefined>
|
|
34
|
+
reason: Ref<AppUpdateReason | undefined>
|
|
35
|
+
checking: ComputedRef<boolean>
|
|
36
|
+
/** 当前平台是否提供更新检查能力(旧宿主 / dev-shell 可能没有) */
|
|
37
|
+
supported: ComputedRef<boolean>
|
|
38
|
+
/** 执行一次检查;并发调用复用同一在途请求 */
|
|
39
|
+
check: () => Promise<void>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 取宿主注入的更新能力(composable 必须在 setup 期间调用;inject 只在 setup 有上下文)
|
|
44
|
+
*
|
|
45
|
+
* 不经 SDK `getPluginContext()`:桌面挂载包没有 `__WASMNEST_SHARED__`,移动端虽有
|
|
46
|
+
* 共享运行时但取 context 的路径也不同;`inject('pluginContext')` 是双端应用都已
|
|
47
|
+
* 提供的唯一入口(桌面 appContext / 移动 PluginViewHost 同键)。
|
|
48
|
+
*/
|
|
49
|
+
function resolveHostApi(): AppUpdateAPI | undefined {
|
|
50
|
+
if (!getCurrentInstance()) return undefined
|
|
51
|
+
return inject<PluginContext | undefined>('pluginContext', undefined)?.appUpdate
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 应用更新状态机(模块内无全局单例:每个设置页实例各自持状态,避免跨应用串状态)
|
|
56
|
+
*/
|
|
57
|
+
export function useAppUpdate(options: UseAppUpdateOptions = {}): UseAppUpdate {
|
|
58
|
+
const hostApi = options.check ? undefined : resolveHostApi()
|
|
59
|
+
const checker =
|
|
60
|
+
options.check ??
|
|
61
|
+
(() => {
|
|
62
|
+
if (!hostApi) {
|
|
63
|
+
return Promise.reject(
|
|
64
|
+
new Error('[PluginSDK] app update capability is not provided by this host'),
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
return hostApi.check()
|
|
68
|
+
})
|
|
69
|
+
const status = ref<AppUpdateStatus>('idle')
|
|
70
|
+
const latestVersion = ref<string | undefined>()
|
|
71
|
+
const currentVersion = ref<string | undefined>()
|
|
72
|
+
const reason = ref<AppUpdateReason | undefined>()
|
|
73
|
+
let inFlight: Promise<void> | null = null
|
|
74
|
+
|
|
75
|
+
const supported = computed(() => Boolean(options.check || hostApi))
|
|
76
|
+
|
|
77
|
+
async function run(): Promise<void> {
|
|
78
|
+
status.value = 'checking'
|
|
79
|
+
reason.value = undefined
|
|
80
|
+
try {
|
|
81
|
+
const result = await checker()
|
|
82
|
+
currentVersion.value = result.currentVersion
|
|
83
|
+
latestVersion.value = result.latestVersion
|
|
84
|
+
reason.value = result.reason
|
|
85
|
+
switch (result.status) {
|
|
86
|
+
case 'up-to-date':
|
|
87
|
+
case 'available':
|
|
88
|
+
case 'incompatible':
|
|
89
|
+
status.value = result.status
|
|
90
|
+
break
|
|
91
|
+
case 'idle':
|
|
92
|
+
case 'checking':
|
|
93
|
+
// 宿主返回中间态没有意义(调用已返回)→ 按失败处理,不把界面钉在「检查中」
|
|
94
|
+
status.value = 'error'
|
|
95
|
+
break
|
|
96
|
+
default:
|
|
97
|
+
status.value = 'error'
|
|
98
|
+
}
|
|
99
|
+
} catch {
|
|
100
|
+
status.value = 'error'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function check(): Promise<void> {
|
|
105
|
+
if (!inFlight) {
|
|
106
|
+
const pending = run().finally(() => {
|
|
107
|
+
if (inFlight === pending) inFlight = null
|
|
108
|
+
})
|
|
109
|
+
inFlight = pending
|
|
110
|
+
}
|
|
111
|
+
return inFlight
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
status,
|
|
116
|
+
latestVersion,
|
|
117
|
+
currentVersion,
|
|
118
|
+
reason,
|
|
119
|
+
checking: computed(() => status.value === 'checking'),
|
|
120
|
+
supported,
|
|
121
|
+
check,
|
|
122
|
+
}
|
|
123
|
+
}
|