MCPcopy Create free account
hub / github.com/efogdev/mpris-timer / runTicker

Method runTicker

internal/core/core.go:116–173  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114}
115
116func (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}

Callers 1

StartMethod · 0.95

Calls 5

DestroyMethod · 0.95
broadcastMethod · 0.95
MakeProgressCircleFunction · 0.85
FormatDurationFunction · 0.85
StopMethod · 0.80

Tested by

no test coverage detected