This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/pkg/login-app/cmd/dialog-reboot.go

51 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"time"
ui "github.com/VladimirMarkelov/clui"
)
type RebootDialog struct {
View *ui.Window
}
func CreateRebootDialog(title, login string) *RebootDialog {
dlg := new(RebootDialog)
sWidth, sHeight := ui.ScreenSize()
wWidth, wHeight := 50, 10
dlg.View = ui.AddWindow(sWidth/2-wWidth/2, sHeight/2-wHeight/2, wWidth, wHeight, title)
ui.WindowManager().BeginUpdate()
defer ui.WindowManager().EndUpdate()
dlg.View.SetModal(true)
dlg.View.SetSizable(false)
dlg.View.SetTitleButtons(ui.ButtonDefault)
dlg.View.SetPack(ui.Vertical)
textfrm := ui.CreateFrame(dlg.View, 1, 1, ui.BorderNone, ui.Fixed)
textfrm.SetPaddings(1, 1)
textfrm.SetPack(ui.Vertical)
textfrm.SetGaps(2, 1)
ui.CreateLabel(textfrm, ui.AutoSize, ui.AutoSize, "You are now successfully logged in as:", ui.Fixed)
ui.CreateLabel(textfrm, ui.AutoSize, ui.AutoSize, login, ui.Fixed)
ui.CreateLabel(textfrm, ui.AutoSize, ui.AutoSize, "Your computer will automatically", ui.Fixed)
ui.CreateLabel(textfrm, ui.AutoSize, ui.AutoSize, "reboot in a few seconds...", ui.Fixed)
progress := ui.CreateProgressBar(textfrm, ui.AutoSize, ui.AutoSize, 1)
progress.SetLimits(0, 100)
go func() {
for i := 0; i < 100; i += 1 {
progress.SetValue(i)
ui.PutEvent(ui.Event{Type: ui.EventRedraw})
time.Sleep(64 * time.Millisecond)
}
ui.WindowManager().DestroyWindow(dlg.View)
}()
return dlg
}