Notify link=: a stage's public/ file sets the phone tap target
A stage's notify block may name `link=<pattern>` (validated like `open=`). When the hook fires, the newest public/ match is read (at most 4 KiB); its first non-empty line, if an absolute http(s) URL ntfy accepts as a click, becomes the ntfy Click and the app notification click, with the run kept as the app's run action and ntfy's browser view. A missing file or invalid URL keeps today's tap target and is noted on the receipt diagnostic. Android opens such an http(s) click in the browser (after clearing the notification) instead of handing it to Flutter as a route.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package net.awan.pipelines_app
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
@@ -24,12 +26,16 @@ class MainActivity : FlutterActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (savedInstanceState == null) clearOpenedNotification(intent)
|
||||
if (savedInstanceState == null) {
|
||||
clearOpenedNotification(intent)
|
||||
openExternalLink(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
clearOpenedNotification(intent)
|
||||
openExternalLink(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,4 +47,18 @@ class MainActivity : FlutterActivity() {
|
||||
intent.removeExtra(NotificationPresenter.EXTRA_NOTIFICATION_ID)
|
||||
NotificationDismissReceiver.queueClear(this, id)
|
||||
}
|
||||
|
||||
/**
|
||||
* A notification whose click is an http(s) page (a stage's `link=`, such
|
||||
* as a published doc) opens it in the browser rather than as an app route.
|
||||
*/
|
||||
private fun openExternalLink(intent: Intent?) {
|
||||
val link = intent?.getStringExtra(NotificationPresenter.EXTRA_EXTERNAL_LINK) ?: return
|
||||
intent.removeExtra(NotificationPresenter.EXTRA_EXTERNAL_LINK)
|
||||
try {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)).addCategory(Intent.CATEGORY_BROWSABLE))
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
// No browser: the app stays open where the tap left it.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -17,6 +17,8 @@ data class NotificationIntentSpec(
|
||||
val ids: String,
|
||||
val action: String?,
|
||||
val data: String?,
|
||||
/** An http(s) page (a stage's `link=`) MainActivity opens in the browser. */
|
||||
val externalLink: String? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -24,8 +26,9 @@ data class NotificationIntentSpec(
|
||||
* conversation notification with the latest artifact preview and unread count,
|
||||
* keyed by its server group. Thread notifications share a
|
||||
* group per namespace, so Android bundles them under a summary ("N chats",
|
||||
* "N runs"). A tap opens the app at the `click` deep link and clears the
|
||||
* thread; a dismissal is reported back so the server clears it everywhere.
|
||||
* "N runs"). A tap opens the app at the `click` deep link (or an http(s)
|
||||
* click in the browser) and clears the thread; a dismissal is reported back so
|
||||
* the server clears it everywhere.
|
||||
*/
|
||||
class NotificationPresenter(private val context: Context) {
|
||||
private val manager = context.getSystemService(NotificationManager::class.java)
|
||||
@@ -219,6 +222,8 @@ class NotificationPresenter(private val context: Context) {
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
)
|
||||
if (spec.action != null) intent.setAction(spec.action).setData(Uri.parse(spec.data))
|
||||
// Not intent data: Flutter would route it as an app location.
|
||||
if (spec.externalLink != null) intent.putExtra(EXTRA_EXTERNAL_LINK, spec.externalLink)
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
requestCode,
|
||||
@@ -280,11 +285,14 @@ class NotificationPresenter(private val context: Context) {
|
||||
/** Builds the deep-link portion of a tray tap without requiring Android Context. */
|
||||
fun notificationIntent(ids: List<String>, click: String): NotificationIntentSpec {
|
||||
val link = notificationLink(click)
|
||||
val appLink = link.substringBefore(":", "") == "pipelines"
|
||||
val scheme = link.substringBefore(":", "")
|
||||
val appLink = scheme == "pipelines"
|
||||
val external = scheme.lowercase() in setOf("http", "https") && link.startsWith("$scheme://")
|
||||
return NotificationIntentSpec(
|
||||
ids = ids.joinToString("\n"),
|
||||
action = if (appLink) Intent.ACTION_VIEW else null,
|
||||
data = if (appLink) link else null,
|
||||
externalLink = if (external) link else null,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -309,6 +317,8 @@ class NotificationPresenter(private val context: Context) {
|
||||
const val ACCOUNT_CHANNEL = "pipelines.account"
|
||||
/** Holds the server id(s) a tap or dismissal clears, newline-separated. */
|
||||
const val EXTRA_NOTIFICATION_ID = "net.awan.pipelines.notification_id"
|
||||
/** Holds the http(s) page a tap opens in the browser instead of an app route. */
|
||||
const val EXTRA_EXTERNAL_LINK = "net.awan.pipelines.external_link"
|
||||
private val KIND_LABELS = mapOf(
|
||||
"run_waiting" to "Run waiting for you",
|
||||
"run_failed" to "Run failed",
|
||||
|
||||
+14
@@ -45,6 +45,20 @@ class NotificationProtocolTest {
|
||||
val intent = NotificationPresenter.notificationIntent(listOf("n-1"), "")
|
||||
assertNull(intent.action)
|
||||
assertNull(intent.data)
|
||||
assertNull(intent.externalLink)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun externalHttpClickOpensInBrowserNotAsAppRoute() {
|
||||
val doc = "https://claude.ai/public/artifacts/0f3c-standup"
|
||||
val intent = NotificationPresenter.notificationIntent(listOf("n-1"), doc)
|
||||
assertNull(intent.action)
|
||||
assertNull(intent.data)
|
||||
assertEquals(doc, intent.externalLink)
|
||||
assertEquals("n-1", intent.ids)
|
||||
assertNull(NotificationPresenter.notificationIntent(listOf("n-1"), "pipelines://run/7").externalLink)
|
||||
assertNull(NotificationPresenter.notificationIntent(listOf("n-1"), "javascript:alert(1)").externalLink)
|
||||
assertNull(NotificationPresenter.notificationIntent(listOf("n-1"), "https:claude.ai").externalLink)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user