mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2025-01-21 20:25:53 +00:00
adding notification for permission issue
This commit is contained in:
parent
5cc0c44151
commit
1677d20fd6
@ -7,4 +7,10 @@ Ever felt the need to keep your machine awake without having to resort to the ag
|
||||
> Introducing the simplest app on the market that has the sole purpose of moving your mouse pointer at regular intervals so that your machine never sleeps! And best of all, it works **ONLY** when you are not working, so be rest assured that the mouse won't start moving on its own without the machine actually being idle.
|
||||
|
||||
|
||||
## Error while moving the app
|
||||
|
||||
In case you get an error from the app saying `mouse pointer cannot be moved.`, you need to give the app permission to control your mouse. Don't worry, it's nothing sinister, but Mac doesn't allow outside apps to gain accessibility to the mouse by default (which include Firefox, Discord etc.)
|
||||
|
||||
In order to resolve this error you need to:
|
||||
|
||||
Go to Security & Privacy -> Privacy -> Accessibility and allow the `amm` app to gain access.
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
|
||||
"github.com/prashantgupta24/automatic-mouse-mover/pkg/notify"
|
||||
)
|
||||
|
||||
var instance *MouseMover
|
||||
@ -45,13 +46,17 @@ func (m *MouseMover) Start() {
|
||||
select {
|
||||
case heartbeat := <-heartbeatCh:
|
||||
if !heartbeat.WasAnyActivity {
|
||||
commCh := make(chan bool)
|
||||
go moveMouse(movePixel, commCh)
|
||||
mouseMoveSuccessCh := make(chan bool)
|
||||
go moveAndCheck(movePixel, mouseMoveSuccessCh)
|
||||
select {
|
||||
case wasMouseMoveSuccess := <-commCh:
|
||||
case wasMouseMoveSuccess := <-mouseMoveSuccessCh:
|
||||
if wasMouseMoveSuccess {
|
||||
log.Infof("moving mouse at : %v\n\n", time.Now())
|
||||
log.Infof("moved mouse at : %v\n\n", time.Now())
|
||||
movePixel *= -1
|
||||
} else {
|
||||
msg := "Mouse pointer cannot be moved. See README for details."
|
||||
log.Errorf(msg)
|
||||
notify.SendMessage(msg)
|
||||
}
|
||||
case <-time.After(timeout * time.Millisecond):
|
||||
//timeout, do nothing
|
||||
@ -80,12 +85,20 @@ func (m *MouseMover) updateRunningStatus(isRunning bool) {
|
||||
m.runningStatus = isRunning
|
||||
}
|
||||
|
||||
func moveMouse(movePixel int, commCh chan bool) {
|
||||
func moveAndCheck(movePixel int, mouseMoveSuccessCh chan bool) {
|
||||
currentX, currentY := robotgo.GetMousePos()
|
||||
moveToX := currentX + movePixel
|
||||
moveToY := currentY + movePixel
|
||||
robotgo.MoveMouse(moveToX, moveToY)
|
||||
commCh <- true
|
||||
|
||||
//check if mouse moved. Sometimes mac users need to give
|
||||
//extra permission for controlling the mouse
|
||||
movedX, movedY := robotgo.GetMousePos()
|
||||
if movedX == currentX && movedY == currentY {
|
||||
mouseMoveSuccessCh <- false
|
||||
} else {
|
||||
mouseMoveSuccessCh <- true
|
||||
}
|
||||
}
|
||||
|
||||
//Quit the app
|
||||
|
@ -1,11 +1,9 @@
|
||||
package mousemover
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
@ -44,12 +42,3 @@ func (suite *TestMover) TestAppStartAndStop() {
|
||||
time.Sleep(time.Millisecond * 500) //wait for app to stop
|
||||
assert.False(t, mouseMover.isRunning(), "app should have stopped")
|
||||
}
|
||||
func (suite *TestMover) TestMouseMove() {
|
||||
t := suite.T()
|
||||
movePixel := 10
|
||||
currentX, _ := robotgo.GetMousePos()
|
||||
commCh := make(chan bool, 1)
|
||||
moveMouse(movePixel, commCh)
|
||||
movedX, _ := robotgo.GetMousePos()
|
||||
assert.Equal(t, float64(movePixel), math.Abs(float64(movedX-currentX)))
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
gosxnotifier "github.com/deckarep/gosx-notifier"
|
||||
)
|
||||
@ -11,6 +11,6 @@ func SendMessage(msg string) {
|
||||
note := gosxnotifier.NewNotification(msg)
|
||||
err := note.Push()
|
||||
if err != nil {
|
||||
fmt.Println("could not send notification")
|
||||
log.Error("could not send")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user