1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 21:17:59 +00:00
rolens/internal/ui/progress.go

35 lines
622 B
Go
Raw Permalink Normal View History

2023-02-21 19:11:40 +00:00
package ui
2023-05-26 15:21:39 +00:00
import (
"time"
2023-02-21 19:11:40 +00:00
2023-05-26 15:21:39 +00:00
"github.com/ncruces/zenity"
)
2023-05-27 15:52:51 +00:00
// @todo: this takes ~0.5 seconds. Improve?
2023-05-26 15:21:39 +00:00
func (u *UI) StartProgressBar(id uint, title string) {
2023-02-21 19:11:40 +00:00
if title == "" {
// default title
2023-05-26 15:21:39 +00:00
title = "Loading…"
2023-02-21 19:11:40 +00:00
}
2023-05-26 15:21:39 +00:00
p, err := zenity.Progress(zenity.Title(title), zenity.Pulsate(), zenity.Modal())
2023-02-21 19:11:40 +00:00
if err != nil {
return
}
2023-05-26 15:21:39 +00:00
u.progressBars[id] = p
2023-02-21 19:11:40 +00:00
}
2023-05-26 15:21:39 +00:00
func (u *UI) StopProgressBar(id uint) {
for try := 0; try < 10; try++ {
2023-05-27 15:52:51 +00:00
if p := u.progressBars[id]; p != nil {
2023-05-26 15:21:39 +00:00
p.Complete()
p.Close()
p = nil
return
}
2023-05-27 15:52:51 +00:00
2023-05-26 15:21:39 +00:00
println("Progress dialog not found:", id, try)
time.Sleep(100 * time.Millisecond)
2023-02-21 19:11:40 +00:00
}
}