mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-11-23 23:57:23 +00:00
add platform and compose debug actions
This commit is contained in:
1 parent
7f18496d94
commit
4fc372035a
5 files changed
+171
No files matched your search
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import android.content.Context
|
||||
import co.touchlab.kermit.Logger
|
||||
import org.koin.core.annotation.Singleton
|
||||
|
||||
/**
|
||||
* Forwards every debug action to a bridge supplied by the host app.
|
||||
*
|
||||
*/
|
||||
@Singleton(binds = [DebugActions::class])
|
||||
class AndroidDebugActions(context: Context) : DebugActions {
|
||||
|
||||
private val host: DebugActions = loadHost(context)
|
||||
|
||||
override val isLeakCanaryAvailable: Boolean
|
||||
get() = host.isLeakCanaryAvailable
|
||||
|
||||
override fun showMemoryLeaks() = host.showMemoryLeaks()
|
||||
|
||||
override fun checkNewStreams() = host.checkNewStreams()
|
||||
|
||||
override fun createErrorNotification() = host.createErrorNotification()
|
||||
|
||||
override fun reportDummyError() = host.reportDummyError()
|
||||
|
||||
private fun loadHost(context: Context): DebugActions = runCatching {
|
||||
Class.forName(HOST_CLASS)
|
||||
.getDeclaredConstructor(Context::class.java)
|
||||
.newInstance(context) as DebugActions
|
||||
}.getOrElse { error ->
|
||||
Logger.w(messageString = "No host debug actions found, falling back to no-op", throwable = error)
|
||||
NoOpDebugActions
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val HOST_CLASS = "org.schabi.newpipe.settings.ComposeDebugActions"
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,47 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import co.touchlab.kermit.Logger
|
||||
|
||||
/**
|
||||
* Platform-specific actions triggered from the Debug settings screen.
|
||||
*
|
||||
*/
|
||||
interface DebugActions {
|
||||
/** Whether the running build ships LeakCanary; its two rows are disabled when it does not. */
|
||||
val isLeakCanaryAvailable: Boolean
|
||||
|
||||
/** Opens the LeakCanary leak list. */
|
||||
fun showMemoryLeaks()
|
||||
|
||||
/** Runs the new-stream notification check now, instead of waiting for its schedule. */
|
||||
fun checkNewStreams()
|
||||
|
||||
/** Posts a dummy error notification, to verify error reporting end to end. */
|
||||
fun createErrorNotification()
|
||||
|
||||
/** Opens the error report screen for a dummy error. */
|
||||
fun reportDummyError()
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback for platforms with no debug tooling to drive, and for Android builds that ship without
|
||||
* the host-side bridge.
|
||||
*/
|
||||
internal object NoOpDebugActions : DebugActions {
|
||||
override val isLeakCanaryAvailable = false
|
||||
|
||||
override fun showMemoryLeaks() = logUnsupported("showMemoryLeaks")
|
||||
|
||||
override fun checkNewStreams() = logUnsupported("checkNewStreams")
|
||||
|
||||
override fun createErrorNotification() = logUnsupported("createErrorNotification")
|
||||
|
||||
override fun reportDummyError() = logUnsupported("reportDummyError")
|
||||
|
||||
private fun logUnsupported(action: String) = Logger.w(messageString = "Debug action '$action' is unsupported on this platform")
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import org.koin.core.annotation.Singleton
|
||||
|
||||
/**
|
||||
* iOS has no debug tooling to drive yet, and the Debug category is hidden there anyway
|
||||
*/
|
||||
@Singleton(binds = [DebugActions::class])
|
||||
class IOSDebugActions : DebugActions by NoOpDebugActions
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import org.koin.core.annotation.Singleton
|
||||
|
||||
/**
|
||||
* Desktop has no debug tooling to drive yet
|
||||
*/
|
||||
|
||||
@Singleton(binds = [DebugActions::class])
|
||||
class JVMDebugActions : DebugActions by NoOpDebugActions
|
||||
Reference in new issue
Block a user