mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 19:57:15 +08:00
perf: 快照添加 githubAssetId 字段
This commit is contained in:
parent
d680365840
commit
dd206f968c
|
@ -12,4 +12,5 @@ interface BaseSnapshot {
|
|||
val screenHeight: Int
|
||||
val screenWidth: Int
|
||||
val isLandscape: Boolean
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package li.songe.gkd.data
|
|||
import com.blankj.utilcode.util.AppUtils
|
||||
import com.blankj.utilcode.util.ScreenUtils
|
||||
import kotlinx.serialization.Serializable
|
||||
import li.songe.gkd.BuildConfig
|
||||
import li.songe.gkd.service.GkdAbService
|
||||
import li.songe.gkd.service.safeActiveWindow
|
||||
import li.songe.gkd.service.topActivityFlow
|
||||
|
@ -21,6 +22,8 @@ data class ComplexSnapshot(
|
|||
override val screenWidth: Int,
|
||||
override val isLandscape: Boolean,
|
||||
|
||||
val gkdVersionCode: Int = BuildConfig.VERSION_CODE,
|
||||
|
||||
val device: DeviceInfo,
|
||||
val nodes: List<NodeInfo>,
|
||||
) : BaseSnapshot
|
||||
|
|
|
@ -31,6 +31,8 @@ data class Snapshot(
|
|||
@ColumnInfo(name = "screen_width") override val screenWidth: Int,
|
||||
@ColumnInfo(name = "is_landscape") override val isLandscape: Boolean,
|
||||
|
||||
@ColumnInfo(name = "github_asset_id") val githubAssetId: Int? = null,
|
||||
|
||||
) : BaseSnapshot {
|
||||
|
||||
val screenshotFile by lazy {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package li.songe.gkd.db
|
||||
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import li.songe.gkd.data.ClickLog
|
||||
|
@ -8,8 +9,9 @@ import li.songe.gkd.data.SubsConfig
|
|||
import li.songe.gkd.data.SubsItem
|
||||
|
||||
@Database(
|
||||
version = 1,
|
||||
version = 2,
|
||||
entities = [SubsItem::class, Snapshot::class, SubsConfig::class, ClickLog::class],
|
||||
autoMigrations = [AutoMigration(from = 1, to = 2)]
|
||||
)
|
||||
abstract class AppDb : RoomDatabase() {
|
||||
abstract fun subsItemDao(): SubsItem.SubsItemDao
|
||||
|
|
|
@ -116,7 +116,7 @@ class GkdAbService : CompositionAbService({
|
|||
lastTriggerShizukuTime =
|
||||
if (newActivityId.startsWith("android.view.") || newActivityId.startsWith("android.widget.")) {
|
||||
val t = System.currentTimeMillis()
|
||||
if (t - lastTriggerShizukuTime < 100) {
|
||||
if (t - lastTriggerShizukuTime < if (currentRulesFlow.value.isNotEmpty()) 100 else 200) {
|
||||
return@onAccessibilityEvent
|
||||
}
|
||||
t
|
||||
|
|
|
@ -71,9 +71,7 @@ import li.songe.gkd.util.ProfileTransitions
|
|||
import li.songe.gkd.util.format
|
||||
import li.songe.gkd.util.launchAsFn
|
||||
import li.songe.gkd.util.navigate
|
||||
import li.songe.gkd.util.recordStoreFlow
|
||||
import li.songe.gkd.util.snapshotZipDir
|
||||
import li.songe.gkd.util.updateStorage
|
||||
import java.io.File
|
||||
|
||||
@RootNavGraph
|
||||
|
@ -91,7 +89,6 @@ fun SnapshotPage() {
|
|||
val vm = hiltViewModel<SnapshotVm>()
|
||||
val snapshots by vm.snapshotsState.collectAsState()
|
||||
val uploadStatus by vm.uploadStatusFlow.collectAsState()
|
||||
val recordStore by recordStoreFlow.collectAsState()
|
||||
|
||||
var selectedSnapshot by remember {
|
||||
mutableStateOf<Snapshot?>(null)
|
||||
|
@ -217,14 +214,12 @@ fun SnapshotPage() {
|
|||
.then(modifier)
|
||||
)
|
||||
Divider()
|
||||
if (recordStore.snapshotIdMap.containsKey(snapshotVal.id)) {
|
||||
val url =
|
||||
"https://i.gkd.li/import/" + recordStore.snapshotIdMap[snapshotVal.id]
|
||||
if (snapshotVal.githubAssetId != null) {
|
||||
Text(
|
||||
text = "复制链接", modifier = Modifier
|
||||
.clickable(onClick = {
|
||||
selectedSnapshot = null
|
||||
ClipboardUtils.copyText(url)
|
||||
ClipboardUtils.copyText(IMPORT_BASE_URL + snapshotVal.githubAssetId)
|
||||
ToastUtils.showShort("复制成功")
|
||||
})
|
||||
.then(modifier)
|
||||
|
@ -278,15 +273,9 @@ fun SnapshotPage() {
|
|||
File(snapshotZipDir, "${snapshotVal.id}.zip").apply {
|
||||
if (exists()) delete()
|
||||
}
|
||||
if (recordStore.snapshotIdMap.containsKey(snapshotVal.id)) {
|
||||
updateStorage(
|
||||
recordStoreFlow,
|
||||
recordStore.copy(snapshotIdMap = recordStore.snapshotIdMap
|
||||
.toMutableMap()
|
||||
.apply {
|
||||
remove(snapshotVal.id)
|
||||
})
|
||||
)
|
||||
if (snapshotVal.githubAssetId != null) {
|
||||
// 当本地快照变更时, 移除快照链接
|
||||
DbSet.snapshotDao.update(snapshotVal.copy(githubAssetId = null))
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showShort("截图尺寸不一致,无法替换")
|
||||
|
@ -305,16 +294,6 @@ fun SnapshotPage() {
|
|||
DbSet.snapshotDao.delete(snapshotVal)
|
||||
withContext(Dispatchers.IO) {
|
||||
SnapshotExt.removeAssets(snapshotVal.id)
|
||||
if (recordStore.snapshotIdMap.containsKey(snapshotVal.id)) {
|
||||
updateStorage(
|
||||
recordStoreFlow,
|
||||
recordStore.copy(snapshotIdMap = recordStore.snapshotIdMap
|
||||
.toMutableMap()
|
||||
.apply {
|
||||
remove(snapshotVal.id)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
selectedSnapshot = null
|
||||
})
|
||||
|
@ -397,9 +376,6 @@ fun SnapshotPage() {
|
|||
SnapshotExt.removeAssets(s.id)
|
||||
}
|
||||
DbSet.snapshotDao.deleteAll()
|
||||
updateStorage(
|
||||
recordStoreFlow, recordStoreFlow.value.copy(snapshotIdMap = emptyMap())
|
||||
)
|
||||
},
|
||||
) {
|
||||
Text(text = "是", color = MaterialTheme.colorScheme.error)
|
||||
|
|
|
@ -25,8 +25,6 @@ import li.songe.gkd.util.FILE_UPLOAD_URL
|
|||
import li.songe.gkd.util.LoadStatus
|
||||
import li.songe.gkd.util.Singleton
|
||||
import li.songe.gkd.util.launchTry
|
||||
import li.songe.gkd.util.recordStoreFlow
|
||||
import li.songe.gkd.util.updateStorage
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
|
@ -60,13 +58,7 @@ class SnapshotVm @Inject constructor() : ViewModel() {
|
|||
if (response.headers["X_RPC_OK"] == "true") {
|
||||
val policiesAsset = response.body<GithubPoliciesAsset>()
|
||||
uploadStatusFlow.value = LoadStatus.Success(policiesAsset)
|
||||
updateStorage(
|
||||
recordStoreFlow,
|
||||
recordStoreFlow.value.copy(snapshotIdMap = recordStoreFlow.value.snapshotIdMap.toMutableMap()
|
||||
.apply {
|
||||
set(snapshot.id, policiesAsset.id)
|
||||
})
|
||||
)
|
||||
DbSet.snapshotDao.update(snapshot.copy(githubAssetId = policiesAsset.id))
|
||||
} else if (response.headers["X_RPC_OK"] == "false") {
|
||||
uploadStatusFlow.value = LoadStatus.Failure(response.body<RpcError>())
|
||||
} else {
|
||||
|
|
|
@ -103,7 +103,6 @@ val storeFlow by lazy {
|
|||
@Serializable
|
||||
data class RecordStore(
|
||||
val clickCount: Int = 0,
|
||||
val snapshotIdMap: Map<Long, Int> = emptyMap(),
|
||||
)
|
||||
|
||||
val recordStoreFlow by lazy {
|
||||
|
|
|
@ -114,7 +114,7 @@ val appIdToRulesFlow by lazy {
|
|||
actionDelay = actionDelay,
|
||||
index = ruleIndex,
|
||||
matches = ruleRaw.matches.map { Selector.parse(it) },
|
||||
excludeMatches = ruleRaw.excludeMatches.map {
|
||||
excludeMatches = (ruleRaw.excludeMatches ?: emptyList()).map {
|
||||
Selector.parse(
|
||||
it
|
||||
)
|
||||
|
@ -126,7 +126,7 @@ val appIdToRulesFlow by lazy {
|
|||
activityIds = activityIds,
|
||||
excludeActivityIds = excludeActivityIds,
|
||||
key = ruleRaw.key,
|
||||
preKeys = ruleRaw.preKeys.toSet(),
|
||||
preKeys = (ruleRaw.preKeys ?: emptyList()).toSet(),
|
||||
rule = ruleRaw,
|
||||
group = groupRaw,
|
||||
app = appRaw,
|
||||
|
|
Loading…
Reference in New Issue
Block a user