feat(update): 应用内更新(检查/下载/安装)与发版流程;版本 1.2.0

- 工具栏新增检查更新按钮:启动静默检查,发现新版本时显示红色角标;
  未检测到新版本或安装包时弹窗提示「当前已是最新版本」
- 更新源:Gitea Releases(说明 = Release 正文 Markdown;安装包 = 附件,
  不进入 git 历史,仓库保持精简)
- 安卓:下载 APK → FileProvider + 系统安装器直接覆盖安装(签名一致)
- Windows:下载绿色版 zip → 解压 → 生成替换脚本,主程序退出后原地覆盖并自动重启
- 新增 lib/update/update_service.dart、lib/ui/update_dialog.dart、lib/version.dart
- 安卓侧:REQUEST_INSTALL_PACKAGES + FileProvider + installApk/getCacheDir 通道 + androidx.core
- 发版工具:scripts/publish_release.ps1(打包 dist、创建 Release、上传附件)
- 测试:test/update_version_test.dart(版本比较 4 组);启动检查在测试环境自动跳过
- 版本号 1.2.0+12;BUILD-NOTES 补充应用内更新与发版流程
This commit is contained in:
2026-10-08 21:08:18 +08:00
parent 91c6132ef9
commit 0ce50d4b8d
15 changed files with 814 additions and 7 deletions
+12
View File
@@ -3,6 +3,8 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<!-- 应用内更新:允许拉起系统安装器安装新版本 APK(Android 8.0+)。 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application
android:label="时序图设计"
android:name="${applicationName}"
@@ -29,6 +31,16 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- 应用内更新:把缓存目录中的新版本 APK 以 content:// 提供给系统安装器。 -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
@@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import androidx.core.content.FileProvider
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
@@ -81,6 +82,22 @@ class MainActivity : FlutterActivity() {
}
}
}
"getCacheDir" -> {
result.success(cacheDir.absolutePath)
}
"installApk" -> {
val path = call.argument<String>("path")
if (path == null) {
result.error("ARGS", "path required", null)
} else {
try {
installApk(path)
result.success(true)
} catch (e: Exception) {
result.error("INSTALL", e.message, null)
}
}
}
else -> result.notImplemented()
}
}
@@ -200,4 +217,17 @@ class MainActivity : FlutterActivity() {
)
return if (f.exists()) f.readBytes() else null
}
/** 应用内更新:拉起系统安装器安装缓存目录中的新版本 APK。 */
private fun installApk(path: String) {
val file = File(path)
if (!file.exists()) throw IllegalStateException("APK not found: $path")
val uri = FileProvider.getUriForFile(this, "$packageName.fileprovider", file)
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "application/vnd.android.package-archive")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 应用内更新:FileProvider 暴露缓存目录中的新版本 APK,供系统安装器读取。 -->
<paths>
<cache-path name="cache" path="." />
<files-path name="files" path="." />
<external-files-path name="external" path="." />
</paths>