ReviewOS

also looking at this

craft-native/craft

feat(android): the clipboard pair — ratchet 100 -> 98

#144
Merged glennmichael123 wants to merge feat/android-clipboard into main
6 files +414 -3
packages/android/templates/CraftNative.kt.templatemodified+29-0
Changes to packages/android/templates/CraftNative.kt.template
@@ -59,6 +59,8 @@ object CraftNative {
5959 private external fun nativeGetDeviceInfo(activity: Activity): String?
6060 private external fun nativeGetMemoryUsage(): String?
6161 private external fun nativeLog(message: String): Boolean
62 private external fun nativeClipboardRead(activity: Activity): String?
63 private external fun nativeClipboardWrite(activity: Activity, text: String): Boolean
6264
6365 /**
6466 * `getDeviceInfo`, or null to use the Kotlin implementation.
@@ -105,4 +107,31 @@ object CraftNative {
105107 false
106108 }
107109 }
110
111 /**
112 * The clipboard's text, or null to use the Kotlin implementation.
113 *
114 * Null and `""` are different answers and both are normal: null means Zig
115 * did not serve this call, `""` means the clipboard is empty — which since
116 * Android 10 is what an app without focus sees every time. Collapsing them
117 * would make an empty clipboard fall through and be read twice.
118 */
119 fun clipboardRead(activity: Activity): String? {
120 if (!isAvailable) return null
121 return try {
122 nativeClipboardRead(activity)
123 } catch (e: UnsatisfiedLinkError) {
124 null
125 }
126 }
127
128 /** Returns whether Zig wrote the clipboard; false falls through. */
129 fun clipboardWrite(activity: Activity, text: String): Boolean {
130 if (!isAvailable) return false
131 return try {
132 nativeClipboardWrite(activity, text)
133 } catch (e: UnsatisfiedLinkError) {
134 false
135 }
136 }
108137}