From 649364beb55a08101f27c86d80c15f8d1a768fe6 Mon Sep 17 00:00:00 2001 From: Romain LE JEUNE Date: Mon, 25 Jul 2022 10:03:54 +0200 Subject: [PATCH] GODT-1670: restore update [skip-ci] GODT-1670: Log the gRPC call --- internal/frontend/bridge-gui/QMLBackend.cpp | 4 +- internal/frontend/bridge-gui/main.cpp | 1 - internal/frontend/grpc/service.go | 43 +++++++++++++++++++-- internal/frontend/grpc/service_methods.go | 7 +++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/internal/frontend/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/QMLBackend.cpp index a5d6b3a8..c4d47b4b 100644 --- a/internal/frontend/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/QMLBackend.cpp @@ -305,7 +305,7 @@ void QMLBackend::toggleAutomaticUpdate(bool active) //**************************************************************************************************************************************************** void QMLBackend::checkUpdates() { - app().grpc().checkUpdate(); + logGRPCCallStatus(app().grpc().checkUpdate(), "checkUpdate"); } @@ -314,7 +314,7 @@ void QMLBackend::checkUpdates() //**************************************************************************************************************************************************** void QMLBackend::installUpdate() { - app().log().error(QString("%1() is not implemented.").arg(__FUNCTION__)); + logGRPCCallStatus(app().grpc().installUpdate(), "installUpdate"); } diff --git a/internal/frontend/bridge-gui/main.cpp b/internal/frontend/bridge-gui/main.cpp index a9c6f7f9..9017dd54 100644 --- a/internal/frontend/bridge-gui/main.cpp +++ b/internal/frontend/bridge-gui/main.cpp @@ -33,7 +33,6 @@ void initQtApplication() if ((!qsgInfo.isEmpty()) && (qsgInfo != "0")) QLoggingCategory::setFilterRules("qt.scenegraph.general=true"); - /// \todo GODT-1670 Get version from go backend. QGuiApplication::setApplicationName("Proton Mail Bridge"); QGuiApplication::setApplicationVersion(PROJECT_VER); QGuiApplication::setOrganizationName("Proton AG"); diff --git a/internal/frontend/grpc/service.go b/internal/frontend/grpc/service.go index 845195b2..41fe3ae4 100644 --- a/internal/frontend/grpc/service.go +++ b/internal/frontend/grpc/service.go @@ -38,6 +38,7 @@ import ( "github.com/ProtonMail/proton-bridge/v2/pkg/keychain" "github.com/ProtonMail/proton-bridge/v2/pkg/listener" "github.com/ProtonMail/proton-bridge/v2/pkg/pmapi" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -179,9 +180,17 @@ func (s *Service) NotifyManualUpdate(version updater.VersionInfo, canInstall boo func (s *Service) SetVersion(update updater.VersionInfo) { s.newVersionInfo = update } -func (s *Service) NotifySilentUpdateInstalled() {} -func (s *Service) NotifySilentUpdateError(error) {} -func (s *Service) WaitUntilFrontendIsReady() {} + +func (s *Service) NotifySilentUpdateInstalled() { + _ = s.SendEvent(NewUpdateSilentRestartNeededEvent()) +} + +func (s *Service) NotifySilentUpdateError(err error) { + s.log.WithError(err).Error("In app update failed, asking for manual.") + _ = s.SendEvent(NewUpdateErrorEvent(UpdateErrorType_UPDATE_SILENT_ERROR)) +} + +func (s *Service) WaitUntilFrontendIsReady() {} func (s *Service) watchEvents() { // nolint:funlen if s.bridge.HasError(bridge.ErrLocalCacheUnavailable) { @@ -336,7 +345,10 @@ func (s *Service) checkUpdate() { } func (s *Service) updateForce() { - s.log.Error("updateForce is not implemented") // TO-DO GODT-1670 implement update. + checkingUpdates.Lock() + defer checkingUpdates.Unlock() + s.checkUpdate() + _ = s.SendEvent(NewUpdateForceEvent(s.newVersionInfo.Version.String())) } func (s *Service) checkUpdateAndNotify(isReqFromUser bool) { @@ -363,3 +375,26 @@ func (s *Service) checkUpdateAndNotify(isReqFromUser bool) { s.NotifyManualUpdate(s.newVersionInfo, s.updater.CanInstall(s.newVersionInfo)) } } + +func (s *Service) installUpdate() { + checkingUpdates.Lock() + defer checkingUpdates.Unlock() + + if !s.updater.CanInstall(s.newVersionInfo) { + s.log.Warning("Skipping update installation, current version too old") + _ = s.SendEvent(NewUpdateErrorEvent(UpdateErrorType_UPDATE_MANUAL_ERROR)) + return + } + + if err := s.updater.InstallUpdate(s.newVersionInfo); err != nil { + if errors.Cause(err) == updater.ErrDownloadVerify { + s.log.WithError(err).Warning("Skipping update installation due to temporary error") + } else { + s.log.WithError(err).Error("The update couldn't be installed") + _ = s.SendEvent(NewUpdateErrorEvent(UpdateErrorType_UPDATE_MANUAL_ERROR)) + } + return + } + + _ = s.SendEvent(NewUpdateSilentRestartNeededEvent()) +} diff --git a/internal/frontend/grpc/service_methods.go b/internal/frontend/grpc/service_methods.go index 59a24149..24911ed0 100644 --- a/internal/frontend/grpc/service_methods.go +++ b/internal/frontend/grpc/service_methods.go @@ -404,7 +404,12 @@ func (s *Service) CheckUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty, func (s *Service) InstallUpdate(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { s.log.Info("InstallUpdate") - // TO-DO GODT-1670 Implement update install + go func() { + defer s.panicHandler.HandlePanic() + + s.installUpdate() + }() + return &emptypb.Empty{}, nil }