mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2024-12-22 16:34:11 +00:00
added system sleep check
This commit is contained in:
parent
708f4623e5
commit
f212967d71
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
vendor/
|
vendor/
|
||||||
bin/
|
bin/
|
||||||
|
log/
|
@ -10,6 +10,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/go-vgo/robotgo"
|
"github.com/go-vgo/robotgo"
|
||||||
|
"github.com/prashantgupta24/activity-tracker/pkg/activity"
|
||||||
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
|
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ type MouseMover struct {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
timeout = 100 //ms
|
timeout = 100 //ms
|
||||||
logFileName = "logFile"
|
logFileName = "log/logFile-amm-1"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Start the main app
|
//Start the main app
|
||||||
@ -51,11 +52,16 @@ func (m *MouseMover) Start() {
|
|||||||
m.updateRunningStatus(true)
|
m.updateRunningStatus(true)
|
||||||
movePixel := 10
|
movePixel := 10
|
||||||
var lastMoved time.Time
|
var lastMoved time.Time
|
||||||
|
isSystemSleeping := false
|
||||||
didNotMoveTimes := 0
|
didNotMoveTimes := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case heartbeat := <-heartbeatCh:
|
case heartbeat := <-heartbeatCh:
|
||||||
if !heartbeat.WasAnyActivity {
|
if !heartbeat.WasAnyActivity {
|
||||||
|
if isSystemSleeping {
|
||||||
|
logger.Infof("system sleeping")
|
||||||
|
continue
|
||||||
|
}
|
||||||
mouseMoveSuccessCh := make(chan bool)
|
mouseMoveSuccessCh := make(chan bool)
|
||||||
go moveAndCheck(movePixel, mouseMoveSuccessCh)
|
go moveAndCheck(movePixel, mouseMoveSuccessCh)
|
||||||
select {
|
select {
|
||||||
@ -80,14 +86,18 @@ func (m *MouseMover) Start() {
|
|||||||
//timeout, do nothing
|
//timeout, do nothing
|
||||||
logger.Errorf("timeout happened after %vms while trying to move mouse", timeout)
|
logger.Errorf("timeout happened after %vms while trying to move mouse", timeout)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
} else { //uncomment to see all activities received
|
logger.Infof("activity detected in the last %v seconds.", int(heartbeatInterval))
|
||||||
// logger.Printf("activity detected in the last %v seconds.", int(heartbeatInterval))
|
logger.Infof("Activity type:\n")
|
||||||
// logger.Printf("Activity type:\n")
|
for activityType, times := range heartbeat.ActivityMap {
|
||||||
// for activityType, times := range heartbeat.ActivityMap {
|
logger.Infof("activityType : %v times: %v\n", activityType, len(times))
|
||||||
// logger.Printf("activityType : %v times: %v\n", activityType, len(times))
|
if activityType == activity.MachineSleep {
|
||||||
// }
|
isSystemSleeping = true
|
||||||
// logger.Printf("\n\n\n")
|
} else if activityType == activity.MachineWake {
|
||||||
|
isSystemSleeping = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.Infof("\n\n\n")
|
||||||
}
|
}
|
||||||
case <-m.quit:
|
case <-m.quit:
|
||||||
logger.Infof("stopping mouse mover")
|
logger.Infof("stopping mouse mover")
|
||||||
@ -132,8 +142,10 @@ func (m *MouseMover) Quit() {
|
|||||||
if m != nil && m.isRunning() {
|
if m != nil && m.isRunning() {
|
||||||
m.quit <- struct{}{}
|
m.quit <- struct{}{}
|
||||||
}
|
}
|
||||||
|
if m.logFile != nil {
|
||||||
m.logFile.Close()
|
m.logFile.Close()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//GetInstance gets the singleton instance for mouse mover app
|
//GetInstance gets the singleton instance for mouse mover app
|
||||||
func GetInstance() *MouseMover {
|
func GetInstance() *MouseMover {
|
||||||
|
Loading…
Reference in New Issue
Block a user