Browse Source

添加图标应用使用

master
viviman 3 years ago
parent
commit
c5cf4355ce
  1. BIN
      golang_learn/data_func/go_to_tray/icon.ico
  2. 79
      golang_learn/data_func/go_to_tray/main.go
  3. 2
      golang_learn/go.mod
  4. 3
      golang_learn/go.sum

BIN
golang_learn/data_func/go_to_tray/icon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

79
golang_learn/data_func/go_to_tray/main.go

@ -0,0 +1,79 @@
package main
import (
"fmt"
"io/ioutil"
"time"
"github.com/riftbit/go-systray"
)
var (
timezone string
)
func main() {
//systray.SetCustomLeftClickAction()
//systray.SetCustomRightClickAction()
systray.Run(onReady, onExit)
}
func onReady() {
timezone = "默认文字"
systray.SetIcon(getIcon("./icon.ico"))
submenu := systray.AddSubMenu("子菜单")
_ = submenu.AddSubMenuItem("开始", "", 0)
_ = submenu.AddSubMenuItem("结束", "", 0)
localTime := systray.AddMenuItem("炎龙", "炎龙", 0)
hcmcTime := systray.AddMenuItem("风鹰", "风鹰", 0)
sydTime := systray.AddMenuItem("黑犀", "黑犀", 0)
gdlTime := systray.AddMenuItem("地虎", "地虎", 0)
sfTime := systray.AddMenuItem("雪獒", "雪獒", 0)
fmt.Printf("%#v", localTime)
systray.AddSeparator()
mQuit := systray.AddMenuItem("退出", "退出", 0)
go func() {
for {
systray.SetTitle(timezone)
systray.SetTooltip(timezone)
time.Sleep(1 * time.Second)
}
}()
go func() {
for {
select {
case <-localTime.OnClickCh():
timezone = "炎龙"
case <-hcmcTime.OnClickCh():
timezone = "风鹰"
case <-sydTime.OnClickCh():
timezone = "黑犀"
case <-gdlTime.OnClickCh():
timezone = "地虎"
case <-sfTime.OnClickCh():
timezone = "雪獒"
case <-mQuit.OnClickCh():
systray.Quit()
return
}
}
}()
}
func onExit() {
// 清除销毁
}
func getIcon(s string) []byte {
b, err := ioutil.ReadFile(s)
if err != nil {
fmt.Print(err)
}
return b
}

2
golang_learn/go.mod

@ -3,6 +3,7 @@ module golang_learn
go 1.16
require (
fyne.io/fyne v1.4.3
fyne.io/fyne/v2 v2.1.4
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/PuerkitoBio/goquery v1.7.1
@ -26,6 +27,7 @@ require (
github.com/mitchellh/go-homedir v1.0.0
github.com/mzky/zip v0.0.0-20210817031838-1b692015aed2
github.com/pingcap/log v0.0.0-20211215031037-e024ba4eb0ee
github.com/riftbit/go-systray v1.0.2
github.com/russross/blackfriday v1.6.0
github.com/shirou/gopsutil v2.20.4+incompatible
github.com/spf13/viper v1.8.1

3
golang_learn/go.sum

@ -289,6 +289,8 @@ github.com/richardlehane/mscfb v1.0.3 h1:rD8TBkYWkObWO0oLDFCbwMeZ4KoalxQy+QgniCj
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/riftbit/go-systray v1.0.2 h1:8cT4UEREfN3NxpErxHC/7G8cR/t/hAiO/nZng5pmSAQ=
github.com/riftbit/go-systray v1.0.2/go.mod h1:4Gw5HqutBhqXW3sRq41ggHZZqC1k/KOU4dix6G6frj0=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
@ -501,6 +503,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

Loading…
Cancel
Save