Ariver
2026-07-12 33f00a1136c9f7e501b989d432b709d632905304
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package axinput
 
import (
    "fmt"
    "sync"
)
 
type clipboardSnapshot struct {
    text    string
    hasText bool
}
 
type clipboardState struct {
    mu      sync.Mutex
    nextID  uint64
    entries map[string]clipboardEntry
}
 
type clipboardEntry struct {
    fallbackText string
    restore      clipboardSnapshot
}
 
func (s *clipboardState) remember(fallbackText string, restore clipboardSnapshot) string {
    s.mu.Lock()
    defer s.mu.Unlock()
    if s.entries == nil {
        s.entries = make(map[string]clipboardEntry)
    }
    s.nextID++
    token := fmt.Sprintf("ax-output-%d", s.nextID)
    s.entries[token] = clipboardEntry{fallbackText: fallbackText, restore: restore}
    return token
}
 
func (s *clipboardState) take(token string) (clipboardEntry, bool) {
    s.mu.Lock()
    defer s.mu.Unlock()
    if s.entries == nil {
        return clipboardEntry{}, false
    }
    entry, ok := s.entries[token]
    if ok {
        delete(s.entries, token)
    }
    return entry, ok
}
 
func shouldRestoreClipboard(current clipboardSnapshot, expectedText string) bool {
    return current.hasText && current.text == expectedText
}