Be dynamic
This commit is contained in:
parent
bb7f987d68
commit
b70269a1ac
3 changed files with 52 additions and 32 deletions
BIN
default.png
Normal file
BIN
default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
BIN
layer_1.png
BIN
layer_1.png
Binary file not shown.
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 119 KiB |
84
main.go
84
main.go
|
@ -1,7 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
@ -12,6 +15,19 @@ import (
|
||||||
"golang.design/x/hotkey"
|
"golang.design/x/hotkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Layer struct {
|
||||||
|
Hotkey hotkey.Key
|
||||||
|
Image *canvas.Image
|
||||||
|
}
|
||||||
|
|
||||||
|
var keymap = map[string]hotkey.Key{
|
||||||
|
"KeyF13": hotkey.KeyF13,
|
||||||
|
"KeyF14": hotkey.KeyF14,
|
||||||
|
"KeyF15": hotkey.KeyF15,
|
||||||
|
"KeyF16": hotkey.KeyF16,
|
||||||
|
"KeyF17": hotkey.KeyF17,
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := app.New()
|
a := app.New()
|
||||||
w := a.NewWindow("SysTray")
|
w := a.NewWindow("SysTray")
|
||||||
|
@ -26,57 +42,61 @@ func main() {
|
||||||
desk.SetSystemTrayMenu(m)
|
desk.SetSystemTrayMenu(m)
|
||||||
desk.SetSystemTrayIcon(icon)
|
desk.SetSystemTrayIcon(icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
// image := canvas.NewImageFromResource(theme.ConfirmIcon())
|
|
||||||
layer_1 := canvas.NewImageFromFile("./layer_1.png")
|
|
||||||
layer_1.Translucency = 0.5
|
|
||||||
layer_2 := canvas.NewImageFromFile("./layer_2.png")
|
|
||||||
layer_2.Translucency = 0.5
|
|
||||||
w.SetContent(container.NewPadded(layer_1))
|
|
||||||
w.Resize(fyne.Size{
|
w.Resize(fyne.Size{
|
||||||
Width: 1656 / 2,
|
Width: 1656 / 2,
|
||||||
Height: 546 / 2,
|
Height: 546 / 2,
|
||||||
})
|
})
|
||||||
|
defaultImage := canvas.NewImageFromFile("./default.png")
|
||||||
|
|
||||||
|
layers := []Layer{}
|
||||||
|
for i := range 5 {
|
||||||
|
imagePath := "./layer_" + strconv.Itoa(i+1) + ".png"
|
||||||
|
if _, err := os.Stat(imagePath); errors.Is(err, os.ErrNotExist) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newLayer := Layer{
|
||||||
|
Image: canvas.NewImageFromFile(imagePath),
|
||||||
|
Hotkey: keymap["KeyF"+strconv.Itoa(12+i)],
|
||||||
|
}
|
||||||
|
|
||||||
|
layers = append(layers, newLayer)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.SetContent(container.NewPadded(defaultImage))
|
||||||
|
|
||||||
// w.SetContent(widget.NewLabel("Fyne System Tray"))
|
|
||||||
w.SetCloseIntercept(func() {
|
w.SetCloseIntercept(func() {
|
||||||
w.Hide()
|
w.Hide()
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(2)
|
wg.Add(len(layers))
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
err := listenHotkey(
|
for _, v := range layers {
|
||||||
func() { w.SetContent(container.NewPadded(layer_1)) },
|
go func() {
|
||||||
func() { w.SetContent(container.NewPadded(layer_2)) },
|
defer wg.Done()
|
||||||
hotkey.Key1,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
err := listenHotkey(
|
log.Printf("Registering %+v", v)
|
||||||
func() { w.SetContent(container.NewPadded(layer_1)) },
|
|
||||||
func() { log.Println("up") },
|
err := listenHotkey(
|
||||||
hotkey.Key2,
|
func() { w.SetContent(container.NewPadded(v.Image)) },
|
||||||
)
|
func() { w.SetContent(container.NewPadded(defaultImage)) },
|
||||||
if err != nil {
|
v.Hotkey,
|
||||||
log.Println(err)
|
)
|
||||||
}
|
if err != nil {
|
||||||
}()
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenHotkey(upfn func(), downfn func(), key hotkey.Key, mods ...hotkey.Modifier) (err error) {
|
func listenHotkey(downfn func(), upfn func(), key hotkey.Key, mods ...hotkey.Modifier) (err error) {
|
||||||
ms := []hotkey.Modifier{}
|
ms := []hotkey.Modifier{}
|
||||||
ms = append(ms, mods...)
|
ms = append(ms, mods...)
|
||||||
hk := hotkey.New(ms, key)
|
hk := hotkey.New(ms, key)
|
||||||
|
|
Loading…
Reference in a new issue