mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2024-12-23 08:54: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
|
all: open
|
||||||
|
|
||||||
build: clean
|
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
|
mkdir -p -v ./bin/amm.app/Contents/MacOS
|
||||||
cp ./appInfo/*.plist ./bin/amm.app/Contents/Info.plist
|
cp ./appInfo/*.plist ./bin/amm.app/Contents/Info.plist
|
||||||
cp ./appInfo/*.icns ./bin/amm.app/Contents/Resources/icon.icns
|
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
|
go build -o ./bin/amm.app/Contents/MacOS/amm cmd/main.go
|
||||||
|
|
||||||
open: build
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/png"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/getlantern/systray"
|
"github.com/getlantern/systray"
|
||||||
"github.com/go-vgo/robotgo"
|
"github.com/go-vgo/robotgo"
|
||||||
"github.com/kirsle/configdir"
|
"github.com/kirsle/configdir"
|
||||||
"github.com/prashantgupta24/automatic-mouse-mover/assets/icon"
|
|
||||||
"github.com/prashantgupta24/automatic-mouse-mover/pkg/mousemover"
|
"github.com/prashantgupta24/automatic-mouse-mover/pkg/mousemover"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -24,22 +27,52 @@ func main() {
|
|||||||
systray.Run(onReady, onExit)
|
systray.Run(onReady, onExit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setIcon(iconName string, configFile string) {
|
func getIcon(iconName string, active bool) []byte {
|
||||||
switch {
|
if iconName != "mouse" && iconName != "cloud" && iconName != "geometric" && iconName != "man" {
|
||||||
case iconName == "mouse":
|
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)
|
|
||||||
}
|
}
|
||||||
|
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 != "" {
|
if configFile != "" {
|
||||||
var settings AppSettings
|
|
||||||
settings = AppSettings{iconName}
|
*settings = AppSettings{iconName}
|
||||||
fh, _ := os.Create(configFile)
|
fh, _ := os.Create(configFile)
|
||||||
defer fh.Close()
|
defer fh.Close()
|
||||||
|
|
||||||
@ -76,7 +109,6 @@ func onReady() {
|
|||||||
decoder := json.NewDecoder(fh)
|
decoder := json.NewDecoder(fh)
|
||||||
decoder.Decode(&settings)
|
decoder.Decode(&settings)
|
||||||
}
|
}
|
||||||
setIcon(settings.Icon, "")
|
|
||||||
|
|
||||||
about := systray.AddMenuItem("About AMM", "Information about the app")
|
about := systray.AddMenuItem("About AMM", "Information about the app")
|
||||||
systray.AddSeparator()
|
systray.AddSeparator()
|
||||||
@ -85,15 +117,17 @@ func onReady() {
|
|||||||
|
|
||||||
icons := systray.AddMenuItem("Icons", "icon of the app")
|
icons := systray.AddMenuItem("Icons", "icon of the app")
|
||||||
mouse := icons.AddSubMenuItem("Mouse", "Mouse icon")
|
mouse := icons.AddSubMenuItem("Mouse", "Mouse icon")
|
||||||
mouse.SetIcon(icon.Data)
|
|
||||||
|
mouse.SetIcon(getIcon("mouse", false))
|
||||||
cloud := icons.AddSubMenuItem("Cloud", "Cloud icon")
|
cloud := icons.AddSubMenuItem("Cloud", "Cloud icon")
|
||||||
cloud.SetIcon(icon.CloudIcon)
|
cloud.SetIcon(getIcon("cloud", false))
|
||||||
man := icons.AddSubMenuItem("Man", "Man icon")
|
man := icons.AddSubMenuItem("Man", "Man icon")
|
||||||
man.SetIcon(icon.ManIcon)
|
man.SetIcon(getIcon("man", false))
|
||||||
geometric := icons.AddSubMenuItem("Geometric", "Geometric")
|
geometric := icons.AddSubMenuItem("Geometric", "Geometric")
|
||||||
geometric.SetIcon(icon.GeometricIcon)
|
geometric.SetIcon(getIcon("geometric", false))
|
||||||
|
|
||||||
ammStop.Disable()
|
ammStop.Disable()
|
||||||
|
setIcon(settings.Icon, "", &settings, true)
|
||||||
systray.AddSeparator()
|
systray.AddSeparator()
|
||||||
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
||||||
// Sets the icon of a menu item. Only available on Mac.
|
// Sets the icon of a menu item. Only available on Mac.
|
||||||
@ -102,6 +136,7 @@ func onReady() {
|
|||||||
mouseMover.Start()
|
mouseMover.Start()
|
||||||
ammStart.Disable()
|
ammStart.Disable()
|
||||||
ammStop.Enable()
|
ammStop.Enable()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ammStart.ClickedCh:
|
case <-ammStart.ClickedCh:
|
||||||
@ -110,12 +145,14 @@ func onReady() {
|
|||||||
ammStart.Disable()
|
ammStart.Disable()
|
||||||
ammStop.Enable()
|
ammStop.Enable()
|
||||||
//notify.SendMessage("starting the app")
|
//notify.SendMessage("starting the app")
|
||||||
|
setIcon(settings.Icon, configFile, &settings, true)
|
||||||
|
|
||||||
case <-ammStop.ClickedCh:
|
case <-ammStop.ClickedCh:
|
||||||
log.Infof("stopping the app")
|
log.Infof("stopping the app")
|
||||||
ammStart.Enable()
|
ammStart.Enable()
|
||||||
ammStop.Disable()
|
ammStop.Disable()
|
||||||
mouseMover.Quit()
|
mouseMover.Quit()
|
||||||
|
setIcon(settings.Icon, configFile, &settings, false)
|
||||||
|
|
||||||
case <-mQuit.ClickedCh:
|
case <-mQuit.ClickedCh:
|
||||||
log.Infof("Requesting quit")
|
log.Infof("Requesting quit")
|
||||||
@ -123,16 +160,16 @@ func onReady() {
|
|||||||
systray.Quit()
|
systray.Quit()
|
||||||
return
|
return
|
||||||
case <-mouse.ClickedCh:
|
case <-mouse.ClickedCh:
|
||||||
setIcon("mouse", configFile)
|
setIcon("mouse", configFile, &settings, ammStart.Disabled())
|
||||||
case <-cloud.ClickedCh:
|
case <-cloud.ClickedCh:
|
||||||
setIcon("cloud", configFile)
|
setIcon("cloud", configFile, &settings, ammStart.Disabled())
|
||||||
case <-man.ClickedCh:
|
case <-man.ClickedCh:
|
||||||
setIcon("man", configFile)
|
setIcon("man", configFile, &settings, ammStart.Disabled())
|
||||||
case <-geometric.ClickedCh:
|
case <-geometric.ClickedCh:
|
||||||
setIcon("geometric", configFile)
|
setIcon("geometric", configFile, &settings, ammStart.Disabled())
|
||||||
case <-about.ClickedCh:
|
case <-about.ClickedCh:
|
||||||
log.Infof("Requesting about")
|
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