diff --git a/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidHistoryActions.kt b/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidHistoryActions.kt new file mode 100644 index 000000000..f03574f84 --- /dev/null +++ b/shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidHistoryActions.kt @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * 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 history action to a bridge supplied by the host app. + */ +@Singleton(binds = [HistoryActions::class]) +class AndroidHistoryActions(context: Context) : HistoryActions { + + private val host: HistoryActions = loadHost(context) + + override fun wipeMetadataCache() = host.wipeMetadataCache() + + override suspend fun clearWatchHistory() = host.clearWatchHistory() + + override suspend fun clearPlaybackStates() = host.clearPlaybackStates() + + override suspend fun clearSearchHistory() = host.clearSearchHistory() + + override fun clearRecaptchaCookies() = host.clearRecaptchaCookies() + + private fun loadHost(context: Context): HistoryActions = runCatching { + Class.forName(HOST_CLASS) + .getDeclaredConstructor(Context::class.java) + .newInstance(context) as HistoryActions + }.getOrElse { error -> + Logger.w( + messageString = "No host history actions found, falling back to no-op", + throwable = error + ) + NoOpHistoryActions + } + + private companion object { + const val HOST_CLASS = "org.schabi.newpipe.settings.ComposeHistoryActions" + } +} diff --git a/shared/src/commonMain/kotlin/net/newpipe/app/platform/HistoryActions.kt b/shared/src/commonMain/kotlin/net/newpipe/app/platform/HistoryActions.kt new file mode 100644 index 000000000..e5326ff89 --- /dev/null +++ b/shared/src/commonMain/kotlin/net/newpipe/app/platform/HistoryActions.kt @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.platform + +import co.touchlab.kermit.Logger + +/** + * Platform-specific actions triggered from the History and cache settings screen. + */ +interface HistoryActions { + + fun wipeMetadataCache() + suspend fun clearWatchHistory(): Boolean + suspend fun clearPlaybackStates(): Boolean + suspend fun clearSearchHistory(): Boolean + fun clearRecaptchaCookies() +} + +internal object NoOpHistoryActions : HistoryActions { + + override fun wipeMetadataCache() = logUnsupported("wipeMetadataCache") + + override suspend fun clearWatchHistory() = logUnsupportedAndFail("clearWatchHistory") + + override suspend fun clearPlaybackStates() = logUnsupportedAndFail("clearPlaybackStates") + + override suspend fun clearSearchHistory() = logUnsupportedAndFail("clearSearchHistory") + + override fun clearRecaptchaCookies() = logUnsupported("clearRecaptchaCookies") + + private fun logUnsupported(action: String) = Logger.w(messageString = "History action '$action' is unsupported on this platform") + + private fun logUnsupportedAndFail(action: String): Boolean { + logUnsupported(action) + return false + } +} diff --git a/shared/src/iosMain/kotlin/net/newpipe/app/platform/IOSHistoryActions.kt b/shared/src/iosMain/kotlin/net/newpipe/app/platform/IOSHistoryActions.kt new file mode 100644 index 000000000..cbb2e89d3 --- /dev/null +++ b/shared/src/iosMain/kotlin/net/newpipe/app/platform/IOSHistoryActions.kt @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.platform + +import org.koin.core.annotation.Singleton + +@Singleton(binds = [HistoryActions::class]) +class IOSHistoryActions : HistoryActions by NoOpHistoryActions diff --git a/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMHistoryActions.kt b/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMHistoryActions.kt new file mode 100644 index 000000000..52ba343de --- /dev/null +++ b/shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMHistoryActions.kt @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2026 NewPipe e.V. + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package net.newpipe.app.platform + +import org.koin.core.annotation.Singleton + +@Singleton(binds = [HistoryActions::class]) +class JVMHistoryActions : HistoryActions by NoOpHistoryActions