From 4fa86dbf036897b0e315e6a94cb4de6f187f3a33 Mon Sep 17 00:00:00 2001 From: kari-ts <135075563+kari-ts@users.noreply.github.com> Date: Fri, 17 May 2024 15:16:25 -0700 Subject: [PATCH] App: tap on notification brings up main view (#407) Updates tailscale/tailscale#10104 Signed-off-by: kari-ts --- .../src/main/java/com/tailscale/ipn/App.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/tailscale/ipn/App.kt b/android/src/main/java/com/tailscale/ipn/App.kt index d4f0acd..05ddd66 100644 --- a/android/src/main/java/com/tailscale/ipn/App.kt +++ b/android/src/main/java/com/tailscale/ipn/App.kt @@ -404,10 +404,22 @@ open class UninitializedApp : Application() { val action = if (vpnRunning) IPNReceiver.INTENT_DISCONNECT_VPN else IPNReceiver.INTENT_CONNECT_VPN val actionLabel = getString(if (vpnRunning) R.string.disconnect else R.string.connect) - val intent = Intent(this, IPNReceiver::class.java).apply { this.action = action } - val pendingIntent: PendingIntent = + val buttonIntent = Intent(this, IPNReceiver::class.java).apply { this.action = action } + val pendingButtonIntent: PendingIntent = PendingIntent.getBroadcast( - this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + this, + 0, + buttonIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + + val intent = + Intent(this, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + } + val pendingIntent: PendingIntent = + PendingIntent.getActivity( + this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + return NotificationCompat.Builder(this, STATUS_CHANNEL_ID) .setSmallIcon(icon) .setContentTitle("Tailscale") @@ -417,7 +429,8 @@ open class UninitializedApp : Application() { .setOngoing(vpnRunning) .setSilent(true) .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .addAction(NotificationCompat.Action.Builder(0, actionLabel, pendingIntent).build()) + .addAction(NotificationCompat.Action.Builder(0, actionLabel, pendingButtonIntent).build()) + .setContentIntent(pendingIntent) .build() } }