Skip to content

Commit 4990b26

Browse files
committed
Handle results on UI
1 parent 0f8ae14 commit 4990b26

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

client/internal/debug/debug.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ func (g *BundleGenerator) addUpdateLogs() error {
607607
inst, err := installer.New()
608608
if err != nil {
609609
// unsupported platform
610+
// nolint
610611
return nil
611612
}
612613
log.Infof("adding updater logs")

client/internal/updatemanager/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func NewManager(statusRecorder *peer.Status, stateManager *statemanager.Manager)
7878
// CheckUpdateSuccess checks if the update was successful. It works without to start the update manager.
7979
func (m *Manager) CheckUpdateSuccess(ctx context.Context) {
8080
m.updateStateManager(ctx)
81-
return
8281
}
8382

8483
func (m *Manager) Start(ctx context.Context) {

client/ui/client_ui.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ type serviceClient struct {
302302
mExitNodeDeselectAll *systray.MenuItem
303303
logFile string
304304
wLoginURL fyne.Window
305-
wUpdateProgress fyne.Window
306305
updateContextCancel context.CancelFunc
307306
}
308307

client/ui/update/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,28 @@ func Execute() {
4747
return
4848
}
4949

50+
// todo validate target version
51+
5052
ui := NewUI()
5153

5254
// Create a context with timeout for the entire update process
5355
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
5456
defer cancel()
5557

56-
ui.ShowUpdateProgress(ctx)
58+
ui.ShowUpdateProgress(ctx, targetVersionFlag)
5759
// Run the update function in a goroutine
5860
go func() {
5961
defer cancel()
6062

6163
if err := update(); err != nil {
6264
log.Errorf("update failed: %v", err)
63-
// The UI will handle the error display through context cancellation
65+
ui.SetError(err)
6466
return
6567
}
6668

6769
// Success - the UI will automatically close the window
6870
log.Infof("update completed successfully")
71+
ui.UpdateSuccess()
6972
}()
7073

7174
// Start the Fyne app event loop (blocks until window is closed or context is done)

client/ui/update/progresswindow.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
type UI struct {
1818
app fyne.App
1919
wUpdateProgress fyne.Window
20+
resultErrCh chan error
21+
resultOkCh chan struct{}
2022
}
2123

2224
func 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.\nUpdating 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.\nUpdating 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+
82101
func (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

Comments
 (0)