MCPcopy Index your code
hub / github.com/codeaashu/claude-code / hasImageInClipboard

Function hasImageInClipboard

src/utils/imagePaste.ts:96–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94 * Check if clipboard contains an image without retrieving it.
95 */
96export 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
124export async function getImageFromClipboard(): Promise<ImageWithDimensions | null> {
125 // Fast path: native NSPasteboard reader (macOS only). Reads PNG bytes

Callers 1

useClipboardImageHintFunction · 0.85

Calls 5

featureFunction · 0.85
getNativeModuleFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected