@@ -17,6 +17,8 @@ import (
1717type UI struct {
1818 app fyne.App
1919 wUpdateProgress fyne.Window
20+ resultErrCh chan error
21+ resultOkCh chan struct {}
2022}
2123
2224func NewUI () * UI {
@@ -32,12 +34,12 @@ func (u *UI) Run() {
3234 u .app .Run ()
3335}
3436
35- func (u * UI ) ShowUpdateProgress (ctx context.Context ) {
37+ func (u * UI ) ShowUpdateProgress (ctx context.Context , version string ) {
3638 log .Infof ("show installer progress window" )
3739 u .wUpdateProgress = u .app .NewWindow ("Automatically updating client" )
3840
41+ infoLabel := widget .NewLabel (fmt .Sprintf ("Your client version is older than the auto-update version set in Management.\n Updating client to %s." , version ))
3942 statusLabel := widget .NewLabel ("Updating..." )
40- infoLabel := widget .NewLabel ("Your client version is older than the auto-update version set in Management.\n Updating client now." )
4143 content := container .NewVBox (infoLabel , statusLabel )
4244 u .wUpdateProgress .SetContent (content )
4345 u .wUpdateProgress .CenterOnScreen ()
@@ -51,10 +53,6 @@ func (u *UI) ShowUpdateProgress(ctx context.Context) {
5153 // Initialize dot updater
5254 updateText := dotUpdater ()
5355
54- // Channel to receive the result from RPC call
55- resultErrCh := make (chan error , 1 )
56- resultOkCh := make (chan struct {}, 1 )
57-
5856 // Update UI with dots and wait for result
5957 go func () {
6058 ticker := time .NewTicker (time .Second )
@@ -65,10 +63,10 @@ func (u *UI) ShowUpdateProgress(ctx context.Context) {
6563 case <- ctx .Done ():
6664 u .showInstallerResult (statusLabel , ctx .Err ())
6765 return
68- case err := <- resultErrCh :
66+ case err := <- u . resultErrCh :
6967 u .showInstallerResult (statusLabel , err )
7068 return
71- case <- resultOkCh :
69+ case <- u . resultOkCh :
7270 u .wUpdateProgress .SetCloseIntercept (nil )
7371 u .wUpdateProgress .Close ()
7472 return
@@ -79,14 +77,35 @@ func (u *UI) ShowUpdateProgress(ctx context.Context) {
7977 }()
8078}
8179
80+ func (u * UI ) UpdateSuccess () {
81+ select {
82+ case u .resultOkCh <- struct {}{}:
83+ log .Infof ("update success signal sent" )
84+ default :
85+ log .Warnf ("could not send update success signal - channel full or already processed" )
86+ }
87+ }
88+
89+ func (u * UI ) SetError (err error ) {
90+ if err == nil {
91+ return
92+ }
93+ select {
94+ case u .resultErrCh <- err :
95+ log .Infof ("update error signal sent: %v" , err )
96+ default :
97+ log .Warnf ("could not send update error signal - channel full or already processed" )
98+ }
99+ }
100+
82101func (u * UI ) showInstallerResult (statusLabel * widget.Label , err error ) {
83102 u .wUpdateProgress .SetCloseIntercept (nil )
84103 switch {
85104 case errors .Is (err , context .DeadlineExceeded ):
86- log .Warn ("update watcher timed out" )
105+ log .Warn ("update timed out" )
87106 statusLabel .SetText ("Update timed out. Please try again." )
88107 case errors .Is (err , context .Canceled ):
89- log .Info ("update watcher canceled" )
108+ log .Info ("update canceled" )
90109 statusLabel .SetText ("Update canceled." )
91110 case err != nil :
92111 log .Errorf ("update failed: %v" , err )
0 commit comments