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
+14 -4
View File
@@ -1,10 +1,10 @@
// Package clipboard wraps golang.design/x/clipboard with lazy initialization.
//
// Why a wrapper:
// - The upstream library requires a one-time clipboard.Init() call. Hiding it
// here keeps the application service free of init concerns.
// - Allows future swap to a different backend (e.g. atotto/clipboard) without
// changing callers.
// - The upstream library requires a one-time clipboard.Init() call. Hiding it
// here keeps the application service free of init concerns.
// - Allows future swap to a different backend (e.g. atotto/clipboard) without
// changing callers.
package clipboard
import (
@@ -17,6 +17,7 @@ import (
// Writer abstracts clipboard writes for testability.
type Writer interface {
WriteText(s string) error
WriteImage(pngBytes []byte) error
}
type clipWriter struct {
@@ -44,3 +45,12 @@ func (w *clipWriter) WriteText(s string) error {
clipboard.Write(clipboard.FmtText, []byte(s))
return nil
}
// WriteImage replaces the clipboard contents with PNG-encoded image data.
func (w *clipWriter) WriteImage(pngBytes []byte) error {
if err := w.ensureInit(); err != nil {
return fmt.Errorf("clipboard init: %w", err)
}
clipboard.Write(clipboard.FmtImage, pngBytes)
return nil
}