()
| 114 | } |
| 115 | |
| 116 | func (p *TimerPlayer) runTicker() { |
| 117 | log.Printf("player requested, fps = %d", p.fps) |
| 118 | |
| 119 | p.progress = 0.0 |
| 120 | mu := sync.Mutex{} |
| 121 | img, _ := MakeProgressCircle(0) |
| 122 | img = "file://" + img |
| 123 | p.img = img |
| 124 | |
| 125 | renderTicker := time.NewTicker(time.Duration(int64(time.Second) / int64(p.fps))) |
| 126 | defer renderTicker.Stop() |
| 127 | go func() { |
| 128 | for range renderTicker.C { |
| 129 | mu.Lock() |
| 130 | img, _ = MakeProgressCircle(p.progress) |
| 131 | img = "file://" + img |
| 132 | p.img = img |
| 133 | mu.Unlock() |
| 134 | } |
| 135 | }() |
| 136 | |
| 137 | ticker := time.NewTicker(p.interval) |
| 138 | defer ticker.Stop() |
| 139 | for { |
| 140 | select { |
| 141 | case <-p.tickerDone: |
| 142 | p.Destroy() |
| 143 | return |
| 144 | case <-ticker.C: |
| 145 | if p.isPaused { |
| 146 | continue |
| 147 | } |
| 148 | |
| 149 | elapsed := time.Since(p.startTime) - p.pausedFor |
| 150 | timeLeft := p.duration - elapsed |
| 151 | |
| 152 | mu.Lock() |
| 153 | p.progress = math.Min(100, (float64(elapsed)/float64(p.duration))*100) |
| 154 | if p.progress == 100 { |
| 155 | p.IsFinished = true |
| 156 | p.broadcast() |
| 157 | p.Destroy() |
| 158 | mu.Unlock() |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | p.progressText = FormatDuration(timeLeft) |
| 163 | p.emitter <- PropsChangedEvent{ |
| 164 | Text: p.progressText, |
| 165 | Img: img, |
| 166 | IsPaused: p.isPaused, |
| 167 | } |
| 168 | mu.Unlock() |
| 169 | |
| 170 | p.broadcast() |
| 171 | } |
| 172 | } |
| 173 | } |
no test coverage detected