v1.3.2 #10

Merged
timi merged 1 commits from release/1.3.2 into master 2026-11-17 03:55:52 +00:00
5 changed files with 124 additions and 10 deletions
+6
View File
@@ -19,6 +19,12 @@ CI 规则(.gitea/workflows/release.yml):
需要更正请发补丁版本
-->
## v1.3.2
### 调整
- 应用内支持下载并安装新的安装包,按提示覆盖安装即可,账号和已有数据都会保留
## v1.3.1
### 新增
+30 -3
View File
@@ -40,7 +40,10 @@ grep versionCode android/app/build.gradle
- 增删插件后执行 `pnpm exec cap sync android`
- 确认 `capacitor.config.ts` 无遗漏
- 本地 `pnpm run android:apk` 打一个包,装机自测
- 用 Android Studio 打包,**签名必须与线上包一致**:线上 1.0.0 用的是
`twa/android.keystore`(alias `gao-customer`,证书 `CN=yeyu` / SHA-256 `3E:9C:CC:8A:…`)。
签名不一致时系统会拒绝覆盖安装,老用户只能卸载重装
- `pnpm run android:apk` 走的是 `assembleDebug`,签的是本机 debug key,**不能用于发版**
### 3. 提高 CI 的兼容基线
@@ -52,14 +55,38 @@ APP_MIN_VERSION_CODE = <第 1 步的新 versionCode>
**这一步最容易漏**。漏了不会报错,只会在老壳用户那里悄悄出问题。
注意顺序:一旦抬高,此后创建的 BUNDLE 记录都会带上新的下限,老壳再也拿不到。
要给老壳发过渡补丁包,必须**先发补丁、再抬基线**。
### 4. 发布原生包
用同一个 versionCode 发一条 `kind = NATIVE` 的发布记录并上线。老壳用户打开 App 会收到强制更新提示,装完才有新壳。
用同一个 versionCode 发一条 `kind = NATIVE` 的发布记录并上线。通道是单指针,这条记录一上线,
热更就停止下发——老壳拿到的 `check` 响应会带 `shell: true` 和安装包地址,新壳因为
`versionCode` 已达标则什么都不下发。所以新壳装完后必须把通道切回最新的 BUNDLE 记录。
### 客户端怎么升级外壳
外壳是 APK,热更(JS)改不了它,所以升级动作分两步:
1. 服务端在 `check` 响应里带 `shell: true`(`AppUpdateCheckResponse.shell`),客户端据此走安装包分支。
**这个字段不能叫 `kind`**:Capgo 插件把 `kind` 当作错误响应标记。
2. 客户端把安装包地址交给系统浏览器(`location.assign`)——Capacitor 对非同源地址走
`Bridge.launchIntent`,用 `ACTION_VIEW` 外抛。下载和安装由浏览器发起,应用不需要
`REQUEST_INSTALL_PACKAGES`,所以 1.0.0 老壳也能用。
要做到「App 内下载、直接拉起安装器」才需要原生改动:`REQUEST_INSTALL_PACKAGES` 权限 +
FileProvider + `ACTION_VIEW` 指向本地 APK,那是下一个壳的事。
### 5. 验证
```bash
# 老壳应被拦住(version_code 填上一版的 code)
# 通道指向 NATIVE 时:老壳应拿到安装包,新壳应无更新
curl -X POST <API>/app/update/check \
-H "Content-Type: application/json" \
-d '{"platform":"android","app_id":"com.imyeyu.gao.customer","version_name":"<当前版本>","version_code":"<旧 code>","device_id":"test"}'
# 期望:shell = true,url 指向 APK
# 通道切回 BUNDLE 后:低于 minVersionCode 的老壳应被拦住
curl -X POST <API>/app/update/check \
-H "Content-Type: application/json" \
-d '{"platform":"android","app_id":"com.imyeyu.gao.customer","version_name":"<当前版本>","version_code":"<旧 code>","device_id":"test"}'
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "gao-customer-h5",
"private": true,
"version": "1.3.1",
"version": "1.3.2",
"type": "module",
"scripts": {
"dev": "vite --host",
+64 -5
View File
@@ -12,10 +12,13 @@ export const APP_ID = "com.imyeyu.gao.customer";
/**
* 服务端下发的更新信息
*
* 在插件协议基础上多一个 note:更新说明由后端附加,插件不识别但会原样透传
* 在插件协议基础上多三个字段,插件不识别但会原样透传:
* note 是更新说明,shell 标记产物为安装包(外壳),mandatory 标记强制更新
*/
export type UpdateInfo = LatestVersion & {
note?: string;
shell?: boolean;
mandatory?: boolean;
};
// 模块级状态,页面与启动逻辑共享同一份
@@ -65,10 +68,34 @@ async function check(): Promise<UpdateInfo | null> {
}
}
/** 是否发现新版本 */
/** 是否发现新版本(外壳更新不看版本号,只认服务端下发的地址) */
function hasUpdate(): boolean {
const target = latest.value;
return Boolean(target?.url) && target?.version !== currentVersion.value;
if (!target?.url) {
return false;
}
return Boolean(target.shell) || target.version !== currentVersion.value;
}
/** 是否为外壳更新,只能下载安装包覆盖安装,热更装不进去 */
function isShellUpdate(): boolean {
const target = latest.value;
return Boolean(target?.shell && target?.url);
}
/**
* 把安装包交给系统浏览器下载
*
* Capacitor 对非同源地址走 Bridge.launchIntent,用 ACTION_VIEW 外抛给浏览器,
* 安装动作由浏览器和系统安装器发起,应用自身不需要安装权限,所以老壳也能用
*/
function openShellDownload(): void {
const target = latest.value;
if (!target?.url) {
error.value = "没有可下载的版本";
return;
}
window.location.assign(target.url);
}
/** 下载最新版本,只落盘不激活 */
@@ -78,6 +105,10 @@ async function download(): Promise<BundleInfo | null> {
error.value = "没有可下载的版本";
return null;
}
if (target.shell) {
error.value = "外壳更新需要下载安装包";
return null;
}
downloading.value = true;
percent.value = 0;
error.value = "";
@@ -149,6 +180,8 @@ export function useAppUpdate() {
loadCurrent,
check,
hasUpdate,
isShellUpdate,
openShellDownload,
download,
apply,
defer,
@@ -186,11 +219,33 @@ function promptUpdate(bundle: BundleInfo): void {
});
}
/**
* 弹窗引导下载安装包
*
* 外壳更新装不进热更,只能走浏览器下载后覆盖安装;强制更新不给「稍后」按钮
*/
function promptShellUpdate(info: UpdateInfo): void {
const dialog = DialogPlugin.confirm({
title: "需要安装新版本",
content: `v${info.version} 是应用外壳更新,需要下载安装包覆盖安装`,
cancelBtn: info.mandatory ? null : "稍后",
confirmBtn: "下载安装包",
onCancel() {
dialog.destroy();
},
onConfirm() {
dialog.destroy();
openShellDownload();
}
});
}
/**
* 启动时检查更新
*
* 检查每次启动都做;是否静默下载取决于自动更新开关
* 下载完成后弹窗让用户选择立即重启还是稍后
* 外壳更新优先处理:热更包是 JS,装不进旧壳
*/
export async function runAutoUpdate(): Promise<void> {
if (!supported) {
@@ -205,10 +260,14 @@ export async function runAutoUpdate(): Promise<void> {
return;
}
const result = await check();
if (!result?.url || result.version === currentVersion.value) {
if (!result?.url) {
return;
}
if (!isAutoUpdateEnabled()) {
if (result.shell) {
promptShellUpdate(result);
return;
}
if (result.version === currentVersion.value || !isAutoUpdateEnabled()) {
return;
}
await download();
+23 -1
View File
@@ -33,6 +33,15 @@
>
检查更新
</t-button>
<t-button
v-else-if="updateStage === 'shell'"
class="cell-button"
theme="primary"
size="large"
@click="handleShellDownload"
>
下载安装包
</t-button>
<t-button
v-else-if="updateStage === 'download'"
class="cell-button"
@@ -143,6 +152,8 @@ const {
loadCurrent,
check,
hasUpdate,
isShellUpdate,
openShellDownload,
download,
apply,
restorePending
@@ -157,7 +168,10 @@ const displayVersion = computed<string>(
const latestVersionText = computed<string>(() => (hasUpdate() ? `v${latest.value?.version ?? ""}` : ""));
/** 当前所处的更新阶段 */
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
const updateStage = computed<"check" | "shell" | "download" | "downloading" | "apply">(() => {
if (isShellUpdate()) {
return "shell";
}
if (downloading.value) {
return "downloading";
}
@@ -175,6 +189,9 @@ const updateHint = computed<string>(() => {
if (!updateSupported) {
return "仅在 App 内可用";
}
if (isShellUpdate()) {
return `发现新版本 v${latest.value?.version ?? ""},需要下载安装包覆盖安装`;
}
if (ready.value) {
return `v${ready.value.version} 已下载,点击下方按钮重启生效`;
}
@@ -241,6 +258,11 @@ async function handleCheck(): Promise<void> {
await loadNotes();
}
/** 外壳更新:交给系统浏览器下载安装包 */
function handleShellDownload(): void {
openShellDownload();
}
async function handleDownload(): Promise<void> {
const bundle = await download();
if (!bundle) {