Modern Apps git

← Modern-Apps.git

openassistant: Tools recognize if needed app doesn't exist

Commit
7f8f091803063e3a0dfd3d29b1b9f712b4c40b8f
Author
Vayun Mathur <[email protected]>
When
2026-02-25 22:33 UTC (9 months ago)
Parents
9a9f7b7

Diff

library/src/main/java/com/vayunmathur/library/util/AssistantIntent.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/AssistantIntent.kt b/library/src/main/java/com/vayunmathur/library/util/AssistantIntent.ktindex a4a25a3097..2d8eba2f59 100644--- a/library/src/main/java/com/vayunmathur/library/util/AssistantIntent.kt+++ b/library/src/main/java/com/vayunmathur/library/util/AssistantIntent.kt@@ -1,6 +1,8 @@ package com.vayunmathur.library.util +import android.annotation.SuppressLint import android.app.Activity+import android.content.Context import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity@@ -57,8 +59,10 @@ class IntentLauncher(activity: ComponentActivity) {         continuation = null     } +    @SuppressLint("QueryPermissionsNeeded")     @OptIn(InternalSerializationApi::class)     suspend fun <Input : Any> launch(+        context: Context,         packageName: String,         className: String,         kClass: KClass<Input>,@@ -71,7 +75,26 @@ class IntentLauncher(activity: ComponentActivity) {             putExtra("DATA", Json.encodeToString(kClass.serializer(), input))         } +        // 1. Check if the package/activity is resolvable+        val packageManager = context.packageManager // You'll need access to context+        if (intent.resolveActivity(packageManager) == null) {+            continuation = null+            // Optional onCancellation cleanup+            cont.resume("package $packageName doesn't exist") { cause, _, _ -> // Optional onCancellation cleanup+                // Optional onCancellation cleanup+            }+            return@suspendCancellableCoroutine+        }++        // 2. Setup cancellation logic         cont.invokeOnCancellation { continuation = null }-        launcher.launch(intent)++        // 3. Launch if everything looks good+        try {+            launcher.launch(intent)+        } catch (e: Exception) {+            continuation = null+            cont.resume("package $packageName doesn't exist")+        }     } }\ No newline at end of file
openassistant/src/main/java/com/vayunmathur/openassistant/data/Tools.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/data/Tools.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/data/Tools.ktindex 8d763c9aeb..e0f1c9388a 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/data/Tools.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/data/Tools.kt@@ -159,15 +159,15 @@ class Tools {                     }                 }             },-            ToolSimple("get_notes", "Get a list of notes (and their content) on the user's phone", listOf()) { _, _ ->-                ToolResult(intentLauncher.launch("com.vayunmathur.notes", "com.vayunmathur.notes.intents.GetIntent", Unit::class, Unit), "Retrieved notes")+            ToolSimple("get_notes", "Get a list of notes (and their content) on the user's phone", listOf()) { _, context ->+                ToolResult(intentLauncher.launch(context,"com.vayunmathur.notes", "com.vayunmathur.notes.intents.GetIntent", Unit::class, Unit), "Retrieved notes")             },             ToolSimple("insert_note", "Add a note to the user's phone", listOf(                 stringParam("title", "the title of the note"),                 stringParam("content", "the content of the note")-            )) { args, _ ->+            )) { args, context ->                 val input = InsertNoteData(args["title"]!!.jsonPrimitive.content, args["content"]!!.jsonPrimitive.content)-                ToolResult(intentLauncher.launch("com.vayunmathur.notes", "com.vayunmathur.notes.intents.InsertIntent", InsertNoteData::class, input), "Added notes")+                ToolResult(intentLauncher.launch(context,"com.vayunmathur.notes", "com.vayunmathur.notes.intents.InsertIntent", InsertNoteData::class, input), "Added notes")             }         )