feat: 实现 4 个 NAPI 包 — modifiers/image-processor/audio-capture/url-handler

- modifiers-napi: 使用 Bun FFI 调用 macOS CGEventSourceFlagsState 检测修饰键
- image-processor-napi: 集成 sharp 库,macOS 剪贴板图像读取 (osascript)
- audio-capture-napi: 基于 SoX/arecord 的跨平台音频录制
- url-handler-napi: 完善函数签名(保持 null fallback)
- 修复 image-processor 类型兼容性问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-01 01:07:42 +08:00
parent fac9341e73
commit 7e15974be9
8 changed files with 398 additions and 23 deletions

View File

@@ -44,9 +44,9 @@ export async function getImageProcessor(): Promise<SharpFunction> {
try {
// Use the native image processor module
const imageProcessor = await import('image-processor-napi')
const sharp = (imageProcessor as Record<string, SharpFunction>).sharp || imageProcessor.default
imageProcessorModule = { default: sharp }
return sharp
const sharpFn = (imageProcessor.sharp ?? imageProcessor.default) as SharpFunction
imageProcessorModule = { default: sharpFn }
return sharpFn
} catch {
// Fall back to sharp if native module is not available
// biome-ignore lint/suspicious/noConsole: intentional warning

View File

@@ -106,10 +106,10 @@ export async function hasImageInClipboard(): Promise<boolean> {
// as an unhandled rejection in useClipboardImageHint's setTimeout.
try {
const { getNativeModule } = await import('image-processor-napi')
const nativeModule = getNativeModule() as Record<string, Function> | null
const hasImage = nativeModule?.hasClipboardImage
if (hasImage) {
return hasImage()
const nativeModule = getNativeModule()
if (nativeModule && 'hasClipboardImage' in nativeModule) {
const hasImage = (nativeModule as unknown as Record<string, Function>).hasClipboardImage
if (hasImage) return hasImage()
}
} catch (e) {
logError(e as Error)
@@ -136,8 +136,10 @@ export async function getImageFromClipboard(): Promise<ImageWithDimensions | nul
) {
try {
const { getNativeModule } = await import('image-processor-napi')
const nativeModule = getNativeModule() as Record<string, Function> | null
const readClipboard = nativeModule?.readClipboardImage
const nativeModule = getNativeModule()
const readClipboard = nativeModule && 'readClipboardImage' in nativeModule
? (nativeModule as unknown as Record<string, Function>).readClipboardImage
: undefined
if (!readClipboard) {
throw new Error('native clipboard reader unavailable')
}