feat(app): implement basic function
General - 配置界面支持配置对象存储桶 - 快捷键进入截图 - 一键上传截图 & 复制截图链接 MacOS - 状态栏指示器和应用图标
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// 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.
|
||||
package clipboard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"golang.design/x/clipboard"
|
||||
)
|
||||
|
||||
// Writer abstracts clipboard writes for testability.
|
||||
type Writer interface {
|
||||
WriteText(s string) error
|
||||
}
|
||||
|
||||
type clipWriter struct {
|
||||
once sync.Once
|
||||
initErr error
|
||||
}
|
||||
|
||||
// New returns a process-wide clipboard writer. Initialization is lazy.
|
||||
func New() Writer {
|
||||
return &clipWriter{}
|
||||
}
|
||||
|
||||
func (w *clipWriter) ensureInit() error {
|
||||
w.once.Do(func() {
|
||||
w.initErr = clipboard.Init()
|
||||
})
|
||||
return w.initErr
|
||||
}
|
||||
|
||||
// WriteText replaces the clipboard contents with the supplied UTF-8 string.
|
||||
func (w *clipWriter) WriteText(s string) error {
|
||||
if err := w.ensureInit(); err != nil {
|
||||
return fmt.Errorf("clipboard init: %w", err)
|
||||
}
|
||||
clipboard.Write(clipboard.FmtText, []byte(s))
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user