Skip to content

Commit

Permalink
feat: upload by github cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Aug 20, 2024
1 parent f66c49c commit dbf810f
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 303 deletions.
54 changes: 1 addition & 53 deletions app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package li.songe.gkd.service

import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import android.graphics.PixelFormat
import android.os.Build
Expand All @@ -16,7 +12,6 @@ import android.view.WindowManager
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
Expand Down Expand Up @@ -46,7 +41,6 @@ import li.songe.gkd.shizuku.useSafeGetTasksFc
import li.songe.gkd.shizuku.useSafeInputTapFc
import li.songe.gkd.shizuku.useShizukuAliveState
import li.songe.gkd.util.UpdateTimeOption
import li.songe.gkd.util.VOLUME_CHANGED_ACTION
import li.songe.gkd.util.checkSubsUpdate
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.map
Expand Down Expand Up @@ -182,7 +176,7 @@ class GkdAbService : CompositionAbService({
latestEvent?.let { n ->
val refreshOk = try {
n.refresh()
} catch (e: Exception) {
} catch (_: Exception) {
false
}
if (!refreshOk) {
Expand Down Expand Up @@ -433,52 +427,6 @@ class GkdAbService : CompositionAbService({
}
}


fun createVolumeReceiver(): BroadcastReceiver {
return object : BroadcastReceiver() {
var lastTriggerTime = -1L
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == VOLUME_CHANGED_ACTION) {
val t = System.currentTimeMillis()
if (t - lastTriggerTime > 3000 && !ScreenUtils.isScreenLock()) {
lastTriggerTime = t
scope.launchTry(Dispatchers.IO) {
SnapshotExt.captureSnapshot()
toast("快照成功")
}
}
}
}
}
}

var captureVolumeReceiver: BroadcastReceiver? = null
scope.launch {
storeFlow.map(scope) { s -> s.captureVolumeChange }.collect {
if (captureVolumeReceiver != null) {
context.unregisterReceiver(captureVolumeReceiver)
}
captureVolumeReceiver = if (it) {
createVolumeReceiver().apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(
this, IntentFilter(VOLUME_CHANGED_ACTION), Context.RECEIVER_EXPORTED
)
} else {
context.registerReceiver(this, IntentFilter(VOLUME_CHANGED_ACTION))
}
}
} else {
null
}
}
}
onDestroy {
if (captureVolumeReceiver != null) {
context.unregisterReceiver(captureVolumeReceiver)
}
}

onAccessibilityEvent { e ->
if (!storeFlow.value.captureScreenshot) return@onAccessibilityEvent
val appId = e.packageName ?: return@onAccessibilityEvent
Expand Down
Loading

0 comments on commit dbf810f

Please sign in to comment.