From feeb7179f5e4acbd3c2866956adb4d896529dff1 Mon Sep 17 00:00:00 2001 From: Michal Horejsek Date: Tue, 23 Feb 2021 08:50:18 +0100 Subject: [PATCH] GODT-1058 Install after chaning channel right away only in case of downgrade --- internal/bridge/bridge.go | 27 +++++++++++-------- internal/frontend/cli/updates.go | 13 ++++++--- .../frontend/qml/BridgeUI/DialogYesNo.qml | 4 +-- internal/frontend/qt/accounts.go | 2 +- internal/frontend/qt/frontend.go | 8 +++--- internal/frontend/types/types.go | 2 +- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.go index 4f950c46..ead478d0 100644 --- a/internal/bridge/bridge.go +++ b/internal/bridge/bridge.go @@ -151,28 +151,33 @@ func (b *Bridge) GetUpdateChannel() updater.UpdateChannel { // Downgrading to previous version (by switching from early to stable, for example) // requires clearing all data including update files due to possibility of // inconsistency between versions and absence of backwards migration scripts. -func (b *Bridge) SetUpdateChannel(channel updater.UpdateChannel) error { +func (b *Bridge) SetUpdateChannel(channel updater.UpdateChannel) (needRestart bool, err error) { b.settings.Set(settings.UpdateChannelKey, string(channel)) version, err := b.updater.Check() if err != nil { - return err + return false, err } - if b.updater.IsDowngrade(version) { - if err := b.Users.ClearData(); err != nil { - log.WithError(err).Error("Failed to clear data while downgrading channel") - } - if err := b.locations.ClearUpdates(); err != nil { - log.WithError(err).Error("Failed to clear updates while downgrading channel") - } + // We have to deal right away only with downgrade - that action needs to + // clear data and updates, and install bridge right away. But regular + // upgrade can be leaved out for periodic check. + if !b.updater.IsDowngrade(version) { + return false, nil + } + + if err := b.Users.ClearData(); err != nil { + log.WithError(err).Error("Failed to clear data while downgrading channel") + } + if err := b.locations.ClearUpdates(); err != nil { + log.WithError(err).Error("Failed to clear updates while downgrading channel") } if err := b.updater.InstallUpdate(version); err != nil { - return err + return false, err } - return b.versioner.RemoveOtherVersions(version.Version) + return true, b.versioner.RemoveOtherVersions(version.Version) } // GetKeychainApp returns current keychain helper. diff --git a/internal/frontend/cli/updates.go b/internal/frontend/cli/updates.go index 4316517f..5050023d 100644 --- a/internal/frontend/cli/updates.go +++ b/internal/frontend/cli/updates.go @@ -81,9 +81,13 @@ func (f *frontendCLI) selectEarlyChannel(c *ishell.Context) { f.Println("Bridge is currently on the stable update channel.") if f.yesNoQuestion("Are you sure you want to switch to the early-access update channel") { - if err := f.bridge.SetUpdateChannel(updater.EarlyChannel); err != nil { + needRestart, err := f.bridge.SetUpdateChannel(updater.EarlyChannel) + if err != nil { f.Println("There was a problem switching update channel.") } + if needRestart { + f.restarter.SetToRestart() + } } } @@ -97,9 +101,12 @@ func (f *frontendCLI) selectStableChannel(c *ishell.Context) { f.Println("Switching to the stable channel may reset all data!") if f.yesNoQuestion("Are you sure you want to switch to the stable update channel") { - if err := f.bridge.SetUpdateChannel(updater.StableChannel); err != nil { + needRestart, err := f.bridge.SetUpdateChannel(updater.StableChannel) + if err != nil { f.Println("There was a problem switching update channel.") } - f.restarter.SetToRestart() + if needRestart { + f.restarter.SetToRestart() + } } } diff --git a/internal/frontend/qml/BridgeUI/DialogYesNo.qml b/internal/frontend/qml/BridgeUI/DialogYesNo.qml index d6f4ac30..e5392f60 100644 --- a/internal/frontend/qml/BridgeUI/DialogYesNo.qml +++ b/internal/frontend/qml/BridgeUI/DialogYesNo.qml @@ -229,7 +229,7 @@ Dialog { currentIndex : 0 title : qsTr("Clear cache", "title of page that displays during cache clearing") question : qsTr("Are you sure you want to clear your local cache?", "displays during cache clearing") - note : qsTr("This will delete all of your stored preferences as well as cached email data for all accounts, temporarily slowing down the email download process significantly.", "displays during cache clearing") + note : qsTr("This will delete all of your stored preferences as well as cached email data for all accounts, and requires you to reconfigure your client.", "displays during cache clearing") answer : qsTr("Clearing the cache ...", "displays during cache clearing") } }, @@ -310,7 +310,7 @@ Dialog { target: root currentIndex : 0 question : qsTr("Are you sure you want to leave early access? Please keep in mind this operation clears the cache and restarts Bridge.") - note : qsTr("This will delete all of your stored preferences as well as cached email data for all accounts, temporarily slowing down the email download process significantly.") + note : qsTr("This will delete all of your stored preferences as well as cached email data for all accounts, and requires you to reconfigure your client.") title : qsTr("Disable early access") answer : qsTr("Disabling early access...") } diff --git a/internal/frontend/qt/accounts.go b/internal/frontend/qt/accounts.go index 56d1b463..0e3ba53a 100644 --- a/internal/frontend/qt/accounts.go +++ b/internal/frontend/qt/accounts.go @@ -84,7 +84,7 @@ func (s *FrontendQt) clearCache() { channel := s.bridge.GetUpdateChannel() if channel == updater.EarlyChannel { - if err := s.bridge.SetUpdateChannel(updater.StableChannel); err != nil { + if _, err := s.bridge.SetUpdateChannel(updater.StableChannel); err != nil { s.Qml.NotifyManualUpdateError() return } diff --git a/internal/frontend/qt/frontend.go b/internal/frontend/qt/frontend.go index b82376da..8deeb7bf 100644 --- a/internal/frontend/qt/frontend.go +++ b/internal/frontend/qt/frontend.go @@ -605,14 +605,16 @@ func (s *FrontendQt) toggleEarlyAccess() { channel = updater.EarlyChannel } - err := s.bridge.SetUpdateChannel(channel) + needRestart, err := s.bridge.SetUpdateChannel(channel) s.Qml.SetIsEarlyAccess(channel == updater.EarlyChannel) if err != nil { s.Qml.NotifyManualUpdateError() return } - s.restarter.SetToRestart() - s.App.Quit() + if needRestart { + s.restarter.SetToRestart() + s.App.Quit() + } } func (s *FrontendQt) toggleAllowProxy() { diff --git a/internal/frontend/types/types.go b/internal/frontend/types/types.go index 3b375b70..b32e66aa 100644 --- a/internal/frontend/types/types.go +++ b/internal/frontend/types/types.go @@ -79,7 +79,7 @@ type Bridger interface { AllowProxy() DisallowProxy() GetUpdateChannel() updater.UpdateChannel - SetUpdateChannel(updater.UpdateChannel) error + SetUpdateChannel(updater.UpdateChannel) (needRestart bool, err error) GetKeychainApp() string SetKeychainApp(keychain string) }