diff --git a/internal/mouse/mouse.go b/internal/mouse/mouse.go index c3da803..1b2fef5 100644 --- a/internal/mouse/mouse.go +++ b/internal/mouse/mouse.go @@ -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() } } @@ -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) +} diff --git a/internal/tray/tray.go b/internal/tray/tray.go index 9bd0cca..fe70062 100644 --- a/internal/tray/tray.go +++ b/internal/tray/tray.go @@ -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()