Skip to content

Commit

Permalink
feat: Change default wait time from static 10 sec to dynamic 10-60 sec (
Browse files Browse the repository at this point in the history
  • Loading branch information
sonjek authored Apr 1, 2024
1 parent 2b02971 commit bbf6273
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 15 additions & 1 deletion internal/mouse/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (c *Controller) MoveMouse() {
// Update last known mouse position
c.LastX, c.LastY = robotgo.Location()

time.Sleep(c.SleepInterval)
// Sleep before the next iteration
c.sleep()
}
}

Expand All @@ -51,3 +52,16 @@ func (c *Controller) SetSleepInterval(interval time.Duration) {
func (c *Controller) SetSleepIntervalSec(sec int) {
c.SetSleepInterval(time.Duration(sec) * time.Second)
}

func (c *Controller) sleep() {
var duration time.Duration

if c.SleepInterval > 0 {
duration = c.SleepInterval
} else {
// Get random duration between 10-60 sec
duration = time.Duration(rand.N(51)+10) * time.Second
}

time.Sleep(duration)
}
9 changes: 5 additions & 4 deletions internal/tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@ func (t *Tray) onReady() {
mDisable.Hide()
}

// Default sleep interval
t.mouseController.SetSleepIntervalSec(10)

// Add interval selection submenu items
t.addIntervalItem(mInterval, "10-60 sec", -1)
t.addIntervalItem(mInterval, "10 sec", 10)
t.addIntervalItem(mInterval, "20 sec", 20)
t.addIntervalItem(mInterval, "30 sec", 30)
t.addIntervalItem(mInterval, "60 sec", 60)

// Set the default sleep interval
t.mouseController.SetSleepIntervalSec(-1)

// Mark the default interval
t.intervalItems[10].Check()
t.intervalItems[-1].Check()

// Create a channel to listen for interval item clicks
intervalClicks := t.createIntervalClicksChannel()
Expand Down

0 comments on commit bbf6273

Please sign in to comment.