git.iko.soy/opencode-android
on 066cded help sign in
50 lines 2.4 kB history raw
1package soy.iko.opencode.notification
3import android.app.NotificationChannel
4import android.app.NotificationManager
5import android.content.Context
6import soy.iko.opencode.R
8/**
9 * The app's notification channels. Created once at startup (idempotent — recreating an
10 * existing channel is a no-op). Two channels keep user control granular:
11 *
12 * - [STATUS]: low-importance, no sound. Used by the foreground service's persistent
13 * "agent running" indicator.
14 * - [COMPLETED]: default importance. Used when a background session finishes a run.
15 * - [PERMISSION]: high importance (heads-up + sound). Used when a paused tool run needs
16 * the user's approval — the whole point is to reach the user who has walked away, so it
17 * interrupts rather than sitting silently in the shade.
18 * - [ERROR]: default importance. Used when a background run fails.
19 */
20object NotificationChannels {
21 const val STATUS = "run_status"
22 const val COMPLETED = "session_completed"
23 const val PERMISSION = "permission_request"
24 const val ERROR = "session_error"
26 fun create(context: Context) {
27 val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager ?: return
28 nm.createNotificationChannel(
29 NotificationChannel(STATUS, context.getString(R.string.notif_channel_status), NotificationManager.IMPORTANCE_LOW).apply {
30 description = context.getString(R.string.notif_channel_status_desc)
31 setShowBadge(false)
32 },
33 )
34 nm.createNotificationChannel(
35 NotificationChannel(COMPLETED, context.getString(R.string.notif_channel_completed), NotificationManager.IMPORTANCE_DEFAULT).apply {
36 description = context.getString(R.string.notif_channel_completed_desc)
37 },
38 )
39 nm.createNotificationChannel(
40 NotificationChannel(PERMISSION, context.getString(R.string.notif_channel_permission), NotificationManager.IMPORTANCE_HIGH).apply {
41 description = context.getString(R.string.notif_channel_permission_desc)
42 },
43 )
44 nm.createNotificationChannel(
45 NotificationChannel(ERROR, context.getString(R.string.notif_channel_error), NotificationManager.IMPORTANCE_DEFAULT).apply {
46 description = context.getString(R.string.notif_channel_error_desc)
47 },
48 )
49 }