feat(app): support local screenshot actions
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user