diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/NostrForegroundService.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/NostrForegroundService.kt index 48e9bc3..41e99f8 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/NostrForegroundService.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/NostrForegroundService.kt @@ -30,9 +30,10 @@ class NostrForegroundService : Service() { return ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED) } - @RequiresApi(Build.VERSION_CODES.O) override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - createNotificationChannel() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + createNotificationChannel() + } val notification = createNotification() startForeground(1, notification) @@ -78,7 +79,7 @@ class NostrForegroundService : Service() { val manager = getSystemService(NotificationManager::class.java) val serviceChannel = NotificationChannel( - "nostr_service_silent", + "nostr_service", "Nostr Background Status", NotificationManager.IMPORTANCE_MIN ).apply { @@ -127,7 +128,7 @@ class NostrForegroundService : Service() { intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) - + val notification = NotificationCompat.Builder(this, "nostr_messages") .setSmallIcon(R.drawable.ic_notification) .setContentTitle("You received a new message") diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index acf0b18..b78eb72 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -202,19 +202,24 @@ class NostrViewModel( private fun login() { viewModelScope.launch { - val secret = secretStore.get("user_signer") + try { + val secret = secretStore.get("user_signer") - if (secret == null) { - _signerRequired.value = true - return@launch - } + if (secret == null) { + _signerRequired.value = true + return@launch + } - runCatching { - val signer = createSigner(secret) - nostr.setSigner(signer) - }.onSuccess { - _signerRequired.value = false - }.onFailure { e -> + runCatching { + val signer = createSigner(secret) + nostr.setSigner(signer) + }.onSuccess { + _signerRequired.value = false + }.onFailure { e -> + showError("Login failed: ${e.message}") + _signerRequired.value = true + } + } catch (e: Exception) { showError("Login failed: ${e.message}") _signerRequired.value = true }