[GODT-274] GUI changes for autoupdates

[GODT-275] Add enable/disable auto updates GUI option

Refactor Updater module
GODT-805 Changed manual update information bar layout
GODT-806, GODT-875 Change update dialogs
Refactor InformationBar
This commit is contained in:
Alexander Bilyak
2020-11-10 08:09:17 +00:00
committed by James Houlahan
parent b7b2297635
commit 98ab794f13
34 changed files with 1069 additions and 612 deletions

View File

@ -23,6 +23,7 @@ import (
"errors"
"os"
"github.com/ProtonMail/proton-bridge/internal/config/settings"
"github.com/ProtonMail/proton-bridge/internal/events"
qtcommon "github.com/ProtonMail/proton-bridge/internal/frontend/qt-common"
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
@ -50,6 +51,7 @@ var log = logrus.WithField("pkg", "frontend-qt-ie")
type FrontendQt struct {
panicHandler types.PanicHandler
locations *locations.Locations
settings *settings.Settings
eventListener listener.Listener
updater types.Updater
ie types.ImportExporter
@ -71,14 +73,17 @@ type FrontendQt struct {
progress *transfer.Progress
restarter types.Restarter
// saving most up-to-date update info to install it manually
updateInfo updater.VersionInfo
}
// New is constructor for Import-Export Qt-Go interface
func New(
version, buildVersion string,
panicHandler types.PanicHandler,
locations *locations.Locations,
settings *settings.Settings,
eventListener listener.Listener,
updater types.Updater,
ie types.ImportExporter,
@ -87,6 +92,7 @@ func New(
f := &FrontendQt{
panicHandler: panicHandler,
locations: locations,
settings: settings,
programName: "ProtonMail Import-Export",
programVersion: "v" + version,
eventListener: eventListener,
@ -111,9 +117,21 @@ func (f *FrontendQt) Loop() (err error) {
return err
}
func (f *FrontendQt) NotifyManualUpdate(update updater.VersionInfo) error {
// NOTE: Save the update somewhere so that it can be installed when user chooses "install now".
return nil
func (f *FrontendQt) NotifyManualUpdate(update updater.VersionInfo, canInstall bool) {
f.Qml.SetUpdateVersion(update.Version.String())
f.Qml.SetUpdateLandingPage(update.Landing)
f.Qml.SetUpdateReleaseNotesLink("https://protonmail.com/download/ie/release_notes.html")
f.Qml.SetUpdateCanInstall(canInstall)
f.updateInfo = update
f.Qml.NotifyManualUpdate()
}
func (f *FrontendQt) NotifySilentUpdateInstalled() {
f.Qml.NotifySilentUpdateRestartNeeded()
}
func (f *FrontendQt) NotifySilentUpdateError(err error) {
f.Qml.NotifySilentUpdateError()
}
func (f *FrontendQt) watchEvents() {
@ -152,7 +170,7 @@ func (f *FrontendQt) watchEvents() {
f.Qml.NotifyLogout(user.Username())
case <-updateApplicationCh:
f.Qml.ProcessFinished()
f.Qml.NotifyUpdate()
f.Qml.NotifyForceUpdate()
case <-newUserCh:
f.Qml.LoadAccounts()
}
@ -219,6 +237,12 @@ func (f *FrontendQt) QtExecute(Procedure func(*FrontendQt) error) error {
f.Qml.SetCredits(importexport.Credits)
f.Qml.SetFullversion(f.buildVersion)
if f.settings.GetBool(settings.AutoUpdateKey) {
f.Qml.SetIsAutoUpdate(true)
} else {
f.Qml.SetIsAutoUpdate(false)
}
// Loop
if ret := gui.QGuiApplication_Exec(); ret != 0 {
//err := errors.New(errors.ErrQApplication, "Event loop ended with return value: %v", string(ret))
@ -299,6 +323,18 @@ func (f *FrontendQt) sendBug(description, emailClient, address string) bool {
return true
}
func (f *FrontendQt) toggleAutoUpdate() {
defer f.Qml.ProcessFinished()
if f.settings.GetBool(settings.AutoUpdateKey) {
f.settings.SetBool(settings.AutoUpdateKey, false)
f.Qml.SetIsAutoUpdate(false)
} else {
f.settings.SetBool(settings.AutoUpdateKey, true)
f.Qml.SetIsAutoUpdate(true)
}
}
// checkInternet is almost idetical to bridge
func (f *FrontendQt) checkInternet() {
f.Qml.SetConnectionStatus(f.ie.CheckConnection() == nil)
@ -369,21 +405,43 @@ func (f *FrontendQt) setProgressManager(progress *transfer.Progress) {
}()
}
func (f *FrontendQt) StartUpdate() {
// NOTE: Fix this.
func (f *FrontendQt) startManualUpdate() {
go func() {
err := f.updater.InstallUpdate(f.updateInfo)
if err != nil {
logrus.WithError(err).Error("An error occurred while installing updates manually")
f.Qml.NotifyManualUpdateError()
}
f.Qml.NotifyManualUpdateRestartNeeded()
}()
}
// isNewVersionAvailable is identical to bridge
// return 0 when local version is fine
// return 1 when new version is available
func (f *FrontendQt) isNewVersionAvailable(showMessage bool) {
func (f *FrontendQt) checkForUpdates() {
go func() {
defer f.Qml.ProcessFinished()
f.Qml.SetConnectionStatus(true) // if we are here connection is ok
f.Qml.SetUpdateState(StatusUpToDate)
if showMessage {
f.Qml.NotifyVersionIsTheLatest()
version, err := f.updater.Check()
if err != nil {
logrus.WithError(err).Error("An error occurred while checking updates manually")
f.Qml.NotifyManualUpdateError()
return
}
if !f.updater.IsUpdateApplicable(version) {
logrus.Debug("No need to update")
return
}
logrus.WithField("version", version.Version).Info("An update is available")
if !f.updater.CanInstall(version) {
logrus.Debug("A manual update is required")
f.NotifyManualUpdate(version, false)
return
}
f.NotifyManualUpdate(version, true)
}()
}

View File

@ -23,6 +23,7 @@ import (
"fmt"
"net/http"
"github.com/ProtonMail/proton-bridge/internal/config/settings"
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
"github.com/ProtonMail/proton-bridge/internal/locations"
"github.com/ProtonMail/proton-bridge/internal/updater"
@ -42,15 +43,21 @@ func (s *FrontendHeadless) Loop() error {
return http.ListenAndServe(":8082", nil)
}
func (s *FrontendHeadless) NotifyManualUpdate(update updater.VersionInfo) error {
func (s *FrontendHeadless) NotifyManualUpdate(update updater.VersionInfo, canInstall bool) {
// NOTE: Save the update somewhere so that it can be installed when user chooses "install now".
return nil
}
func (s *FrontendHeadless) NotifySilentUpdateInstalled() {
}
func (s *FrontendHeadless) NotifySilentUpdateError(err error) {
}
func New(
version, buildVersion string,
panicHandler types.PanicHandler,
locations *locations.Locations,
settings *settings.Settings,
eventListener listener.Listener,
updater types.Updater,
ie types.ImportExporter,

View File

@ -33,6 +33,7 @@ type GoQMLInterface struct {
_ func() `constructor:"init"`
_ bool `property:"isAutoUpdate"`
_ string `property:"currentAddress"`
_ string `property:"goos"`
_ string `property:"credits"`
@ -49,11 +50,21 @@ type GoQMLInterface struct {
_ string `property:importLogFileName`
_ string `property:"programTitle"`
_ string `property:"newversion"`
_ string `property:"fullversion"`
_ string `property:"downloadLink"`
_ string `property:"landingPage"`
_ string `property:"releaseNotesLink"`
_ string `property:"updateVersion"`
_ bool `property:"updateCanInstall"`
_ string `property:"updateLandingPage"`
_ string `property:"updateReleaseNotesLink"`
_ func() `signal:"notifyManualUpdate"`
_ func() `signal:"notifyManualUpdateRestartNeeded"`
_ func() `signal:"notifyManualUpdateError"`
_ func() `signal:"notifyForceUpdate"`
_ func() `signal:"notifySilentUpdateRestartNeeded"`
_ func() `signal:"notifySilentUpdateError"`
_ func() `slot:"checkForUpdates"`
_ func() `slot:"startManualUpdate"`
// translations
_ string `property:"wrongCredentials"`
@ -79,6 +90,7 @@ type GoQMLInterface struct {
_ func() `signal:"showWindow"`
_ func() `slot:"toggleAutoUpdate"`
_ func() `slot:"quit"`
_ func() `slot:"loadAccounts"`
_ func() `slot:"openLogs"`
@ -89,8 +101,7 @@ type GoQMLInterface struct {
_ func() `signal:"highlightSystray"`
_ func() `signal:"normalSystray"`
_ func(showMessage bool) `slot:"isNewVersionAvailable"`
_ func() string `slot:"getBackendVersion"`
_ func() string `slot:"getBackendVersion"`
_ func(description, client, address string) bool `slot:"sendBug"`
_ func(address string) bool `slot:"sendImportReport"`
@ -128,12 +139,10 @@ type GoQMLInterface struct {
_ func() `signal:"notifyVersionIsTheLatest"`
_ func() `signal:"notifyKeychainRebuild"`
_ func() `signal:"notifyHasNoKeychain"`
_ func() `signal:"notifyUpdate"`
_ func(accname string) `signal:"notifyLogout"`
_ func(accname string) `signal:"notifyAddressChanged"`
_ func(accname string) `signal:"notifyAddressChangedLogout"`
_ func() `slot:"startUpdate"`
_ func(hasError bool) `signal:"updateFinished"`
// errors
@ -150,6 +159,7 @@ func (s *GoQMLInterface) init() {}
func (s *GoQMLInterface) SetFrontend(f *FrontendQt) {
s.ConnectQuit(f.App.Quit)
s.ConnectToggleAutoUpdate(f.toggleAutoUpdate)
s.ConnectLoadAccounts(f.Accounts.LoadAccounts)
s.ConnectOpenLogs(f.openLogs)
s.ConnectOpenDownloadLink(f.openDownloadLink)
@ -170,10 +180,10 @@ func (s *GoQMLInterface) SetFrontend(f *FrontendQt) {
s.SetProgramTitle(f.programName)
s.ConnectOpenLicenseFile(f.openLicenseFile)
s.SetReleaseNotesLink("https://protonmail.com/download/ie/release_notes.html")
s.SetUpdateReleaseNotesLink("https://protonmail.com/download/ie/release_notes.html")
s.ConnectGetLocalVersionInfo(f.getLocalVersionInfo)
s.ConnectIsNewVersionAvailable(f.isNewVersionAvailable)
s.ConnectCheckForUpdates(f.checkForUpdates)
s.ConnectGetBackendVersion(func() string {
return f.programVersion
})
@ -193,7 +203,5 @@ func (s *GoQMLInterface) SetFrontend(f *FrontendQt) {
s.ConnectCheckPathStatus(CheckPathStatus)
s.ConnectStartUpdate(f.StartUpdate)
s.ConnectEmitEvent(f.emitEvent)
}