()
| 94 | * Check if clipboard contains an image without retrieving it. |
| 95 | */ |
| 96 | export async function hasImageInClipboard(): Promise<boolean> { |
| 97 | if (process.platform !== 'darwin') { |
| 98 | return false |
| 99 | } |
| 100 | if ( |
| 101 | feature('NATIVE_CLIPBOARD_IMAGE') && |
| 102 | getFeatureValue_CACHED_MAY_BE_STALE('tengu_collage_kaleidoscope', true) |
| 103 | ) { |
| 104 | // Native NSPasteboard check (~0.03ms warm). Fall through to osascript |
| 105 | // when the module/export is missing. Catch a throw too: it would surface |
| 106 | // as an unhandled rejection in useClipboardImageHint's setTimeout. |
| 107 | try { |
| 108 | const { getNativeModule } = await import('image-processor-napi') |
| 109 | const hasImage = getNativeModule()?.hasClipboardImage |
| 110 | if (hasImage) { |
| 111 | return hasImage() |
| 112 | } |
| 113 | } catch (e) { |
| 114 | logError(e as Error) |
| 115 | } |
| 116 | } |
| 117 | const result = await execFileNoThrowWithCwd('osascript', [ |
| 118 | '-e', |
| 119 | 'the clipboard as «class PNGf»', |
| 120 | ]) |
| 121 | return result.code === 0 |
| 122 | } |
| 123 | |
| 124 | export async function getImageFromClipboard(): Promise<ImageWithDimensions | null> { |
| 125 | // Fast path: native NSPasteboard reader (macOS only). Reads PNG bytes |
no test coverage detected