feat(app): support local screenshot actions

This commit is contained in:
2026-06-04 01:05:28 +08:00
parent c45864e44c
commit 1d52d154fd
11 changed files with 662 additions and 108 deletions
+48 -16
View File
@@ -4,35 +4,67 @@ package main
import "C"
//export nativeOverlayConfirm
func nativeOverlayConfirm(x, y, w, h C.int, annotationsJSON *C.char) {
func nativeCaptureResult(x, y, w, h C.int, annotationsJSON *C.char) CaptureResult {
rawAnnotations := C.GoString(annotationsJSON)
return CaptureResult{
Rect: RegionRect{
X: int(x),
Y: int(y),
W: int(w),
H: int(h),
},
Annotations: parseNativeAnnotations(rawAnnotations),
}
}
func consumeNativeOverlayApp() *App {
nativeOverlayState.Lock()
app := nativeOverlayState.app
nativeOverlayState.app = nil
nativeOverlayState.Unlock()
return app
}
//export nativeOverlayConfirm
func nativeOverlayConfirm(x, y, w, h C.int, annotationsJSON *C.char) {
app := consumeNativeOverlayApp()
if app == nil {
return
}
rawAnnotations := C.GoString(annotationsJSON)
result := nativeCaptureResult(x, y, w, h, annotationsJSON)
go func() {
_ = app.ConfirmNativeRegion(CaptureResult{
Rect: RegionRect{
X: int(x),
Y: int(y),
W: int(w),
H: int(h),
},
Annotations: parseNativeAnnotations(rawAnnotations),
})
_ = app.ConfirmNativeRegion(result)
}()
}
//export nativeOverlayCopy
func nativeOverlayCopy(x, y, w, h C.int, annotationsJSON *C.char) {
app := consumeNativeOverlayApp()
if app == nil {
return
}
result := nativeCaptureResult(x, y, w, h, annotationsJSON)
go func() {
_ = app.CopyNativeRegionImage(result)
}()
}
//export nativeOverlaySave
func nativeOverlaySave(x, y, w, h C.int, annotationsJSON *C.char, dir *C.char) {
app := consumeNativeOverlayApp()
if app == nil {
return
}
result := nativeCaptureResult(x, y, w, h, annotationsJSON)
saveDir := C.GoString(dir)
go func() {
_, _ = app.SaveNativeRegionImageToDir(result, saveDir)
}()
}
//export nativeOverlayCancel
func nativeOverlayCancel() {
nativeOverlayState.Lock()
app := nativeOverlayState.app
nativeOverlayState.app = nil
nativeOverlayState.Unlock()
app := consumeNativeOverlayApp()
if app == nil {
return
}