Skip to content

Commit 7363394

Browse files
committed
finalize progress bar
1 parent 049a630 commit 7363394

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

internal/update/apt/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
7878
return nil, update.ErrOperationAlreadyInProgress
7979
}
8080
eventsCh := make(chan update.Event, 100)
81-
8281
go func() {
8382
defer s.lock.Unlock()
8483
defer close(eventsCh)
@@ -96,6 +95,7 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
9695
}()
9796

9897
eventsCh <- update.NewDataEvent(update.StartEvent, "Upgrade is starting")
98+
eventsCh <- update.NewProgressEvent(0.0)
9999
stream := runUpgradeCommand(ctx, names)
100100
for line, err := range stream {
101101
if err != nil {
@@ -104,14 +104,14 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
104104
}
105105
eventsCh <- update.NewDataEvent(update.UpgradeLineEvent, line)
106106
}
107-
108107
eventsCh <- update.NewDataEvent(update.StartEvent, "apt cleaning cache is starting")
109108
eventsCh <- update.NewProgressEvent(80.0)
110109
for line, err := range runAptCleanCommand(ctx) {
111110
if err != nil {
112111
eventsCh <- update.NewErrorEvent(fmt.Errorf("error running apt clean command: %w", err))
113112
return
114113
}
114+
115115
eventsCh <- update.NewDataEvent(update.UpgradeLineEvent, line)
116116
}
117117
eventsCh <- update.NewProgressEvent(85.0)

internal/update/arduino/arduino.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
144144
defer a.lock.Unlock()
145145
defer close(eventsCh)
146146

147-
const indexWeight float32 = 30.0
148147
const indexBase float32 = 0.0
148+
const indexWeight float32 = 30.0
149149
const upgradeBase float32 = 30.0
150150
const upgradeWeight float32 = 60.0
151151

internal/update/event.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func NewDataEvent(t EventType, data string) Event {
6969

7070
func NewProgressEvent(progress float32) Event {
7171
return Event{
72-
Type: ProgressEvent,
73-
data: fmt.Sprintf("%.2f", progress),
72+
Type: ProgressEvent,
73+
data: fmt.Sprintf("%.2f", progress),
74+
Progress: progress,
7475
}
7576
}
7677

internal/update/update.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,11 @@ func (m *Manager) UpgradePackages(ctx context.Context, pkgs []UpgradablePackage)
148148
for e := range arduinoEvents {
149149
if e.Type == ProgressEvent {
150150
globalProgress := (e.Progress / 100.0) * arduinoWeight
151-
fmt.Println("++++++++++++++++++++++++ globalProgress arduinoEvents:", globalProgress)
152-
slog.Debug("Arduino upgrade progress", slog.Float64("globalProgress", float64(globalProgress)))
153151
m.broadcast(NewProgressEvent(globalProgress))
154152
} else {
155153
m.broadcast(e)
156154
}
157155
}
158-
159156
aptEvents, err := m.debUpdateService.UpgradePackages(ctx, debPkgs)
160157
if err != nil {
161158
m.broadcast(NewErrorEvent(fmt.Errorf("failed to upgrade APT packages: %w", err)))
@@ -164,14 +161,12 @@ func (m *Manager) UpgradePackages(ctx context.Context, pkgs []UpgradablePackage)
164161
for e := range aptEvents {
165162
if e.Type == ProgressEvent {
166163
globalProgress := arduinoWeight + (e.Progress/100.0)*aptWeight
167-
fmt.Println("++++++++++++++++++++++++ globalProgress APT:", globalProgress)
168-
slog.Debug("APT upgrade progress", slog.Float64("globalProgress", float64(globalProgress)))
169164
m.broadcast(NewProgressEvent(globalProgress))
170165
} else {
171166
m.broadcast(e)
172167
}
173168
}
174-
169+
m.broadcast(NewProgressEvent(100.0))
175170
m.broadcast(NewDataEvent(DoneEvent, "Update completed"))
176171
}()
177172
return nil

0 commit comments

Comments
 (0)