Don't allow setting blank user agent string

This commit is contained in:
arkon 2022-08-19 08:23:55 -04:00
parent 47b56644de
commit 3760b310df
2 changed files with 16 additions and 10 deletions

View File

@ -229,22 +229,27 @@ class SettingsAdvancedController(
summary = network.defaultUserAgent summary = network.defaultUserAgent
onChange { onChange {
if (it.toString().isBlank()) {
activity?.toast(R.string.error_user_agent_string_blank)
false
} else {
activity?.toast(R.string.requires_app_restart) activity?.toast(R.string.requires_app_restart)
true true
} }
} }
if (preferences.defaultUserAgent().isSet()) { }
preference { preference {
key = "pref_reset_user_agent" key = "pref_reset_user_agent"
titleRes = R.string.pref_reset_user_agent_string titleRes = R.string.pref_reset_user_agent_string
visibleIf(preferences.defaultUserAgent()) { it != preferences.defaultUserAgent().defaultValue }
onClick { onClick {
preferences.defaultUserAgent().delete() preferences.defaultUserAgent().delete()
activity?.toast(R.string.requires_app_restart) activity?.toast(R.string.requires_app_restart)
} }
} }
} }
}
preferenceCategory { preferenceCategory {
titleRes = R.string.label_library titleRes = R.string.label_library

View File

@ -475,6 +475,7 @@
<string name="pref_clear_cookies">Clear cookies</string> <string name="pref_clear_cookies">Clear cookies</string>
<string name="pref_dns_over_https">DNS over HTTPS (DoH)</string> <string name="pref_dns_over_https">DNS over HTTPS (DoH)</string>
<string name="pref_user_agent_string">Default user agent string</string> <string name="pref_user_agent_string">Default user agent string</string>
<string name="error_user_agent_string_blank">User agent string can not be blank</string>
<string name="pref_reset_user_agent_string">Reset default user agent string</string> <string name="pref_reset_user_agent_string">Reset default user agent string</string>
<string name="requires_app_restart">Requires app restart to take effect</string> <string name="requires_app_restart">Requires app restart to take effect</string>
<string name="cookies_cleared">Cookies cleared</string> <string name="cookies_cleared">Cookies cleared</string>