Skip to content

Commit b029539

Browse files
committed
Exit from updater UI after close window
1 parent fb912b5 commit b029539

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

client/ui/update/main.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ func Execute() {
7575
ui := NewUI()
7676

7777
// Create a context with timeout for the entire update process
78-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
79-
defer cancel()
78+
//defer cancel()
8079

81-
ui.ShowUpdateProgress(ctx, targetVersionFlag)
80+
ui.ShowUpdateProgress(context.Background(), targetVersionFlag)
8281
// Run the update function in a goroutine
8382
go func() {
84-
defer cancel()
83+
//defer cancel()
8584

86-
if err := update(); err != nil {
85+
ctx, _ := context.WithTimeout(context.Background(), 10*time.Minute)
86+
if err := update(ctx); err != nil {
8787
log.Errorf("update failed: %v", err)
8888
ui.SetError(err)
8989
return
@@ -98,11 +98,10 @@ func Execute() {
9898
ui.Run()
9999
}
100100

101-
func update() error {
101+
func update(ctx context.Context) error {
102102
log.Infof("updater started: %s, %s", serviceDirFlag, targetVersionFlag)
103103
updater := installer.NewWithDir(tempDirFlag)
104-
if err := updater.Setup(context.Background(), dryRunFlag, targetVersionFlag, serviceDirFlag); err != nil {
105-
// todo update ui
104+
if err := updater.Setup(ctx, dryRunFlag, targetVersionFlag, serviceDirFlag); err != nil {
106105
log.Errorf("failed to update application: %v", err)
107106
return err
108107
}

client/ui/update/progresswindow.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func NewUI() *UI {
2626
a := app.NewWithID("NetBird-update")
2727

2828
return &UI{
29-
app: a,
29+
app: a,
30+
resultErrCh: make(chan error, 1),
31+
resultOkCh: make(chan struct{}, 1),
3032
}
3133
}
3234

@@ -61,13 +63,15 @@ func (u *UI) ShowUpdateProgress(ctx context.Context, version string) {
6163
for {
6264
select {
6365
case <-ctx.Done():
66+
u.wUpdateProgress.SetCloseIntercept(u.closeApp)
6467
u.showInstallerResult(statusLabel, ctx.Err())
6568
return
6669
case err := <-u.resultErrCh:
70+
u.wUpdateProgress.SetCloseIntercept(u.closeApp)
6771
u.showInstallerResult(statusLabel, err)
6872
return
6973
case <-u.resultOkCh:
70-
u.wUpdateProgress.SetCloseIntercept(nil)
74+
u.wUpdateProgress.SetCloseIntercept(u.closeApp)
7175
u.wUpdateProgress.Close()
7276
return
7377
case <-ticker.C:
@@ -99,7 +103,6 @@ func (u *UI) SetError(err error) {
99103
}
100104

101105
func (u *UI) showInstallerResult(statusLabel *widget.Label, err error) {
102-
u.wUpdateProgress.SetCloseIntercept(nil)
103106
switch {
104107
case errors.Is(err, context.DeadlineExceeded):
105108
log.Warn("update timed out")
@@ -115,6 +118,11 @@ func (u *UI) showInstallerResult(statusLabel *widget.Label, err error) {
115118
}
116119
}
117120

121+
func (u *UI) closeApp() {
122+
log.Infof("close updater UI app")
123+
u.app.Quit()
124+
}
125+
118126
// dotUpdater returns a closure that cycles through dots for a loading animation.
119127
func dotUpdater() func() string {
120128
dotCount := 0

0 commit comments

Comments
 (0)