43 lines
962 B
Go
43 lines
962 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
func (a *App) ReadClipboardText() (string, error) {
|
|
text, err := wailsruntime.ClipboardGetText(a.ctx)
|
|
if err != nil {
|
|
return "", fmt.Errorf("clipboard text is unavailable")
|
|
}
|
|
return text, nil
|
|
}
|
|
|
|
func (a *App) CaptureClipboardTextWithContext(contextJSON string) (*InboxNodeDTO, error) {
|
|
text, err := a.ReadClipboardText()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
kind, value := classifyClipboardText(text)
|
|
if value == "" {
|
|
return nil, fmt.Errorf("clipboard is empty")
|
|
}
|
|
if kind == "url" {
|
|
return a.CaptureURLWithContext(value, "", "clipboard_button", contextJSON)
|
|
}
|
|
return a.CaptureTextWithContext(value, "clipboard_button", contextJSON)
|
|
}
|
|
|
|
func classifyClipboardText(text string) (string, string) {
|
|
value := strings.TrimSpace(text)
|
|
if value == "" {
|
|
return "text", ""
|
|
}
|
|
if isURLLike(value) {
|
|
return "url", value
|
|
}
|
|
return "text", value
|
|
}
|