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