From 1677d20fd69222de68b1ad3f9550659aa726f132 Mon Sep 17 00:00:00 2001 From: Prashant Gupta Date: Thu, 28 Mar 2019 15:02:36 -0700 Subject: [PATCH 1/2] adding notification for permission issue --- README.md | 6 ++++++ pkg/mousemover/mouseMover.go | 25 +++++++++++++++++++------ pkg/mousemover/mouseMover_test.go | 11 ----------- pkg/notify/notify.go | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b861cdc..3dd1074 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pkg/mousemover/mouseMover.go b/pkg/mousemover/mouseMover.go index a8ab5df..7071a7d 100644 --- a/pkg/mousemover/mouseMover.go +++ b/pkg/mousemover/mouseMover.go @@ -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 diff --git a/pkg/mousemover/mouseMover_test.go b/pkg/mousemover/mouseMover_test.go index c3c7cd2..7b48d2b 100644 --- a/pkg/mousemover/mouseMover_test.go +++ b/pkg/mousemover/mouseMover_test.go @@ -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))) -} diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index ebe1b28..ce422c3 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -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") } } From 47583a943d9893fa266e9b8f76581e5d015c4862 Mon Sep 17 00:00:00 2001 From: Prashant Gupta Date: Thu, 28 Mar 2019 15:06:15 -0700 Subject: [PATCH 2/2] updated readme with error message --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3dd1074..cf59031 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Ever felt the need to keep your machine awake without having to resort to the ag ## 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 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 apps to gain accessibility to the computer by default (even standard apps like Automator, Firefox etc. who might want to access some features need to go through the same process) In order to resolve this error you need to: -Go to Security & Privacy -> Privacy -> Accessibility and allow the `amm` app to gain access. +> Go to Security & Privacy -> Privacy -> Accessibility and allow the `amm` app to gain access.