mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2024-12-23 00:44:10 +00:00
Merge branch 'use-png-activable-icons' into icons-management
This commit is contained in:
commit
e80c4f8a60
3
Makefile
3
Makefile
@ -6,10 +6,11 @@ COVER_HTML=cover.html
|
||||
all: open
|
||||
|
||||
build: clean
|
||||
mkdir -p -v ./bin/amm.app/Contents/Resources
|
||||
mkdir -p -v ./bin/amm.app/Contents/Resources/assets/icon
|
||||
mkdir -p -v ./bin/amm.app/Contents/MacOS
|
||||
cp ./appInfo/*.plist ./bin/amm.app/Contents/Info.plist
|
||||
cp ./appInfo/*.icns ./bin/amm.app/Contents/Resources/icon.icns
|
||||
cp ./assets/icon/* ./bin/amm.app/Contents/Resources/assets/icon
|
||||
go build -o ./bin/amm.app/Contents/MacOS/amm cmd/main.go
|
||||
|
||||
open: build
|
||||
|
BIN
assets/icon/cloud.png
Normal file
BIN
assets/icon/cloud.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/icon/geometric.png
Normal file
BIN
assets/icon/geometric.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/icon/man.png
Normal file
BIN
assets/icon/man.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
assets/icon/mouse.png
Normal file
BIN
assets/icon/mouse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
File diff suppressed because it is too large
Load Diff
87
cmd/main.go
87
cmd/main.go
@ -1,14 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/getlantern/systray"
|
||||
"github.com/go-vgo/robotgo"
|
||||
"github.com/kirsle/configdir"
|
||||
"github.com/prashantgupta24/automatic-mouse-mover/assets/icon"
|
||||
"github.com/prashantgupta24/automatic-mouse-mover/pkg/mousemover"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -24,22 +27,52 @@ func main() {
|
||||
systray.Run(onReady, onExit)
|
||||
}
|
||||
|
||||
func setIcon(iconName string, configFile string) {
|
||||
switch {
|
||||
case iconName == "mouse":
|
||||
systray.SetIcon(icon.Data)
|
||||
case iconName == "cloud":
|
||||
systray.SetIcon(icon.CloudIcon)
|
||||
case iconName == "man":
|
||||
systray.SetIcon(icon.ManIcon)
|
||||
case iconName == "geometric":
|
||||
systray.SetIcon(icon.GeometricIcon)
|
||||
default:
|
||||
systray.SetIcon(icon.Data)
|
||||
func getIcon(iconName string, active bool) []byte {
|
||||
if iconName != "mouse" && iconName != "cloud" && iconName != "geometric" && iconName != "man" {
|
||||
iconName = "mouse"
|
||||
}
|
||||
var b []byte
|
||||
var err error
|
||||
ex, _ := os.Executable()
|
||||
exPath := filepath.Dir(ex)
|
||||
|
||||
if _, err := os.Stat(exPath + "/../Resources/assets/icon"); os.IsNotExist(err) {
|
||||
b, err = os.ReadFile(exPath + "/../assets/icon/" + iconName + ".png")
|
||||
} else {
|
||||
b, err = os.ReadFile(exPath + "/../Resources/assets/icon/" + iconName + ".png")
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if active {
|
||||
img, err := png.Decode(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
var dimg *image.RGBA = image.NewRGBA(img.Bounds())
|
||||
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
|
||||
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
|
||||
r, g, b, a := img.At(x, y).RGBA()
|
||||
if a != 0 {
|
||||
dimg.Set(x, y, color.RGBA{30, 144, 255, 255})
|
||||
} else {
|
||||
dimg.Set(x, y, color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)})
|
||||
}
|
||||
}
|
||||
}
|
||||
var c bytes.Buffer
|
||||
png.Encode(&c, dimg)
|
||||
return c.Bytes()
|
||||
}
|
||||
return b
|
||||
|
||||
}
|
||||
|
||||
func setIcon(iconName string, configFile string, settings *AppSettings, active ...bool) {
|
||||
systray.SetIcon(getIcon(iconName, len(active) != 0 && active[0]))
|
||||
if configFile != "" {
|
||||
var settings AppSettings
|
||||
settings = AppSettings{iconName}
|
||||
|
||||
*settings = AppSettings{iconName}
|
||||
fh, _ := os.Create(configFile)
|
||||
defer fh.Close()
|
||||
|
||||
@ -76,7 +109,6 @@ func onReady() {
|
||||
decoder := json.NewDecoder(fh)
|
||||
decoder.Decode(&settings)
|
||||
}
|
||||
setIcon(settings.Icon, "")
|
||||
|
||||
about := systray.AddMenuItem("About AMM", "Information about the app")
|
||||
systray.AddSeparator()
|
||||
@ -85,15 +117,17 @@ func onReady() {
|
||||
|
||||
icons := systray.AddMenuItem("Icons", "icon of the app")
|
||||
mouse := icons.AddSubMenuItem("Mouse", "Mouse icon")
|
||||
mouse.SetIcon(icon.Data)
|
||||
|
||||
mouse.SetIcon(getIcon("mouse", false))
|
||||
cloud := icons.AddSubMenuItem("Cloud", "Cloud icon")
|
||||
cloud.SetIcon(icon.CloudIcon)
|
||||
cloud.SetIcon(getIcon("cloud", false))
|
||||
man := icons.AddSubMenuItem("Man", "Man icon")
|
||||
man.SetIcon(icon.ManIcon)
|
||||
man.SetIcon(getIcon("man", false))
|
||||
geometric := icons.AddSubMenuItem("Geometric", "Geometric")
|
||||
geometric.SetIcon(icon.GeometricIcon)
|
||||
geometric.SetIcon(getIcon("geometric", false))
|
||||
|
||||
ammStop.Disable()
|
||||
setIcon(settings.Icon, "", &settings, true)
|
||||
systray.AddSeparator()
|
||||
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
||||
// Sets the icon of a menu item. Only available on Mac.
|
||||
@ -102,6 +136,7 @@ func onReady() {
|
||||
mouseMover.Start()
|
||||
ammStart.Disable()
|
||||
ammStop.Enable()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ammStart.ClickedCh:
|
||||
@ -110,12 +145,14 @@ func onReady() {
|
||||
ammStart.Disable()
|
||||
ammStop.Enable()
|
||||
//notify.SendMessage("starting the app")
|
||||
setIcon(settings.Icon, configFile, &settings, true)
|
||||
|
||||
case <-ammStop.ClickedCh:
|
||||
log.Infof("stopping the app")
|
||||
ammStart.Enable()
|
||||
ammStop.Disable()
|
||||
mouseMover.Quit()
|
||||
setIcon(settings.Icon, configFile, &settings, false)
|
||||
|
||||
case <-mQuit.ClickedCh:
|
||||
log.Infof("Requesting quit")
|
||||
@ -123,16 +160,16 @@ func onReady() {
|
||||
systray.Quit()
|
||||
return
|
||||
case <-mouse.ClickedCh:
|
||||
setIcon("mouse", configFile)
|
||||
setIcon("mouse", configFile, &settings, ammStart.Disabled())
|
||||
case <-cloud.ClickedCh:
|
||||
setIcon("cloud", configFile)
|
||||
setIcon("cloud", configFile, &settings, ammStart.Disabled())
|
||||
case <-man.ClickedCh:
|
||||
setIcon("man", configFile)
|
||||
setIcon("man", configFile, &settings, ammStart.Disabled())
|
||||
case <-geometric.ClickedCh:
|
||||
setIcon("geometric", configFile)
|
||||
setIcon("geometric", configFile, &settings, ammStart.Disabled())
|
||||
case <-about.ClickedCh:
|
||||
log.Infof("Requesting about")
|
||||
robotgo.Alert("Automatic-mouse-mover app v1.3.0", "Developed by Prashant Gupta. \n\nMore info at: https://github.com/prashantgupta24/automatic-mouse-mover", "OK", "")
|
||||
robotgo.Alert("Automatic-mouse-mover app v1.3.1", "Developed by Prashant Gupta. \n\nMore info at: https://github.com/prashantgupta24/automatic-mouse-mover", "OK", "")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user