-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaf.go
68 lines (58 loc) · 1.64 KB
/
af.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
package main
import (
"embed"
"fmt"
"net/http"
"time"
"github.com/gen2brain/beeep"
"github.com/getlantern/systray"
"github.com/skratchdot/open-golang/open"
)
//go:embed asciiflow2/*
var asciiflow2 embed.FS
func main() {
onExit := func() {
fmt.Println(time.Now().String(), "AF退出")
}
systray.Run(onReady, onExit)
}
const (
Title = "ASCIIFlow"
ToolTip = "ASCIIFlow:纯文本流程图绘制工具"
Port = ":3000"
AF2Path = "/asciiflow2/"
AF3Path = "/asciiflow3/"
)
func onReady() {
systray.SetTemplateIcon(Data, Data)
systray.SetTitle(Title)
systray.SetTooltip(ToolTip)
go func() {
http.Handle(AF2Path, http.FileServer(http.FS(asciiflow2)))
http.Handle(AF3Path, http.FileServer(http.FS(asciiflow2)))
fmt.Println(http.ListenAndServe(Port, nil))
}()
// We can manipulate the systray in other goroutines
go func() {
mOpen2 := systray.AddMenuItem("👀打开ASCIIFlow2", "ASCIIFlow2操作界面")
mOpen3 := systray.AddMenuItem("👀打开ASCIIFlow2", "ASCIIFlow2操作界面")
mOpen3.Disable()
systray.AddMenuItem(fmt.Sprintf("Server:http://127.0.0.1%s", Port), "点击拷贝").Disable()
systray.AddSeparator()
mQuit := systray.AddMenuItem("退出", "退出整个应用")
beeep.Notify(Title, "请点击"+Title+"图标打开相应的版本", "")
for {
select {
case <-mOpen2.ClickedCh:
open.Run("http://127.0.0.1" + Port + AF2Path)
beeep.Notify(Title, "请在浏览器中操作"+Title+"2", "")
case <-mOpen3.ClickedCh:
open.Run("http://127.0.0.1" + Port + AF3Path)
beeep.Notify(Title, "请在浏览器中操作"+Title+"3", "")
case <-mQuit.ClickedCh:
systray.Quit()
return
}
}
}()
}