Option to disable captcha notification for specific source (#1253 #1300)

This commit is contained in:
Koitharu
2025-02-24 14:39:16 +02:00
parent c835ebff3f
commit 1fa470fd00
4 changed files with 21 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
import org.koitharu.kotatsu.core.model.getTitle
import org.koitharu.kotatsu.core.model.isNsfw
import org.koitharu.kotatsu.core.nav.AppRouter
import org.koitharu.kotatsu.core.prefs.SourceSettings
import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission
import org.koitharu.kotatsu.parsers.model.MangaSource
@@ -29,6 +30,9 @@ class CaptchaNotifier(
if (!context.checkNotificationPermission(CHANNEL_ID)) {
return
}
if (exception.source != null && SourceSettings(context, exception.source).isCaptchaNotificationsDisabled) {
return
}
val manager = NotificationManagerCompat.from(context)
val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW)
.setName(context.getString(R.string.captcha_required))

View File

@@ -25,6 +25,9 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
val isSlowdownEnabled: Boolean
get() = prefs.getBoolean(KEY_SLOWDOWN, false)
val isCaptchaNotificationsDisabled: Boolean
get() = prefs.getBoolean(KEY_NO_CAPTCHA, false)
@Suppress("UNCHECKED_CAST")
override fun <T> get(key: ConfigKey<T>): T {
return when (key) {
@@ -65,5 +68,6 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
const val KEY_SORT_ORDER = "sort_order"
const val KEY_SLOWDOWN = "slowdown"
const val KEY_NO_CAPTCHA = "no_captcha"
}
}

View File

@@ -804,4 +804,6 @@
<string name="search_everywhere">Search everywhere</string>
<string name="simple">Simple</string>
<string name="global_search">Global search</string>
<string name="disable_captcha_notifications">Disable captcha notifications</string>
<string name="disable_captcha_notifications_summary">You will not receive notifications about solving CAPTCHA for this source but this can lead to breaking background operations (checking for new chapters, obtaining recommendations, etc)</string>
</resources>

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<SwitchPreferenceCompat
android:defaultValue="false"
@@ -11,6 +12,13 @@
android:persistent="false"
android:title="@string/enable_source" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="no_captcha"
android:order="104"
android:summary="@string/disable_captcha_notifications_summary"
android:title="@string/disable_captcha_notifications" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="slowdown"
@@ -25,6 +33,7 @@
android:persistent="false"
android:title="@string/open_in_browser"
app:allowDividerAbove="true"
app:isPreferenceVisible="false" />
app:isPreferenceVisible="false"
tools:isPreferenceVisible="true" />
</PreferenceScreen>