also looking at this
feat(android): the clipboard pair — ratchet 100 -> 98
#144
6 files
+414
-3
| @@ -59,6 +59,8 @@ object CraftNative { | ||
| 59 | 59 | private external fun nativeGetDeviceInfo(activity: Activity): String? |
| 60 | 60 | private external fun nativeGetMemoryUsage(): String? |
| 61 | 61 | 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 | |
| 62 | 64 | |
| 63 | 65 | /** |
| 64 | 66 | * `getDeviceInfo`, or null to use the Kotlin implementation. |
| @@ -105,4 +107,31 @@ object CraftNative { | ||
| 105 | 107 | false |
| 106 | 108 | } |
| 107 | 109 | } |
| 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 | } | |
| 108 | 137 | } |