mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 10:59:15 +01:00
Add ability to clear cookies per-extension (closes #3153)
This commit is contained in:
parent
9fe1a7e2ae
commit
bba7372556
@ -25,10 +25,12 @@ import eu.kanade.tachiyomi.data.preference.minusAssign
|
|||||||
import eu.kanade.tachiyomi.data.preference.plusAssign
|
import eu.kanade.tachiyomi.data.preference.plusAssign
|
||||||
import eu.kanade.tachiyomi.databinding.ExtensionDetailControllerBinding
|
import eu.kanade.tachiyomi.databinding.ExtensionDetailControllerBinding
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.getPreferenceKey
|
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.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.openInBrowser
|
import eu.kanade.tachiyomi.ui.base.controller.openInBrowser
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
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.switchPreference
|
||||||
import eu.kanade.tachiyomi.util.preference.switchSettingsPreference
|
import eu.kanade.tachiyomi.util.preference.switchSettingsPreference
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||||
|
import eu.kanade.tachiyomi.util.system.logcat
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
@ -47,6 +51,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
NucleusController<ExtensionDetailControllerBinding, ExtensionDetailsPresenter>(bundle) {
|
NucleusController<ExtensionDetailControllerBinding, ExtensionDetailsPresenter>(bundle) {
|
||||||
|
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
private val network: NetworkHelper by injectLazy()
|
||||||
|
|
||||||
private var preferenceScreen: PreferenceScreen? = null
|
private var preferenceScreen: PreferenceScreen? = null
|
||||||
|
|
||||||
@ -199,6 +204,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
R.id.action_history -> openCommitHistory()
|
R.id.action_history -> openCommitHistory()
|
||||||
R.id.action_enable_all -> toggleAllSources(true)
|
R.id.action_enable_all -> toggleAllSources(true)
|
||||||
R.id.action_disable_all -> toggleAllSources(false)
|
R.id.action_disable_all -> toggleAllSources(false)
|
||||||
|
R.id.action_clear_cookies -> clearCookies()
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
@ -229,6 +235,19 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
openInBrowser(url)
|
openInBrowser(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearCookies() {
|
||||||
|
val urls = presenter.extension?.sources
|
||||||
|
?.filterIsInstance<HttpSource>()
|
||||||
|
?.map { it.baseUrl }
|
||||||
|
?.distinct() ?: emptyList()
|
||||||
|
|
||||||
|
urls.forEach {
|
||||||
|
network.cookieManager.remove(it.toHttpUrl())
|
||||||
|
}
|
||||||
|
|
||||||
|
logcat { "Cleared cookies for: ${urls.joinToString()}" }
|
||||||
|
}
|
||||||
|
|
||||||
private fun Source.isEnabled(): Boolean {
|
private fun Source.isEnabled(): Boolean {
|
||||||
return id.toString() !in preferences.disabledSources().get()
|
return id.toString() !in preferences.disabledSources().get()
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,9 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||||
|
|
||||||
class SettingsAdvancedController : SettingsController() {
|
class SettingsAdvancedController : SettingsController() {
|
||||||
|
|
||||||
private val network: NetworkHelper by injectLazy()
|
private val network: NetworkHelper by injectLazy()
|
||||||
|
|
||||||
private val chapterCache: ChapterCache by injectLazy()
|
private val chapterCache: ChapterCache by injectLazy()
|
||||||
|
|
||||||
private val db: DatabaseHelper by injectLazy()
|
private val db: DatabaseHelper by injectLazy()
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
@SuppressLint("BatteryLife")
|
||||||
|
@ -18,4 +18,9 @@
|
|||||||
android:title="@string/action_disable_all"
|
android:title="@string/action_disable_all"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_clear_cookies"
|
||||||
|
android:title="@string/pref_clear_cookies"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
Loading…
Reference in New Issue
Block a user