Merge pull request #54 from wunter8/disable-unified-push-toggle
add toggle to disable UnifiedPush
This commit is contained in:
commit
58e522b846
6 changed files with 44 additions and 0 deletions
|
@ -292,6 +292,16 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getUnifiedPushEnabled(): Boolean {
|
||||||
|
return sharedPrefs.getBoolean(SHARED_PREFS_UNIFIEDPUSH_ENABLED, true) // Enabled by default
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setUnifiedPushEnabled(enabled: Boolean) {
|
||||||
|
sharedPrefs.edit()
|
||||||
|
.putBoolean(SHARED_PREFS_UNIFIEDPUSH_ENABLED, enabled)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
|
||||||
fun getInsistentMaxPriorityEnabled(): Boolean {
|
fun getInsistentMaxPriorityEnabled(): Boolean {
|
||||||
return sharedPrefs.getBoolean(SHARED_PREFS_INSISTENT_MAX_PRIORITY_ENABLED, false) // Disabled by default
|
return sharedPrefs.getBoolean(SHARED_PREFS_INSISTENT_MAX_PRIORITY_ENABLED, false) // Disabled by default
|
||||||
}
|
}
|
||||||
|
@ -477,6 +487,7 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
|
||||||
const val SHARED_PREFS_CONNECTION_PROTOCOL = "ConnectionProtocol"
|
const val SHARED_PREFS_CONNECTION_PROTOCOL = "ConnectionProtocol"
|
||||||
const val SHARED_PREFS_DARK_MODE = "DarkMode"
|
const val SHARED_PREFS_DARK_MODE = "DarkMode"
|
||||||
const val SHARED_PREFS_BROADCAST_ENABLED = "BroadcastEnabled"
|
const val SHARED_PREFS_BROADCAST_ENABLED = "BroadcastEnabled"
|
||||||
|
const val SHARED_PREFS_UNIFIEDPUSH_ENABLED = "UnifiedPushEnabled"
|
||||||
const val SHARED_PREFS_INSISTENT_MAX_PRIORITY_ENABLED = "InsistentMaxPriority"
|
const val SHARED_PREFS_INSISTENT_MAX_PRIORITY_ENABLED = "InsistentMaxPriority"
|
||||||
const val SHARED_PREFS_RECORD_LOGS_ENABLED = "RecordLogs"
|
const val SHARED_PREFS_RECORD_LOGS_ENABLED = "RecordLogs"
|
||||||
const val SHARED_PREFS_BATTERY_OPTIMIZATIONS_REMIND_TIME = "BatteryOptimizationsRemindTime"
|
const val SHARED_PREFS_BATTERY_OPTIMIZATIONS_REMIND_TIME = "BatteryOptimizationsRemindTime"
|
||||||
|
|
|
@ -364,6 +364,26 @@ class SettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.OnPrefere
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable UnifiedPush
|
||||||
|
val unifiedPushEnabledPrefId = context?.getString(R.string.settings_advanced_unifiedpush_key) ?: return
|
||||||
|
val unifiedPushEnabled: SwitchPreference? = findPreference(unifiedPushEnabledPrefId)
|
||||||
|
unifiedPushEnabled?.isChecked = repository.getUnifiedPushEnabled()
|
||||||
|
unifiedPushEnabled?.preferenceDataStore = object : PreferenceDataStore() {
|
||||||
|
override fun putBoolean(key: String?, value: Boolean) {
|
||||||
|
repository.setUnifiedPushEnabled(value)
|
||||||
|
}
|
||||||
|
override fun getBoolean(key: String?, defValue: Boolean): Boolean {
|
||||||
|
return repository.getUnifiedPushEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unifiedPushEnabled?.summaryProvider = Preference.SummaryProvider<SwitchPreference> { pref ->
|
||||||
|
if (pref.isChecked) {
|
||||||
|
getString(R.string.settings_advanced_unifiedpush_summary_enabled)
|
||||||
|
} else {
|
||||||
|
getString(R.string.settings_advanced_unifiedpush_summary_disabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Export logs
|
// Export logs
|
||||||
val exportLogsPrefId = context?.getString(R.string.settings_advanced_export_logs_key) ?: return
|
val exportLogsPrefId = context?.getString(R.string.settings_advanced_export_logs_key) ?: return
|
||||||
val exportLogs: ListPreference? = findPreference(exportLogsPrefId)
|
val exportLogs: ListPreference? = findPreference(exportLogsPrefId)
|
||||||
|
|
|
@ -38,6 +38,11 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
|
||||||
val repository = app.repository
|
val repository = app.repository
|
||||||
val distributor = Distributor(app)
|
val distributor = Distributor(app)
|
||||||
Log.d(TAG, "REGISTER received for app $appId (connectorToken=$connectorToken)")
|
Log.d(TAG, "REGISTER received for app $appId (connectorToken=$connectorToken)")
|
||||||
|
if (!repository.getUnifiedPushEnabled()) {
|
||||||
|
Log.w(TAG, "Refusing registration because 'EnableUP' is disabled")
|
||||||
|
distributor.sendRegistrationFailed(appId, connectorToken, "UnifiedPush is disabled in ntfy")
|
||||||
|
return
|
||||||
|
}
|
||||||
if (appId.isBlank()) {
|
if (appId.isBlank()) {
|
||||||
Log.w(TAG, "Refusing registration: Empty application")
|
Log.w(TAG, "Refusing registration: Empty application")
|
||||||
distributor.sendRegistrationFailed(appId, connectorToken, "Empty application string")
|
distributor.sendRegistrationFailed(appId, connectorToken, "Empty application string")
|
||||||
|
|
|
@ -320,6 +320,9 @@
|
||||||
<string name="settings_advanced_broadcast_title">Broadcast messages</string>
|
<string name="settings_advanced_broadcast_title">Broadcast messages</string>
|
||||||
<string name="settings_advanced_broadcast_summary_enabled">Apps can receive incoming notifications as broadcasts</string>
|
<string name="settings_advanced_broadcast_summary_enabled">Apps can receive incoming notifications as broadcasts</string>
|
||||||
<string name="settings_advanced_broadcast_summary_disabled">Apps cannot receive notifications as broadcasts</string>
|
<string name="settings_advanced_broadcast_summary_disabled">Apps cannot receive notifications as broadcasts</string>
|
||||||
|
<string name="settings_advanced_unifiedpush_title">Enable UnifiedPush</string>
|
||||||
|
<string name="settings_advanced_unifiedpush_summary_enabled">ntfy will act as a UnifiedPush distributor</string>
|
||||||
|
<string name="settings_advanced_unifiedpush_summary_disabled">ntfy will not act as a UnifiedPush distributor</string>
|
||||||
<string name="settings_advanced_record_logs_title">Record logs</string>
|
<string name="settings_advanced_record_logs_title">Record logs</string>
|
||||||
<string name="settings_advanced_record_logs_summary_enabled">Logging (up to 1,000 entries) to device …</string>
|
<string name="settings_advanced_record_logs_summary_enabled">Logging (up to 1,000 entries) to device …</string>
|
||||||
<string name="settings_advanced_record_logs_summary_disabled">Turn on logging, so you can share logs later to diagnose issues.</string>
|
<string name="settings_advanced_record_logs_summary_disabled">Turn on logging, so you can share logs later to diagnose issues.</string>
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<string name="settings_backup_restore_backup_key" translatable="false">Backup</string>
|
<string name="settings_backup_restore_backup_key" translatable="false">Backup</string>
|
||||||
<string name="settings_backup_restore_restore_key" translatable="false">Restore</string>
|
<string name="settings_backup_restore_restore_key" translatable="false">Restore</string>
|
||||||
<string name="settings_advanced_broadcast_key" translatable="false">BroadcastEnabled</string>
|
<string name="settings_advanced_broadcast_key" translatable="false">BroadcastEnabled</string>
|
||||||
|
<string name="settings_advanced_unifiedpush_key" translatable="false">UnifiedPushEnabled</string>
|
||||||
<string name="settings_advanced_record_logs_key" translatable="false">RecordLogs</string>
|
<string name="settings_advanced_record_logs_key" translatable="false">RecordLogs</string>
|
||||||
<string name="settings_advanced_export_logs_key" translatable="false">ExportLogs</string>
|
<string name="settings_advanced_export_logs_key" translatable="false">ExportLogs</string>
|
||||||
<string name="settings_advanced_clear_logs_key" translatable="false">ClearLogs</string>
|
<string name="settings_advanced_clear_logs_key" translatable="false">ClearLogs</string>
|
||||||
|
|
|
@ -76,6 +76,10 @@
|
||||||
app:key="@string/settings_advanced_broadcast_key"
|
app:key="@string/settings_advanced_broadcast_key"
|
||||||
app:title="@string/settings_advanced_broadcast_title"
|
app:title="@string/settings_advanced_broadcast_title"
|
||||||
app:enabled="true"/>
|
app:enabled="true"/>
|
||||||
|
<SwitchPreference
|
||||||
|
app:key="@string/settings_advanced_unifiedpush_key"
|
||||||
|
app:title="@string/settings_advanced_unifiedpush_title"
|
||||||
|
app:enabled="true"/>
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
app:key="@string/settings_advanced_record_logs_key"
|
app:key="@string/settings_advanced_record_logs_key"
|
||||||
app:title="@string/settings_advanced_record_logs_title"
|
app:title="@string/settings_advanced_record_logs_title"
|
||||||
|
|
Loading…
Reference in a new issue