mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(logs): game debug logs turn off after the session, and a badge shows while they are on (#3239)
This commit is contained in:
1 parent
bdd3d247c3
commit
cc04546373
6 files changed
+117
-7
No files matched your search
@@ -39,6 +39,10 @@ internal object BuildWatermarkSetting {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
notifyChanged(context)
|
||||
}
|
||||
|
||||
fun notifyChanged(context: Context) {
|
||||
context.sendBroadcast(Intent(CHANGED).setPackage(context.packageName))
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,9 @@ object SessionPaths {
|
||||
@Volatile
|
||||
private var startedAt = 0L
|
||||
|
||||
@Volatile
|
||||
private var debugLogsContext: Context? = null
|
||||
|
||||
@Synchronized
|
||||
fun beginOrCurrent(context: Context, label: String? = null): File {
|
||||
dir?.let { if (it.isDirectory) return it }
|
||||
@@ -44,6 +47,7 @@ object SessionPaths {
|
||||
startedAt = System.currentTimeMillis()
|
||||
if (!made.isDirectory && !made.mkdirs()) Log.e(TAG, "could not create $made")
|
||||
dir = made
|
||||
debugLogsContext = if (SessionPrefs.gameDebugLogsEnabled(context)) context.applicationContext else null
|
||||
if (enhanced && !EnhancedDiagnostics.consumeInto(context, made)) {
|
||||
Log.e(TAG, "could not activate enhanced diagnostics for $made")
|
||||
}
|
||||
@@ -65,6 +69,9 @@ object SessionPaths {
|
||||
val taken = dir
|
||||
dir = null
|
||||
if (taken != null) ended = taken
|
||||
val expiring = debugLogsContext
|
||||
debugLogsContext = null
|
||||
if (taken != null && expiring != null) SessionPrefs.expireGameDebugLogs(expiring)
|
||||
return taken
|
||||
}
|
||||
|
||||
|
||||
@@ -1228,7 +1228,7 @@ object SessionPrefs {
|
||||
oldValue = logsEnabled(context),
|
||||
newValue = on,
|
||||
newEffective = gameDebugLogsEffective(context, on, gameDebugLogsEnabled(context)),
|
||||
)
|
||||
).also { if (it) BuildWatermarkSetting.notifyChanged(context) }
|
||||
}
|
||||
|
||||
fun gameDebugLogsEnabled(context: Context): Boolean =
|
||||
@@ -1241,7 +1241,13 @@ object SessionPrefs {
|
||||
oldValue = gameDebugLogsEnabled(context),
|
||||
newValue = on,
|
||||
newEffective = gameDebugLogsEffective(context, logsEnabled(context), on),
|
||||
)
|
||||
).also { if (it) BuildWatermarkSetting.notifyChanged(context) }
|
||||
}
|
||||
|
||||
/** The setting lasts for the session that started with it on; the next session's start republishes the environment. */
|
||||
internal fun expireGameDebugLogs(context: Context) {
|
||||
prefs(context).edit().putBoolean("gameDebugLogsEnabled", false).apply()
|
||||
runCatching { BuildWatermarkSetting.notifyChanged(context) }
|
||||
}
|
||||
|
||||
private fun setLogPreference(
|
||||
|
||||
@@ -81,10 +81,13 @@ object BuildWatermark {
|
||||
if (activity is QuestXrActivity) return
|
||||
val decor = activity.window.decorView as? ViewGroup ?: return
|
||||
decor.findViewWithTag<View>(TAG)?.let(decor::removeView)
|
||||
if (!com.droiddeck.launcher.session.SessionPrefs.buildWatermarkEnabled(activity)) return
|
||||
val lab = com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" }
|
||||
val build = lineProvider().orEmpty()
|
||||
val content = (listOfNotNull(lab) + build).ifEmpty { return }
|
||||
val prefs = com.droiddeck.launcher.session.SessionPrefs
|
||||
val debugLogs = if (prefs.logsEnabled(activity) && prefs.gameDebugLogsEnabled(activity)) DEBUG_LOGS_LINE else null
|
||||
val build = if (prefs.buildWatermarkEnabled(activity)) {
|
||||
listOfNotNull(com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" }) +
|
||||
lineProvider().orEmpty()
|
||||
} else emptyList()
|
||||
val content = (build + listOfNotNull(debugLogs)).ifEmpty { return }
|
||||
val margin = (8 * activity.resources.displayMetrics.density).toInt()
|
||||
decor.addView(
|
||||
MarkView(activity, content).apply { tag = TAG },
|
||||
@@ -96,6 +99,8 @@ object BuildWatermark {
|
||||
)
|
||||
}
|
||||
|
||||
internal const val DEBUG_LOGS_LINE = "GAME DEBUG LOGS ON | slows games"
|
||||
|
||||
private const val TAG = "build-watermark"
|
||||
|
||||
private class MarkView(context: Context, private val lines: List<String>) : View(context) {
|
||||
|
||||
Reference in new issue
Block a user