From bba7372556b7760350d507bb9484043aebfb2050 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 19 Nov 2021 11:28:59 -0500 Subject: [PATCH] Add ability to clear cookies per-extension (closes #3153) --- .../details/ExtensionDetailsController.kt | 19 +++++++++++++++++++ .../ui/setting/SettingsAdvancedController.kt | 3 +-- app/src/main/res/menu/extension_details.xml | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index 8c7cfb2c88..89acafbb3b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -25,10 +25,12 @@ import eu.kanade.tachiyomi.data.preference.minusAssign import eu.kanade.tachiyomi.data.preference.plusAssign import eu.kanade.tachiyomi.databinding.ExtensionDetailControllerBinding import eu.kanade.tachiyomi.extension.model.Extension +import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.getPreferenceKey +import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.openInBrowser import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction @@ -38,8 +40,10 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.switchSettingsPreference import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import okhttp3.HttpUrl.Companion.toHttpUrl import uy.kohesive.injekt.injectLazy @SuppressLint("RestrictedApi") @@ -47,6 +51,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : NucleusController(bundle) { private val preferences: PreferencesHelper by injectLazy() + private val network: NetworkHelper by injectLazy() private var preferenceScreen: PreferenceScreen? = null @@ -199,6 +204,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : R.id.action_history -> openCommitHistory() R.id.action_enable_all -> toggleAllSources(true) R.id.action_disable_all -> toggleAllSources(false) + R.id.action_clear_cookies -> clearCookies() } return super.onOptionsItemSelected(item) } @@ -229,6 +235,19 @@ class ExtensionDetailsController(bundle: Bundle? = null) : openInBrowser(url) } + private fun clearCookies() { + val urls = presenter.extension?.sources + ?.filterIsInstance() + ?.map { it.baseUrl } + ?.distinct() ?: emptyList() + + urls.forEach { + network.cookieManager.remove(it.toHttpUrl()) + } + + logcat { "Cleared cookies for: ${urls.joinToString()}" } + } + private fun Source.isEnabled(): Boolean { return id.toString() !in preferences.disabledSources().get() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 858df6d165..b40608c603 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -43,10 +43,9 @@ import uy.kohesive.injekt.injectLazy import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys class SettingsAdvancedController : SettingsController() { + private val network: NetworkHelper by injectLazy() - private val chapterCache: ChapterCache by injectLazy() - private val db: DatabaseHelper by injectLazy() @SuppressLint("BatteryLife") diff --git a/app/src/main/res/menu/extension_details.xml b/app/src/main/res/menu/extension_details.xml index 81978095f5..d31bb377fd 100644 --- a/app/src/main/res/menu/extension_details.xml +++ b/app/src/main/res/menu/extension_details.xml @@ -18,4 +18,9 @@ android:title="@string/action_disable_all" app:showAsAction="never" /> + +