-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (89 loc) · 2.04 KB
/
main.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"github.com/getlantern/systray"
"github.com/rs/zerolog/log"
"golang.design/x/clipboard"
)
var ServiceFlag bool = true
func main() {
InitLogger(true)
Gconfig.LoadConfig()
onExit := func() {
// now := time.Now()
log.Info().Msg(`on_exit_.txt`)
}
systray.Run(onReady, onExit)
}
func onReady() {
var tray_name = "iClipboard"
// var clipboard = ClipBoardBase{"linux"}
// var clip_board_type = clipboard.info()
err := clipboard.Init()
if err != nil {
fmt.Println("iClipboard init failid")
panic(err)
}
systray.SetTemplateIcon(IconData, IconData)
systray.SetTitle(tray_name)
systray.SetTooltip("iClipboard")
go func() {
RunHTTPServer()
}()
// We can manipulate the systray in other goroutines
go func() {
systray.SetTemplateIcon(IconData, IconData)
systray.SetTitle(tray_name)
// systray.SetTooltip("Pretty awesome棒棒嗒")
mChecked := systray.AddMenuItemCheckbox("Enabled", "Check Me", true)
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
// Sets the icon of a menu item. Only available on Mac.
mQuit.SetIcon(IconData)
systray.AddSeparator()
for {
select {
case <-mChecked.ClickedCh:
if mChecked.Checked() {
mChecked.Uncheck()
mChecked.SetTitle("Disabled")
ServiceFlag = false
} else {
mChecked.Check()
mChecked.SetTitle("Enabled")
ServiceFlag = true
}
case <-mQuit.ClickedCh:
systray.Quit()
fmt.Println("Quit2 now...")
return
}
}
}()
}
// func write_2_file(file string) error {
// var b []byte
// var err error
// file = "hhh.txt"
// b = clipboard.Read(clipboard.FmtText)
// if b == nil {
// b = clipboard.Read(clipboard.FmtImage)
// file = "hhh.png"
// }
//
// if file != "" && b != nil {
// err = os.WriteFile(file, b, os.ModePerm)
// if err != nil {
// fmt.Fprintf(os.Stderr, "failed to write data to file %s: %v", file, err)
// }
// return err
// }
//
// for len(b) > 0 {
// n, err := os.Stdout.Write(b)
// if err != nil {
// return err
// }
// b = b[n:]
// }
// return nil
// }