mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 11:28:22 +00:00
Add a warning when the kill switch is enabled
This commit is contained in:
@@ -229,7 +229,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
isStartingApp.value = false
|
||||
|
||||
checkForNewRelaysAndUpdateAllFilters(true)
|
||||
if (settings.killSwitch) {
|
||||
if (settings.killSwitch.value) {
|
||||
client.disconnect()
|
||||
}
|
||||
launch(Dispatchers.Main) {
|
||||
@@ -239,7 +239,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
isAppInForeground = true
|
||||
|
||||
// activates the profile filter only when the app is in the foreground
|
||||
if (!settings.killSwitch) {
|
||||
if (!settings.killSwitch.value) {
|
||||
applicationIOScope.launch {
|
||||
profileSubscription.updateFilter()
|
||||
}
|
||||
@@ -277,7 +277,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
}
|
||||
|
||||
fun reconnect() {
|
||||
if (settings.killSwitch) {
|
||||
if (settings.killSwitch.value) {
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "reconnecting relays")
|
||||
@@ -315,7 +315,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
suspend fun checkForNewRelaysAndUpdateAllFilters(
|
||||
shouldReconnect: Boolean = false,
|
||||
) {
|
||||
if (settings.killSwitch) {
|
||||
if (settings.killSwitch.value) {
|
||||
client.disconnect()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ object LocalPreferences {
|
||||
putBoolean(SettingsKeys.USE_PIN.key, settings.usePin)
|
||||
putBoolean(SettingsKeys.USE_PROXY.key, settings.useProxy)
|
||||
putInt(SettingsKeys.PROXY_PORT.key, settings.proxyPort)
|
||||
putBoolean(SettingsKeys.KILL_SWITCH.key, settings.killSwitch)
|
||||
putBoolean(SettingsKeys.KILL_SWITCH.key, settings.killSwitch.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ object LocalPreferences {
|
||||
usePin = getBoolean(SettingsKeys.USE_PIN.key, false),
|
||||
useProxy = getBoolean(SettingsKeys.USE_PROXY.key, false),
|
||||
proxyPort = getInt(SettingsKeys.PROXY_PORT.key, 9050),
|
||||
killSwitch = getBoolean(SettingsKeys.KILL_SWITCH.key, false),
|
||||
killSwitch = MutableStateFlow(getBoolean(SettingsKeys.KILL_SWITCH.key, false)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.greenart7c3.nostrsigner.models
|
||||
import com.greenart7c3.nostrsigner.ui.BiometricsTimeType
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
val defaultAppRelays = listOf(
|
||||
RelayUrlNormalizer.normalize("wss://relay.nsec.app/"),
|
||||
@@ -25,5 +26,5 @@ data class AmberSettings(
|
||||
val usePin: Boolean = false,
|
||||
val useProxy: Boolean = false,
|
||||
val proxyPort: Int = 9050,
|
||||
val killSwitch: Boolean = false,
|
||||
val killSwitch: MutableStateFlow<Boolean> = MutableStateFlow(false),
|
||||
)
|
||||
|
||||
@@ -137,7 +137,7 @@ class AmberRelayStats(
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentIntent(contentPendingIntent)
|
||||
.addAction(R.drawable.ic_notification, appContext.getString(R.string.reconnect), reconnectPendingIntent)
|
||||
.addAction(R.drawable.ic_notification, appContext.getString(if (Amber.instance.settings.killSwitch) R.string.disable_kill_switch else R.string.enable_kill_switch), killSwitchPendingIntent)
|
||||
.addAction(R.drawable.ic_notification, appContext.getString(if (Amber.instance.settings.killSwitch.value) R.string.disable_kill_switch else R.string.enable_kill_switch), killSwitchPendingIntent)
|
||||
|
||||
return notificationBuilder.build()
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class ConnectivityService : Service() {
|
||||
super.onAvailable(network)
|
||||
@Suppress("KotlinConstantConditions")
|
||||
if (BuildConfig.FLAVOR == "offline") return
|
||||
if (Amber.instance.settings.killSwitch) return
|
||||
if (Amber.instance.settings.killSwitch.value) return
|
||||
|
||||
if (lastNetwork != null && lastNetwork != network) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
@@ -52,7 +52,7 @@ class ConnectivityService : Service() {
|
||||
|
||||
@Suppress("KotlinConstantConditions")
|
||||
if (BuildConfig.FLAVOR == "offline") return
|
||||
if (Amber.instance.settings.killSwitch) return
|
||||
if (Amber.instance.settings.killSwitch.value) return
|
||||
|
||||
scope.launch(Dispatchers.IO) {
|
||||
Log.d(
|
||||
@@ -97,7 +97,7 @@ class ConnectivityService : Service() {
|
||||
delay(1000)
|
||||
}
|
||||
@Suppress("KotlinConstantConditions")
|
||||
if (BuildConfig.FLAVOR != "offline" && !Amber.instance.settings.killSwitch) {
|
||||
if (BuildConfig.FLAVOR != "offline" && !Amber.instance.settings.killSwitch.value) {
|
||||
Amber.instance.client.connect()
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
Amber.instance.checkForNewRelaysAndUpdateAllFilters()
|
||||
@@ -121,7 +121,7 @@ class ConnectivityService : Service() {
|
||||
if (BuildConfig.FLAVOR == "offline") {
|
||||
return
|
||||
}
|
||||
if (Amber.instance.settings.killSwitch) return
|
||||
if (Amber.instance.settings.killSwitch.value) return
|
||||
|
||||
scope.launch {
|
||||
if (!Amber.instance.client.isActive()) {
|
||||
|
||||
@@ -10,9 +10,9 @@ import kotlinx.coroutines.launch
|
||||
class KillSwitchReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
Amber.instance.settings = Amber.instance.settings.copy(killSwitch = !Amber.instance.settings.killSwitch)
|
||||
Amber.instance.settings.killSwitch.emit(!Amber.instance.settings.killSwitch.value)
|
||||
LocalPreferences.saveSettingsToEncryptedStorage(Amber.instance.settings)
|
||||
if (Amber.instance.settings.killSwitch) {
|
||||
if (Amber.instance.settings.killSwitch.value) {
|
||||
Amber.instance.client.disconnect()
|
||||
} else {
|
||||
Amber.instance.checkForNewRelaysAndUpdateAllFilters(shouldReconnect = true)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.greenart7c3.nostrsigner.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@@ -10,6 +11,7 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -35,9 +37,11 @@ import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.NavController
|
||||
import com.greenart7c3.nostrsigner.Amber
|
||||
import com.greenart7c3.nostrsigner.LocalPreferences
|
||||
import com.greenart7c3.nostrsigner.R
|
||||
import com.greenart7c3.nostrsigner.models.Account
|
||||
import com.greenart7c3.nostrsigner.models.TimeUtils
|
||||
import com.greenart7c3.nostrsigner.service.KillSwitchReceiver
|
||||
import com.greenart7c3.nostrsigner.service.toShortenHex
|
||||
import com.greenart7c3.nostrsigner.ui.components.AmberButton
|
||||
import com.greenart7c3.nostrsigner.ui.navigation.Route
|
||||
@@ -53,7 +57,48 @@ fun ApplicationsScreen(
|
||||
Column(
|
||||
modifier,
|
||||
) {
|
||||
val killSwitch = Amber.instance.settings.killSwitch.collectAsStateWithLifecycle()
|
||||
if (killSwitch.value) {
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.kill_switch_message),
|
||||
modifier = Modifier.wrapContentSize(),
|
||||
color = Color.Black,
|
||||
)
|
||||
TextButton(
|
||||
onClick = {
|
||||
val killSwitchIntent = Intent(Amber.instance, KillSwitchReceiver::class.java)
|
||||
Amber.instance.sendBroadcast(killSwitchIntent)
|
||||
LocalPreferences.switchToAccount(Amber.instance, account.npub)
|
||||
},
|
||||
content = {
|
||||
Text(
|
||||
text = stringResource(R.string.disable_kill_switch),
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!account.didBackup) {
|
||||
if (killSwitch.value) {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
}
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
|
||||
@@ -552,4 +552,5 @@
|
||||
<string name="default_relay_text">Default</string>
|
||||
<string name="enable_kill_switch">Enable kill switch</string>
|
||||
<string name="disable_kill_switch">Disable kill switch</string>
|
||||
<string name="kill_switch_message">Kill Switch enabled, remote login and profile fetching will not work</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user