Compare commits
8
Commits
76990f2c41
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f9ce7aed8 | ||
|
|
5dae8385a0 | ||
|
|
ed290f3d7d | ||
|
|
69b83a2f20 | ||
|
|
fbd5d5bd2c | ||
|
|
315db320a7 | ||
|
|
d317ede90d | ||
|
|
c326b11163 |
@@ -29,6 +29,7 @@ render.experimental.xml
|
||||
# Keystore files
|
||||
*.jks
|
||||
*.keystore
|
||||
keystore.properties
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
google-services.json
|
||||
|
||||
@@ -1,3 +1,151 @@
|
||||
# 2FAir
|
||||
|
||||
2FA令牌管理器
|
||||
2FA 令牌管理器(两步验证 / 身份验证器),Android 原生应用。
|
||||
|
||||
当前版本:0.0.1
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 令牌
|
||||
- 支持 **TOTP / HOTP / Steam** 三种令牌类型
|
||||
- 算法支持 **SHA-1 / SHA-256 / SHA-512**,位数、周期、计数器均可配置
|
||||
- 三种添加方式:**扫描二维码**(CameraX + ZXing 实时识别)、**从相册图片导入**、**手动输入**
|
||||
- 标准 `otpauth://` URI 解析与生成;令牌详情可查看二维码、复制密钥,便于迁移
|
||||
- 复制验证码;HOTP 支持手动刷新计数器
|
||||
- 按密钥(归一化后)检测重复令牌,可选强制添加
|
||||
- 搜索令牌(发行方 / 账户名)
|
||||
- 分组管理:新建 / 重命名 / 删除分组、拖拽排序、折叠展开;分组删除后令牌移入「未分组」
|
||||
- 令牌与分组均支持拖拽排序
|
||||
|
||||
### 安全
|
||||
- 密钥加密存储:AndroidKeyStore 生成的 AES-GCM 密钥,通过 Room `TypeConverter` 在落库 / 读取时透明加解密,数据库文件中不存明文密钥
|
||||
- 应用锁:
|
||||
- 6 位数字 PIN(Keystore 加密后存于 DataStore,非明文)
|
||||
- 生物识别解锁(指纹 / 面部,`BiometricPrompt`)
|
||||
- 锁定时机可选:立即 / 1 分钟 / 3 分钟 / 5 分钟;后台时间持久化,进程被杀后恢复仍会正确上锁
|
||||
- PIN 连续输错 5 次锁定 30 秒
|
||||
- 「禁止截屏」开关(`FLAG_SECURE`,防截屏 / 录屏)
|
||||
- `SecretString` 重写 `toString()`,避免密钥意外进入日志
|
||||
|
||||
### 备份与恢复
|
||||
- 导出 / 导入加密备份文件,支持跨设备迁移
|
||||
- 加密方案:PBKDF2-HMAC-SHA256(10 000 次迭代、16 字节随机盐、256 位密钥)+ AES-GCM(128 位 tag)
|
||||
- 文件格式:`[salt 长度(1B)][salt][IV 长度(1B)][IV][密文]`
|
||||
- 备份带版本号,导入新版本备份会提示先升级应用
|
||||
- 导入按名称合并分组、按归一化密钥去重令牌,并自动重映射分组 ID
|
||||
|
||||
### 应用内更新
|
||||
- 基于 Gitea Release 实现:启动时静默检测(每进程一次,失败不打扰),关于页可手动检测
|
||||
- 发现新版本弹窗展示更新内容,确认后应用内下载(按设备 ABI 自动选择 arm64-v8a / armeabi-v7a / x86_64 安装包)并拉起系统安装器
|
||||
- 首次安装前会引导开启「安装未知应用」权限
|
||||
|
||||
### 界面与个性化
|
||||
- Jetpack Compose + Material 3,edge-to-edge
|
||||
- 主题模式:跟随系统 / 浅色 / 深色
|
||||
- 动态取色(Material You,Android 12+)与自定义主题色
|
||||
- 应用内语言切换:跟随系统 / 简体中文 / 繁體中文 / English
|
||||
|
||||
## 技术栈
|
||||
|
||||
| 类别 | 选型 |
|
||||
|---|---|
|
||||
| 语言 | Kotlin 2.2.10 + C++17(NDK) |
|
||||
| UI | Jetpack Compose(BOM 2026.02.01)、Material 3、Navigation Compose、reorderable |
|
||||
| 数据 | Room 2.6.1(KSP)、DataStore Preferences |
|
||||
| 扫码 | CameraX 1.4.0 + ZXing Core 3.5.3 |
|
||||
| 安全 | AndroidKeyStore(AES-GCM)、androidx.biometric、security-crypto |
|
||||
| 序列化 | Gson(备份 JSON) |
|
||||
| 构建 | Gradle 9.4.1、AGP 9.2.1、JDK 17 toolchain(foojay 自动下载)、CMake 3.22.1 |
|
||||
|
||||
OTP 核心算法(HMAC、SHA-1/256/512、Base32、HOTP/TOTP/Steam)在 `app/src/main/cpp` 以 C++ 自行实现,无第三方依赖,通过 JNI(`NativeLib`)调用。
|
||||
|
||||
## 系统要求
|
||||
|
||||
- Android 7.0(API 24)及以上
|
||||
- 生物识别解锁需要设备具备对应硬件并已录入生物信息
|
||||
|
||||
## 构建
|
||||
|
||||
环境要求:
|
||||
- JDK 17(Gradle toolchain 会按 `gradle/gradle-daemon-jvm.properties` 自动下载)
|
||||
- Android SDK(compileSdk 37)
|
||||
- NDK + CMake 3.22.1(仓库提供 `mise.toml`,执行 `mise install` 可获得对应版本 cmake / ninja)
|
||||
|
||||
```bash
|
||||
# Debug 构建
|
||||
./gradlew assembleDebug
|
||||
|
||||
# Release 构建(R8 混淆 + 资源收缩,按 ABI 拆分 APK)
|
||||
./gradlew assembleRelease
|
||||
```
|
||||
|
||||
Release 产物按 `arm64-v8a / armeabi-v7a / x86_64` 拆分;资源仅保留 `en / zh-rCN / zh-rTW`。
|
||||
|
||||
### 手动发版
|
||||
|
||||
CI 服务器无需编译,Release 由本地构建后上传:
|
||||
|
||||
```bash
|
||||
# 1. 一次性创建签名密钥(密钥库与 keystore.properties 均已 gitignore)
|
||||
keytool -genkeypair -v -keystore release.keystore -alias a2fair -keyalg RSA -keysize 4096 -validity 10000
|
||||
cat > keystore.properties <<'EOF'
|
||||
storeFile=release.keystore
|
||||
storePassword=密钥库口令
|
||||
keyAlias=a2fair
|
||||
keyPassword=密钥口令
|
||||
EOF
|
||||
|
||||
# 2. 本地构建已签名 Release
|
||||
./gradlew assembleRelease
|
||||
|
||||
# 3. 打标签推送,在 Gitea 网页(或 API)创建 Release 并附上 APK
|
||||
git tag vX.Y.Z && git push origin vX.Y.Z
|
||||
```
|
||||
|
||||
产物在 `app/build/outputs/apk/release/`,命名规范 `2fair-<版本>-<abi>.apk`(如 `2fair-0.1.0-arm64-v8a.apk`),文件名自带 ABI 子串,符合应用内更新择包约定。绝大多数设备用 `arm64-v8a`。
|
||||
|
||||
应用内更新依赖发版约定:
|
||||
|
||||
- **递增 `versionCode`**(否则系统拒绝覆盖安装),tag 与 `versionName` 对应(如 `v0.0.2` ↔ `0.0.2`,`V` 前缀大小写均可)
|
||||
- 三个 APK 附件名需包含 ABI 子串(`arm64-v8a` / `armeabi-v7a` / `x86_64`),更新器按设备 ABI 择包
|
||||
- 更新检测走 `releases/latest` 接口,仅认最新非草稿、非预发布版本
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
app/src/main/
|
||||
├── cpp/ # NDK 原生代码:OTP/HMAC/SHA/Base32
|
||||
│ ├── otp.{h,cpp} # HOTP / TOTP / Steam 生成
|
||||
│ ├── hmac.{h,cpp} # HMAC
|
||||
│ ├── sha1/sha256/sha512 # 哈希实现
|
||||
│ └── base32.{h,cpp} # Base32 编解码
|
||||
├── java/cn/airnan/a2fair/
|
||||
│ ├── MainActivity.kt # 锁屏 / 主界面切换、主题、语言、FLAG_SECURE
|
||||
│ ├── A2FairApplication.kt # 全局依赖组装(Crypto/DB/Repo/AppLock/Backup)
|
||||
│ ├── core/
|
||||
│ │ ├── OtpUriParser.kt # otpauth:// 解析
|
||||
│ │ ├── OtpUriBuilder.kt # otpauth:// 生成
|
||||
│ │ ├── NativeLib.kt # JNI 绑定
|
||||
│ │ ├── security/ # AppLockManager(锁定时机/生命周期)、PinPolicy
|
||||
│ │ └── backup/ # BackupManager(加密导出/导入/去重/合并)
|
||||
│ ├── crypto/CryptoManager.kt # AndroidKeyStore AES-GCM 加解密
|
||||
│ ├── data/
|
||||
│ │ ├── entity/ # Token、Group(Room 实体)
|
||||
│ │ ├── dao/ # TokenDao、GroupDao
|
||||
│ │ ├── repository/ # TokenRepository、SettingsRepository
|
||||
│ │ └── SecretString.kt # 密钥包装 + Base32 归一化
|
||||
│ └── ui/
|
||||
│ ├── tokens/ # 令牌列表 / 详情 / 编辑 / 添加(扫码、图片、手动)
|
||||
│ ├── settings/ # 设置、安全(PIN/生物识别/锁屏)、备份、主题、语言、关于、开源许可
|
||||
│ ├── navigation/ # 导航
|
||||
│ └── theme/ # Material 3 主题
|
||||
└── res/ # 文案(en / zh-rCN / zh-rTW)、图标
|
||||
```
|
||||
|
||||
## 源代码
|
||||
|
||||
<https://git.airnan.cn/wangairnan/2FAir>
|
||||
|
||||
## 许可证
|
||||
|
||||
[AGPL-3.0](LICENSE)
|
||||
|
||||
+47
-2
@@ -1,9 +1,22 @@
|
||||
import com.android.build.api.variant.FilterConfiguration
|
||||
import java.util.Properties
|
||||
|
||||
// 版本单点维护:defaultConfig 与 APK 命名共用
|
||||
val appVersionCode = 2
|
||||
val appVersionName = "0.1.0"
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.ksp)
|
||||
}
|
||||
|
||||
// 本地发布签名:根目录 keystore.properties(不入库)指向密钥库,存在则 release 自动签名
|
||||
val keystorePropertiesFile = rootProject.file("keystore.properties")
|
||||
val keystoreProperties = Properties().apply {
|
||||
if (keystorePropertiesFile.exists()) keystorePropertiesFile.inputStream().use { load(it) }
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "cn.airnan.a2fair"
|
||||
compileSdk = 37
|
||||
@@ -13,8 +26,8 @@ android {
|
||||
applicationId = "cn.airnan.a2fair"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "0.0.1"
|
||||
versionCode = appVersionCode
|
||||
versionName = appVersionName
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -25,6 +38,17 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
if (keystorePropertiesFile.exists()) {
|
||||
create("release") {
|
||||
storeFile = rootProject.file(keystoreProperties.getProperty("storeFile"))
|
||||
storePassword = keystoreProperties.getProperty("storePassword")
|
||||
keyAlias = keystoreProperties.getProperty("keyAlias")
|
||||
keyPassword = keystoreProperties.getProperty("keyPassword")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
@@ -33,6 +57,9 @@ android {
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
if (keystorePropertiesFile.exists()) {
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +92,24 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
// APK 命名规范:2fair-<版本>-<abi>.apk(非 release 附构建类型,如 2fair-0.1.0-debug-arm64-v8a.apk)
|
||||
androidComponents {
|
||||
onVariants { variant ->
|
||||
val buildType = variant.buildType
|
||||
variant.outputs.forEach { output ->
|
||||
val abi = output.filters
|
||||
.firstOrNull { it.filterType == FilterConfiguration.FilterType.ABI }?.identifier
|
||||
val fileName = buildString {
|
||||
append("2fair-").append(appVersionName)
|
||||
abi?.let { append('-').append(it) }
|
||||
if (buildType != "release") append('-').append(buildType)
|
||||
append(".apk")
|
||||
}
|
||||
output.outputFileName.set(fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.reorderable)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
<application
|
||||
android:name=".A2FairApplication"
|
||||
@@ -15,7 +17,17 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:theme="@style/Theme._2FAir">
|
||||
<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>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Build
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import cn.airnan.a2fair.core.backup.BackupManager
|
||||
import cn.airnan.a2fair.core.security.AppLockManager
|
||||
import cn.airnan.a2fair.core.update.UpdateManager
|
||||
import cn.airnan.a2fair.crypto.CryptoManager
|
||||
import cn.airnan.a2fair.data.AppDatabase
|
||||
import cn.airnan.a2fair.data.repository.SettingsRepository
|
||||
@@ -37,6 +38,8 @@ class A2FairApplication : Application() {
|
||||
lateinit var backupManager: BackupManager
|
||||
private set
|
||||
|
||||
val updateManager: UpdateManager by lazy { UpdateManager(this) }
|
||||
|
||||
override fun attachBaseContext(base: Context) {
|
||||
val languageCode = try {
|
||||
runBlocking { base.dataStore.data.first() }[intPreferencesKey("language")] ?: 0
|
||||
|
||||
@@ -23,6 +23,7 @@ import cn.airnan.a2fair.data.repository.dataStore
|
||||
import cn.airnan.a2fair.ui.navigation.AppNavigation
|
||||
import cn.airnan.a2fair.ui.settings.security.LockScreen
|
||||
import cn.airnan.a2fair.ui.theme._2FAirTheme
|
||||
import cn.airnan.a2fair.ui.update.UpdateDialog
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.util.Locale
|
||||
@@ -65,9 +66,11 @@ class MainActivity : FragmentActivity() {
|
||||
val seedColor by settingsRepo.seedColor.collectAsStateWithLifecycle(initialValue = 0xFF6750A4.toInt())
|
||||
val isFlagSecureEnabled by settingsRepo.isFlagSecureEnabled.collectAsStateWithLifecycle(initialValue = false)
|
||||
val isLocked by appLockManager.isLocked.collectAsStateWithLifecycle()
|
||||
val updateState by app.updateManager.state.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
appLockManager.checkInitialLockState()
|
||||
app.updateManager.silentCheck()
|
||||
}
|
||||
|
||||
LaunchedEffect(isFlagSecureEnabled) {
|
||||
@@ -114,6 +117,18 @@ class MainActivity : FragmentActivity() {
|
||||
AppNavigation()
|
||||
}
|
||||
}
|
||||
|
||||
// 更新弹窗锁屏期间不展示,解锁后可见;下载中弹窗不可随手关(需显式取消)
|
||||
if (!isLocked) {
|
||||
UpdateDialog(
|
||||
state = updateState,
|
||||
onDismiss = { app.updateManager.dismiss() },
|
||||
onDownload = { app.updateManager.download(it) },
|
||||
onCancelDownload = { app.updateManager.cancelDownload() },
|
||||
onInstall = { app.updateManager.installReady(it) },
|
||||
onRetryDownload = { app.updateManager.download(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
package cn.airnan.a2fair.core.update
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.core.content.FileProvider
|
||||
import cn.airnan.a2fair.BuildConfig
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
/** Gitea Release 摘要(应用内更新用) */
|
||||
data class UpdateInfo(
|
||||
val tagName: String,
|
||||
/** tag 去掉 v/V 前缀后的版本号,如 "V0.0.2" -> "0.0.2" */
|
||||
val version: String,
|
||||
val changelog: String,
|
||||
val assetName: String,
|
||||
val downloadUrl: String,
|
||||
val sizeBytes: Long
|
||||
)
|
||||
|
||||
sealed interface UpdateState {
|
||||
data object Checking : UpdateState
|
||||
data object UpToDate : UpdateState
|
||||
data class Available(val info: UpdateInfo) : UpdateState
|
||||
data class CheckError(val message: String) : UpdateState
|
||||
/** progress 取值 0..100;-1 表示响应无 Content-Length,进度未知 */
|
||||
data class Downloading(val info: UpdateInfo, val progress: Int) : UpdateState
|
||||
data class DownloadFailed(val info: UpdateInfo, val message: String) : UpdateState
|
||||
data class ReadyToInstall(val info: UpdateInfo, val file: File) : UpdateState
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于 Gitea Release 的应用内更新:
|
||||
* - 启动时静默检测(每进程一次),仅在发现新版本时弹窗
|
||||
* - 关于页手动检测,结果回写到 [state]
|
||||
* - 确认更新后按设备 ABI 择包下载,经 FileProvider 拉起系统安装器
|
||||
*/
|
||||
class UpdateManager(private val context: Context) {
|
||||
|
||||
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val silentChecked = AtomicBoolean(false)
|
||||
private var checkJob: Job? = null
|
||||
private var downloadJob: Job? = null
|
||||
|
||||
private val _state = MutableStateFlow<UpdateState?>(null)
|
||||
val state: StateFlow<UpdateState?> = _state.asStateFlow()
|
||||
|
||||
/** 启动静默检测:失败与已是最新均不打扰 UI */
|
||||
fun silentCheck() {
|
||||
if (!silentChecked.compareAndSet(false, true)) return
|
||||
scope.launch {
|
||||
delay(SILENT_CHECK_DELAY_MS)
|
||||
check(silent = true)
|
||||
}
|
||||
}
|
||||
|
||||
/** 关于页手动检测 */
|
||||
fun manualCheck() {
|
||||
if (_state.value is UpdateState.Downloading) return
|
||||
checkJob?.cancel()
|
||||
checkJob = scope.launch { check(silent = false) }
|
||||
}
|
||||
|
||||
fun download(info: UpdateInfo) {
|
||||
if (_state.value is UpdateState.Downloading) return
|
||||
downloadJob?.cancel()
|
||||
downloadJob = scope.launch {
|
||||
try {
|
||||
val file = downloadApk(info) { progress ->
|
||||
_state.value = UpdateState.Downloading(info, progress)
|
||||
}
|
||||
_state.value = UpdateState.ReadyToInstall(info, file)
|
||||
} catch (e: Exception) {
|
||||
if (e is kotlinx.coroutines.CancellationException) throw e
|
||||
_state.value = UpdateState.DownloadFailed(info, e.message ?: "unknown")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelDownload() {
|
||||
downloadJob?.cancel()
|
||||
downloadJob = null
|
||||
_state.value = null
|
||||
}
|
||||
|
||||
/** 关闭弹窗;下载中不允许直接关(必须显式取消) */
|
||||
fun dismiss() {
|
||||
if (_state.value is UpdateState.Downloading) return
|
||||
_state.value = null
|
||||
}
|
||||
|
||||
/** 安装已下载的 APK;缺少「安装未知应用」权限时先引导授权 */
|
||||
fun installReady(ready: UpdateState.ReadyToInstall) {
|
||||
if (canInstallNow()) {
|
||||
install(ready.file)
|
||||
} else {
|
||||
requestInstallPermission()
|
||||
}
|
||||
}
|
||||
|
||||
fun canInstallNow(): Boolean =
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
|
||||
context.packageManager.canRequestPackageInstalls()
|
||||
|
||||
private fun requestInstallPermission() {
|
||||
val intent = Intent(
|
||||
Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,
|
||||
Uri.parse("package:${context.packageName}")
|
||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
private fun install(file: File) {
|
||||
val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
private suspend fun check(silent: Boolean) {
|
||||
if (!silent) _state.value = UpdateState.Checking
|
||||
try {
|
||||
val info = fetchLatestRelease()
|
||||
when {
|
||||
info == null -> if (!silent) _state.value = UpdateState.UpToDate
|
||||
isNewer(info.version, BuildConfig.VERSION_NAME) ->
|
||||
_state.value = UpdateState.Available(info)
|
||||
!silent -> _state.value = UpdateState.UpToDate
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (!silent) _state.value = UpdateState.CheckError(e.message ?: "unknown")
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchLatestRelease(): UpdateInfo? {
|
||||
val conn = openConnection("$API_BASE/releases/latest")
|
||||
val code = conn.responseCode
|
||||
if (code == HttpURLConnection.HTTP_NOT_FOUND) return null // 仓库尚无 release
|
||||
if (code != HttpURLConnection.HTTP_OK) throw IOException("HTTP $code")
|
||||
val body = conn.inputStream.bufferedReader(Charsets.UTF_8).use { it.readText() }
|
||||
|
||||
val json = JSONObject(body)
|
||||
val tagName = json.optString("tag_name").trim()
|
||||
if (tagName.isEmpty()) return null
|
||||
val asset = pickAsset(json.optJSONArray("assets")) ?: return null // 没有可用 APK 附件
|
||||
|
||||
return UpdateInfo(
|
||||
tagName = tagName,
|
||||
version = if (tagName.startsWith("v") || tagName.startsWith("V")) tagName.substring(1) else tagName,
|
||||
changelog = json.optString("body"),
|
||||
assetName = asset.optString("name"),
|
||||
downloadUrl = asset.optString("browser_download_url"),
|
||||
sizeBytes = asset.optLong("size", -1L)
|
||||
)
|
||||
}
|
||||
|
||||
/** 按 Build.SUPPORTED_ABIS 优先级择包,兜底 arm64-v8a,再兜底第一个 .apk */
|
||||
private fun pickAsset(assets: JSONArray?): JSONObject? {
|
||||
if (assets == null) return null
|
||||
val apks = (0 until assets.length())
|
||||
.map { assets.getJSONObject(it) }
|
||||
.filter { it.optString("name").endsWith(".apk", ignoreCase = true) }
|
||||
if (apks.isEmpty()) return null
|
||||
for (abi in Build.SUPPORTED_ABIS) {
|
||||
apks.firstOrNull { it.optString("name").contains(abi, ignoreCase = true) }
|
||||
?.let { return it }
|
||||
}
|
||||
return apks.firstOrNull { it.optString("name").contains("arm64-v8a", ignoreCase = true) }
|
||||
?: apks.first()
|
||||
}
|
||||
|
||||
private suspend fun downloadApk(info: UpdateInfo, onProgress: (Int) -> Unit): File {
|
||||
val dir = File(context.filesDir, "updates").apply { mkdirs() }
|
||||
val tmp = File(dir, "${info.version}.apk.part")
|
||||
val target = File(dir, "${info.version}.apk")
|
||||
target.delete()
|
||||
|
||||
val conn = openConnection(info.downloadUrl)
|
||||
val code = conn.responseCode
|
||||
if (code != HttpURLConnection.HTTP_OK) throw IOException("HTTP $code")
|
||||
val total = conn.contentLengthLong
|
||||
var written = 0L
|
||||
var lastPercent = -1
|
||||
val activeContext = coroutineContext
|
||||
|
||||
conn.inputStream.use { input ->
|
||||
tmp.outputStream().use { output ->
|
||||
val buffer = ByteArray(64 * 1024)
|
||||
while (true) {
|
||||
activeContext.ensureActive()
|
||||
val n = input.read(buffer)
|
||||
if (n == -1) break
|
||||
output.write(buffer, 0, n)
|
||||
written += n
|
||||
if (total > 0) {
|
||||
val percent = (written * 100 / total).toInt()
|
||||
if (percent != lastPercent) {
|
||||
lastPercent = percent
|
||||
onProgress(percent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (total > 0 && written != total) throw IOException("truncated download")
|
||||
if (!tmp.renameTo(target)) throw IOException("rename failed")
|
||||
return target
|
||||
}
|
||||
|
||||
private fun openConnection(url: String): HttpURLConnection =
|
||||
(URL(url).openConnection() as HttpURLConnection).apply {
|
||||
connectTimeout = 10_000
|
||||
readTimeout = 20_000
|
||||
instanceFollowRedirects = true
|
||||
setRequestProperty("Accept", "*/*")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val API_BASE = "https://git.airnan.cn/api/v1/repos/wangairnan/2FAir"
|
||||
private const val SILENT_CHECK_DELAY_MS = 3_000L
|
||||
|
||||
/** 语义化比较:v 前缀可有可无,缺失段补 0,比较失败即不更新 */
|
||||
fun isNewer(remote: String, current: String): Boolean {
|
||||
fun parse(v: String) = v.split('.')
|
||||
.map { seg -> seg.takeWhile(Char::isDigit).toIntOrNull() ?: 0 }
|
||||
val r = parse(remote)
|
||||
val c = parse(current)
|
||||
for (i in 0 until maxOf(r.size, c.size)) {
|
||||
val a = r.getOrElse(i) { 0 }
|
||||
val b = c.getOrElse(i) { 0 }
|
||||
if (a != b) return a > b
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,4 +34,7 @@ interface TokenDao {
|
||||
|
||||
@Query("UPDATE tokens SET counter = :counter WHERE id = :id")
|
||||
fun updateCounter(id: Long, counter: Long): Int
|
||||
|
||||
@Query("UPDATE tokens SET groupId = :targetGroupId WHERE groupId IS NULL")
|
||||
fun reassignUncategorizedTokens(targetGroupId: Long)
|
||||
}
|
||||
|
||||
@@ -28,4 +28,5 @@ class TokenRepository(
|
||||
suspend fun updateToken(token: Token) { withContext(Dispatchers.IO) { tokenDao.updateToken(token) } }
|
||||
suspend fun deleteToken(token: Token) { withContext(Dispatchers.IO) { tokenDao.deleteToken(token) } }
|
||||
suspend fun updateCounter(id: Long, counter: Long) { withContext(Dispatchers.IO) { tokenDao.updateCounter(id, counter) } }
|
||||
suspend fun reassignUncategorizedTokens(targetGroupId: Long) { withContext(Dispatchers.IO) { tokenDao.reassignUncategorizedTokens(targetGroupId) } }
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -28,8 +29,11 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import cn.airnan.a2fair.A2FairApplication
|
||||
import cn.airnan.a2fair.BuildConfig
|
||||
import cn.airnan.a2fair.R
|
||||
import cn.airnan.a2fair.core.update.UpdateState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -38,6 +42,21 @@ fun AboutScreen(
|
||||
onNavigateToLicenses: () -> Unit = {}
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val app = context.applicationContext as A2FairApplication
|
||||
val updateState by app.updateManager.state.collectAsStateWithLifecycle()
|
||||
|
||||
val updateStatusText = when (val s = updateState) {
|
||||
null -> stringResource(R.string.check_update_desc)
|
||||
UpdateState.Checking -> stringResource(R.string.update_checking)
|
||||
UpdateState.UpToDate -> stringResource(R.string.update_up_to_date)
|
||||
is UpdateState.Available -> stringResource(R.string.update_available_title, s.info.version)
|
||||
is UpdateState.CheckError -> stringResource(R.string.update_check_failed, s.message)
|
||||
is UpdateState.Downloading ->
|
||||
if (s.progress >= 0) stringResource(R.string.update_download_progress, s.progress)
|
||||
else stringResource(R.string.update_downloading)
|
||||
is UpdateState.DownloadFailed -> stringResource(R.string.update_download_failed, s.message)
|
||||
is UpdateState.ReadyToInstall -> stringResource(R.string.update_ready_title)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -86,6 +105,15 @@ fun AboutScreen(
|
||||
|
||||
Spacer(modifier = Modifier.height(48.dp))
|
||||
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.author_homepage)) },
|
||||
supportingContent = { Text(stringResource(R.string.author_handle)) },
|
||||
modifier = Modifier.clickable {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://airnan.cn"))
|
||||
context.startActivity(intent)
|
||||
}
|
||||
)
|
||||
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.source_code)) },
|
||||
supportingContent = { Text(stringResource(R.string.view_on_gitea)) },
|
||||
@@ -95,8 +123,15 @@ fun AboutScreen(
|
||||
}
|
||||
)
|
||||
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.check_update)) },
|
||||
supportingContent = { Text(updateStatusText) },
|
||||
modifier = Modifier.clickable { app.updateManager.manualCheck() }
|
||||
)
|
||||
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.open_source_licenses)) },
|
||||
supportingContent = { Text(stringResource(R.string.licenses_desc)) },
|
||||
modifier = Modifier.clickable { onNavigateToLicenses() }
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package cn.airnan.a2fair.ui.settings
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
|
||||
@@ -83,6 +83,7 @@ fun TokensScreen(
|
||||
val lazyListState = rememberLazyListState()
|
||||
var renameTarget by remember { mutableStateOf<Group?>(null) }
|
||||
var deleteTarget by remember { mutableStateOf<Group?>(null) }
|
||||
var renameUncategorized by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(isSearchExpanded) {
|
||||
if (isSearchExpanded) {
|
||||
@@ -137,12 +138,7 @@ fun TokensScreen(
|
||||
)
|
||||
} else {
|
||||
MediumFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.tokens)) },
|
||||
actions = {
|
||||
IconButton(onClick = { isSearchExpanded = true }) {
|
||||
Icon(Icons.Default.Search, contentDescription = stringResource(R.string.search))
|
||||
}
|
||||
},
|
||||
title = { Text(stringResource(R.string.app_name)) },
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
}
|
||||
@@ -158,6 +154,33 @@ fun TokensScreen(
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
) {
|
||||
if (!isSearchExpanded) {
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.extraLarge,
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 4.dp)
|
||||
.clickable { isSearchExpanded = true }
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Search,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.search_tokens),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
val latestUiState by rememberUpdatedState(uiState)
|
||||
if (uiState.groupedTokens.isEmpty()) {
|
||||
if (uiState.searchQuery.isBlank()) {
|
||||
@@ -219,7 +242,7 @@ fun TokensScreen(
|
||||
group = group,
|
||||
isCollapsed = isCollapsed,
|
||||
onToggle = { viewModel.toggleGroupCollapse(groupId) },
|
||||
onRename = { group?.let { renameTarget = it } },
|
||||
onRename = { renameTarget = group; renameUncategorized = group == null },
|
||||
onDelete = { group?.let { deleteTarget = it } },
|
||||
dragModifier = with(groupDragScope) {
|
||||
Modifier.draggableHandle(
|
||||
@@ -286,10 +309,12 @@ fun TokensScreen(
|
||||
)
|
||||
}
|
||||
|
||||
renameTarget?.let { target ->
|
||||
var newName by remember(target.id) { mutableStateOf(target.name) }
|
||||
if (renameUncategorized || renameTarget != null) {
|
||||
val target = renameTarget
|
||||
val currentName = target?.name ?: stringResource(R.string.uncategorized)
|
||||
var newName by remember(renameTarget?.id, currentName) { mutableStateOf(currentName) }
|
||||
AlertDialog(
|
||||
onDismissRequest = { renameTarget = null },
|
||||
onDismissRequest = { renameTarget = null; renameUncategorized = false },
|
||||
title = { Text(stringResource(R.string.group_rename)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
@@ -302,17 +327,18 @@ fun TokensScreen(
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
enabled = newName.isNotBlank() && newName.trim() != target.name,
|
||||
enabled = newName.isNotBlank() && newName.trim() != currentName,
|
||||
onClick = {
|
||||
viewModel.renameGroup(target, newName)
|
||||
renameTarget = null
|
||||
renameUncategorized = false
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.save))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { renameTarget = null }) {
|
||||
TextButton(onClick = { renameTarget = null; renameUncategorized = false }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
@@ -450,6 +476,8 @@ fun GroupHeader(
|
||||
onRename()
|
||||
}
|
||||
)
|
||||
// 未分组是伪分组(groupId IS NULL),不可删除,仅真实分组显示删除项
|
||||
if (group != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.delete)) },
|
||||
onClick = {
|
||||
@@ -459,6 +487,7 @@ fun GroupHeader(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Icon(
|
||||
imageVector = if (isCollapsed) Icons.Default.ExpandMore else Icons.Default.ExpandLess,
|
||||
contentDescription = stringResource(R.string.toggle_group)
|
||||
|
||||
@@ -130,9 +130,16 @@ class TokensViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun renameGroup(group: Group, newName: String) {
|
||||
fun renameGroup(group: Group?, newName: String) {
|
||||
val trimmed = newName.trim()
|
||||
if (trimmed.isEmpty() || trimmed == group.name) return
|
||||
if (trimmed.isEmpty()) return
|
||||
if (group == null) {
|
||||
// 未分组重命名 = 物化为真实组;改回默认名视为无操作
|
||||
if (trimmed == getApplication<Application>().getString(R.string.uncategorized)) return
|
||||
materializeUncategorized(trimmed)
|
||||
return
|
||||
}
|
||||
if (trimmed == group.name) return
|
||||
viewModelScope.launch {
|
||||
tokenRepository.updateGroup(group.copy(name = trimmed))
|
||||
}
|
||||
@@ -144,6 +151,33 @@ class TokensViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 物化未分组(重命名触发):建同名真实分组(已存在同名组则并入),
|
||||
* 全部 groupId 为 NULL 的令牌转入,新分组继承未分组的显示位置,
|
||||
* 伪分组位置重置回默认(列表末尾)。未分组不支持删除,物化仅由重命名进入。
|
||||
*/
|
||||
private fun materializeUncategorized(name: String) {
|
||||
viewModelScope.launch {
|
||||
val hasUncategorized = tokenRepository.getAllTokens().first().any { it.groupId == null }
|
||||
if (!hasUncategorized) return@launch
|
||||
|
||||
val groups = tokenRepository.getAllGroups().first()
|
||||
val existing = groups.firstOrNull { it.name == name }
|
||||
val targetId = existing?.id ?: run {
|
||||
val sorted = groups.sortedBy { it.sortOrder }
|
||||
val newGroup = Group(name = name, sortOrder = 0)
|
||||
val newId = tokenRepository.insertGroup(newGroup)
|
||||
val insertIdx = settingsRepository.uncategorizedOrder.first().coerceIn(0, sorted.size)
|
||||
sorted.toMutableList()
|
||||
.apply { add(insertIdx, newGroup.copy(id = newId)) }
|
||||
.forEachIndexed { index, g -> tokenRepository.updateGroup(g.copy(sortOrder = index)) }
|
||||
newId
|
||||
}
|
||||
tokenRepository.reassignUncategorizedTokens(targetId)
|
||||
settingsRepository.setUncategorizedOrder(Int.MAX_VALUE)
|
||||
}
|
||||
}
|
||||
|
||||
/** Persists a new display order of groups; Uncategorized (null) position is stored separately. */
|
||||
fun applyGroupOrder(ordered: List<Group?>) {
|
||||
viewModelScope.launch {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package cn.airnan.a2fair.ui.update
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import cn.airnan.a2fair.R
|
||||
import cn.airnan.a2fair.core.update.UpdateInfo
|
||||
import cn.airnan.a2fair.core.update.UpdateState
|
||||
|
||||
@Composable
|
||||
fun UpdateDialog(
|
||||
state: UpdateState?,
|
||||
onDismiss: () -> Unit,
|
||||
onDownload: (UpdateInfo) -> Unit,
|
||||
onCancelDownload: () -> Unit,
|
||||
onInstall: (UpdateState.ReadyToInstall) -> Unit,
|
||||
onRetryDownload: (UpdateInfo) -> Unit
|
||||
) {
|
||||
when (state) {
|
||||
is UpdateState.Available -> AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.update_available_title, state.info.version)) },
|
||||
text = {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.heightIn(max = 300.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
if (state.info.changelog.isNotBlank()) {
|
||||
Text(
|
||||
text = stringResource(R.string.update_changelog),
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text = state.info.changelog,
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onDownload(state.info) }) {
|
||||
Text(stringResource(R.string.update_download))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.update_later))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
is UpdateState.Downloading -> AlertDialog(
|
||||
onDismissRequest = onCancelDownload,
|
||||
title = { Text(stringResource(R.string.update_downloading)) },
|
||||
text = {
|
||||
Column {
|
||||
if (state.progress >= 0) {
|
||||
LinearProgressIndicator(
|
||||
progress = { state.progress / 100f },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.update_download_progress, state.progress),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
} else {
|
||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onCancelDownload) {
|
||||
Text(stringResource(R.string.update_cancel_download))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
is UpdateState.ReadyToInstall -> AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.update_ready_title)) },
|
||||
text = { Text(stringResource(R.string.update_ready_message)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onInstall(state) }) {
|
||||
Text(stringResource(R.string.update_install))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.update_later))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
is UpdateState.DownloadFailed -> AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.update_download_failed_title)) },
|
||||
text = { Text(stringResource(R.string.update_download_failed, state.message)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onRetryDownload(state.info) }) {
|
||||
Text(stringResource(R.string.update_retry))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,8 @@
|
||||
<string name="backup_restore">备份与恢复</string>
|
||||
<string name="theme">主题</string>
|
||||
<string name="about">关于</string>
|
||||
<string name="author_homepage">作者主页</string>
|
||||
<string name="author_handle">@码农阿楠</string>
|
||||
|
||||
<!-- Security Settings -->
|
||||
<string name="app_lock_pin">应用锁 PIN 码</string>
|
||||
@@ -162,6 +164,26 @@
|
||||
<string name="dynamic_color_desc">使用壁纸提取的颜色(Android 12+)</string>
|
||||
<string name="seed_color">主题色</string>
|
||||
|
||||
<!-- Update -->
|
||||
<string name="check_update">检查更新</string>
|
||||
<string name="check_update_desc">从 Gitea Release 检查并安装新版本</string>
|
||||
<string name="update_checking">正在检查更新…</string>
|
||||
<string name="update_up_to_date">当前已是最新版本</string>
|
||||
<string name="update_available_title">发现新版本 v%s</string>
|
||||
<string name="update_changelog">更新内容</string>
|
||||
<string name="update_download">下载更新</string>
|
||||
<string name="update_later">以后再说</string>
|
||||
<string name="update_downloading">正在下载更新…</string>
|
||||
<string name="update_download_progress">正在下载 %1$d%%</string>
|
||||
<string name="update_cancel_download">取消下载</string>
|
||||
<string name="update_download_failed_title">下载失败</string>
|
||||
<string name="update_download_failed">下载失败:%s</string>
|
||||
<string name="update_retry">重试</string>
|
||||
<string name="update_ready_title">安装包下载完成</string>
|
||||
<string name="update_ready_message">安装包已下载,是否立即安装?</string>
|
||||
<string name="update_install">立即安装</string>
|
||||
<string name="update_check_failed">检查更新失败:%s</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="back">返回</string>
|
||||
<string name="app_icon">应用图标</string>
|
||||
|
||||
@@ -162,6 +162,26 @@
|
||||
<string name="dynamic_color_desc">使用桌布提取的顏色(Android 12+)</string>
|
||||
<string name="seed_color">主題色</string>
|
||||
|
||||
<!-- Update -->
|
||||
<string name="check_update">檢查更新</string>
|
||||
<string name="check_update_desc">從 Gitea Release 檢查並安裝新版本</string>
|
||||
<string name="update_checking">正在檢查更新…</string>
|
||||
<string name="update_up_to_date">目前已是最新版本</string>
|
||||
<string name="update_available_title">發現新版本 v%s</string>
|
||||
<string name="update_changelog">更新內容</string>
|
||||
<string name="update_download">下載更新</string>
|
||||
<string name="update_later">稍後再說</string>
|
||||
<string name="update_downloading">正在下載更新…</string>
|
||||
<string name="update_download_progress">正在下載 %1$d%%</string>
|
||||
<string name="update_cancel_download">取消下載</string>
|
||||
<string name="update_download_failed_title">下載失敗</string>
|
||||
<string name="update_download_failed">下載失敗:%s</string>
|
||||
<string name="update_retry">重試</string>
|
||||
<string name="update_ready_title">安裝套件下載完成</string>
|
||||
<string name="update_ready_message">安裝套件已下載,是否立即安裝?</string>
|
||||
<string name="update_install">立即安裝</string>
|
||||
<string name="update_check_failed">檢查更新失敗:%s</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="back">返回</string>
|
||||
<string name="app_icon">應用程式圖示</string>
|
||||
|
||||
@@ -82,6 +82,8 @@
|
||||
<string name="backup_restore">Backup & Restore</string>
|
||||
<string name="theme">Theme</string>
|
||||
<string name="about">About</string>
|
||||
<string name="author_homepage">Author homepage</string>
|
||||
<string name="author_handle">@Airnan</string>
|
||||
|
||||
<!-- Security Settings -->
|
||||
<string name="app_lock_pin">App Lock PIN</string>
|
||||
@@ -162,6 +164,26 @@
|
||||
<string name="dynamic_color_desc">Use colors extracted from wallpaper (Android 12+)</string>
|
||||
<string name="seed_color">Seed Color</string>
|
||||
|
||||
<!-- Update -->
|
||||
<string name="check_update">Check for updates</string>
|
||||
<string name="check_update_desc">Check and install new versions from Gitea releases</string>
|
||||
<string name="update_checking">Checking for updates…</string>
|
||||
<string name="update_up_to_date">You are on the latest version</string>
|
||||
<string name="update_available_title">Update available: v%s</string>
|
||||
<string name="update_changelog">What\'s new</string>
|
||||
<string name="update_download">Download update</string>
|
||||
<string name="update_later">Later</string>
|
||||
<string name="update_downloading">Downloading update…</string>
|
||||
<string name="update_download_progress">Downloading %1$d%%</string>
|
||||
<string name="update_cancel_download">Cancel download</string>
|
||||
<string name="update_download_failed_title">Download failed</string>
|
||||
<string name="update_download_failed">Download failed: %s</string>
|
||||
<string name="update_retry">Retry</string>
|
||||
<string name="update_ready_title">Update downloaded</string>
|
||||
<string name="update_ready_message">The update package is ready. Install it now?</string>
|
||||
<string name="update_install">Install now</string>
|
||||
<string name="update_check_failed">Update check failed: %s</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="back">Back</string>
|
||||
<string name="app_icon">App Icon</string>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<!-- 应用内更新下载的安装包目录 -->
|
||||
<files-path name="updates" path="updates/" />
|
||||
</paths>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 仅放行本机回环明文流量,供 adb reverse + 本地 mock server 联调更新流程;正式更新走 https -->
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="false">localhost</domain>
|
||||
<domain includeSubdomains="false">127.0.0.1</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
Reference in New Issue
Block a user