Commit 197e62f4 authored by Roman Alifanov's avatar Roman Alifanov

Add RebootRequired to UpdateCategory, use for reboot button logic

parent 7a754a31
package model package model
type UpdateCategory struct { type UpdateCategory struct {
Name string Name string
Enabled bool // User can toggle this category Enabled bool // User can toggle this category
Available bool // Has updates available Available bool // Has updates available
Packages []Package RebootRequired bool
DownloadSize uint64 Packages []Package
InstallSize int64 DownloadSize uint64
LastChecked string // RFC3339 timestamp InstallSize int64
LastChecked string // RFC3339 timestamp
} }
type KernelUpdateInfo struct { type KernelUpdateInfo struct {
......
...@@ -148,7 +148,13 @@ func (us *UpdateService) RunUpdates(ctx context.Context) error { ...@@ -148,7 +148,13 @@ func (us *UpdateService) RunUpdates(ctx context.Context) error {
startTime := time.Now() startTime := time.Now()
packagesUpdated := 0 packagesUpdated := 0
var categoryErrors []string var categoryErrors []string
systemOrKernelSucceeded := false rebootRequired := false
categoryMap := map[string]*model.UpdateCategory{
"System": state.SystemUpdates,
"Kernel": state.KernelUpdates,
"Play": state.PlayUpdates,
}
// Execute updates sequentially // Execute updates sequentially
for _, category := range categories { for _, category := range categories {
...@@ -158,13 +164,11 @@ func (us *UpdateService) RunUpdates(ctx context.Context) error { ...@@ -158,13 +164,11 @@ func (us *UpdateService) RunUpdates(ctx context.Context) error {
continue continue
} }
switch category { if cat, ok := categoryMap[category]; ok {
case "System": packagesUpdated += len(cat.Packages)
packagesUpdated += len(state.SystemUpdates.Packages) if cat.RebootRequired {
systemOrKernelSucceeded = true rebootRequired = true
case "Kernel": }
packagesUpdated += len(state.KernelUpdates.Packages)
systemOrKernelSucceeded = true
} }
} }
...@@ -174,9 +178,9 @@ func (us *UpdateService) RunUpdates(ctx context.Context) error { ...@@ -174,9 +178,9 @@ func (us *UpdateService) RunUpdates(ctx context.Context) error {
// Finish update // Finish update
success := len(categoryErrors) == 0 success := len(categoryErrors) == 0
us.store.Dispatch(&store.FinishUpdateAction{ us.store.Dispatch(&store.FinishUpdateAction{
Success: success, Success: success,
Error: strings.Join(categoryErrors, "; "), Error: strings.Join(categoryErrors, "; "),
SystemOrKernelSucceeded: systemOrKernelSucceeded, RebootRequired: rebootRequired,
}) })
// Record in history // Record in history
......
...@@ -28,6 +28,7 @@ func (a *LoadSystemUpdatesAction) Apply(state *State) error { ...@@ -28,6 +28,7 @@ func (a *LoadSystemUpdatesAction) Apply(state *State) error {
state.SystemUpdates.Packages = append(state.SystemUpdates.Packages, a.Changes.Install...) state.SystemUpdates.Packages = append(state.SystemUpdates.Packages, a.Changes.Install...)
state.SystemUpdates.DownloadSize = a.Changes.DownloadSize state.SystemUpdates.DownloadSize = a.Changes.DownloadSize
state.SystemUpdates.InstallSize = a.Changes.InstallSize state.SystemUpdates.InstallSize = a.Changes.InstallSize
state.SystemUpdates.RebootRequired = true
state.SystemUpdates.LastChecked = time.Now().Format(time.RFC3339) state.SystemUpdates.LastChecked = time.Now().Format(time.RFC3339)
return nil return nil
} }
...@@ -42,6 +43,7 @@ func (a *LoadKernelUpdatesAction) Apply(state *State) error { ...@@ -42,6 +43,7 @@ func (a *LoadKernelUpdatesAction) Apply(state *State) error {
state.KernelUpdates.Packages = append(state.KernelUpdates.Packages, a.Info.Packages.Install...) state.KernelUpdates.Packages = append(state.KernelUpdates.Packages, a.Info.Packages.Install...)
state.KernelUpdates.DownloadSize = a.Info.Packages.DownloadSize state.KernelUpdates.DownloadSize = a.Info.Packages.DownloadSize
state.KernelUpdates.InstallSize = a.Info.Packages.InstallSize state.KernelUpdates.InstallSize = a.Info.Packages.InstallSize
state.KernelUpdates.RebootRequired = true
state.KernelUpdates.LastChecked = time.Now().Format(time.RFC3339) state.KernelUpdates.LastChecked = time.Now().Format(time.RFC3339)
return nil return nil
} }
...@@ -124,9 +126,9 @@ func (a *UpdateProgressAction) Apply(state *State) error { ...@@ -124,9 +126,9 @@ func (a *UpdateProgressAction) Apply(state *State) error {
} }
type FinishUpdateAction struct { type FinishUpdateAction struct {
Success bool Success bool
Error string Error string
SystemOrKernelSucceeded bool RebootRequired bool
} }
func (a *FinishUpdateAction) Apply(state *State) error { func (a *FinishUpdateAction) Apply(state *State) error {
......
...@@ -136,8 +136,7 @@ func (w *Window) onStateChange(change store.StateChange) { ...@@ -136,8 +136,7 @@ func (w *Window) onStateChange(change store.StateChange) {
case store.ChangeUpdateFinish: case store.ChangeUpdateFinish:
action, ok := change.Data.(*store.FinishUpdateAction) action, ok := change.Data.(*store.FinishUpdateAction)
if ok { if ok {
showReboot := action.Success || action.SystemOrKernelSucceeded w.processPage.ShowComplete(action.Success, action.RebootRequired)
w.processPage.ShowComplete(action.Success, showReboot)
} }
case store.ChangeHistory: case store.ChangeHistory:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment