This commit is contained in:
2026-05-31 08:27:38 +07:00
parent 31c2760b93
commit 9293d0f76f
2 changed files with 21 additions and 15 deletions

View File

@@ -30,9 +30,10 @@ class NostrForegroundService : Service() {
return ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED) return ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)
} }
@RequiresApi(Build.VERSION_CODES.O)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
createNotificationChannel() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
}
val notification = createNotification() val notification = createNotification()
startForeground(1, notification) startForeground(1, notification)
@@ -78,7 +79,7 @@ class NostrForegroundService : Service() {
val manager = getSystemService(NotificationManager::class.java) val manager = getSystemService(NotificationManager::class.java)
val serviceChannel = NotificationChannel( val serviceChannel = NotificationChannel(
"nostr_service_silent", "nostr_service",
"Nostr Background Status", "Nostr Background Status",
NotificationManager.IMPORTANCE_MIN NotificationManager.IMPORTANCE_MIN
).apply { ).apply {
@@ -127,7 +128,7 @@ class NostrForegroundService : Service() {
intent, intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
val notification = NotificationCompat.Builder(this, "nostr_messages") val notification = NotificationCompat.Builder(this, "nostr_messages")
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
.setContentTitle("You received a new message") .setContentTitle("You received a new message")

View File

@@ -202,19 +202,24 @@ class NostrViewModel(
private fun login() { private fun login() {
viewModelScope.launch { viewModelScope.launch {
val secret = secretStore.get("user_signer") try {
val secret = secretStore.get("user_signer")
if (secret == null) { if (secret == null) {
_signerRequired.value = true _signerRequired.value = true
return@launch return@launch
} }
runCatching { runCatching {
val signer = createSigner(secret) val signer = createSigner(secret)
nostr.setSigner(signer) nostr.setSigner(signer)
}.onSuccess { }.onSuccess {
_signerRequired.value = false _signerRequired.value = false
}.onFailure { e -> }.onFailure { e ->
showError("Login failed: ${e.message}")
_signerRequired.value = true
}
} catch (e: Exception) {
showError("Login failed: ${e.message}") showError("Login failed: ${e.message}")
_signerRequired.value = true _signerRequired.value = true
} }