From 51cfef2fdcd051219e7f883673bbf3799f6baf49 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Fri, 2 Jun 2023 18:34:28 -0400
Subject: [PATCH] updatemanager: use msiexec to launch update installer

Change-Id: I605cc425b600b08dac809f0d38d366279140895d
---
 src/app/lrcinstance.h                         |  1 -
 src/app/mainapplication.cpp                   |  7 ------
 .../components/UpdateDownloadDialog.qml       |  8 +++---
 src/app/updatemanager.cpp                     | 25 ++++++++++---------
 src/app/updatemanager.h                       |  6 ++---
 5 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/src/app/lrcinstance.h b/src/app/lrcinstance.h
index f9c3fd402..19ee68903 100644
--- a/src/app/lrcinstance.h
+++ b/src/app/lrcinstance.h
@@ -138,7 +138,6 @@ Q_SIGNALS:
     void selectedConvUidChanged();
     void restoreAppRequested();
     void notificationClicked();
-    void quitEngineRequested();
     void conversationUpdated(const QString& convId, const QString& accountId);
     void draftSaved(const QString& convId);
     void base64SwarmAvatarChanged();
diff --git a/src/app/mainapplication.cpp b/src/app/mainapplication.cpp
index 526bd2692..a98bd4607 100644
--- a/src/app/mainapplication.cpp
+++ b/src/app/mainapplication.cpp
@@ -177,13 +177,6 @@ MainApplication::init()
         screenInfo_.setCurrentFocusWindow(this->focusWindow());
     });
 
-    QObject::connect(
-        lrcInstance_.get(),
-        &LRCInstance::quitEngineRequested,
-        this,
-        [this] { Q_EMIT engine_->quit(); },
-        Qt::DirectConnection);
-
     auto downloadPath = settingsManager_->getValue(Settings::Key::DownloadPath);
     auto screenshotPath = settingsManager_->getValue(Settings::Key::ScreenshotPath);
     auto allowTransferFromTrusted = settingsManager_->getValue(Settings::Key::AutoAcceptFiles)
diff --git a/src/app/settingsview/components/UpdateDownloadDialog.qml b/src/app/settingsview/components/UpdateDownloadDialog.qml
index e0bab64a7..d4827c223 100644
--- a/src/app/settingsview/components/UpdateDownloadDialog.qml
+++ b/src/app/settingsview/components/UpdateDownloadDialog.qml
@@ -36,12 +36,12 @@ SimpleMessageDialog {
     Connections {
         target: UpdateManager
 
-        function onDownloadProgressChanged(bytesRead, totalBytes) {
-            downloadDialog.setDownloadProgress(bytesRead, totalBytes);
+        function onUpdateErrorOccurred(error) {
+            downloadDialog.close();
         }
 
-        function onUpdateDownloadErrorOccurred(error) {
-            downloadDialog.close();
+        function onDownloadProgressChanged(bytesRead, totalBytes) {
+            downloadDialog.setDownloadProgress(bytesRead, totalBytes);
         }
 
         function onUpdateDownloadFinished() {
diff --git a/src/app/updatemanager.cpp b/src/app/updatemanager.cpp
index 180cd2b3f..ca300d336 100644
--- a/src/app/updatemanager.cpp
+++ b/src/app/updatemanager.cpp
@@ -95,12 +95,12 @@ struct UpdateManager::Impl : public QObject
                 &NetworkManager::errorOccured,
                 &parent_,
                 &UpdateManager::updateErrorOccurred);
-        connect(&parent_, &UpdateManager::statusChanged, this, [this](GetStatus status) {
+        connect(&parent_, &UpdateManager::statusChanged, this, [this](Status status) {
             switch (status) {
-            case GetStatus::STARTED:
+            case Status::STARTED:
                 Q_EMIT parent_.updateDownloadStarted();
                 break;
-            case GetStatus::FINISHED:
+            case Status::FINISHED:
                 Q_EMIT parent_.updateDownloadFinished();
                 break;
             default:
@@ -116,14 +116,15 @@ struct UpdateManager::Impl : public QObject
             [this, downloadUrl](bool success, const QString& errorMessage) {
                 Q_UNUSED(success)
                 Q_UNUSED(errorMessage)
-                lrcInstance_->finish();
-                Q_EMIT lrcInstance_->quitEngineRequested();
-                auto args = QString(" /passive /norestart WIXNONUILAUNCH=1");
                 QProcess process;
-                process.start("powershell ",
-                              QStringList() << tempPath_ + "\\" + downloadUrl.fileName() << "/L*V"
-                                            << tempPath_ + "\\jami_x64_install.log" + args);
-                process.waitForFinished();
+                auto basePath = tempPath_ + QDir::separator();
+                auto msiPath = QDir::toNativeSeparators(basePath + downloadUrl.fileName());
+                auto logPath = QDir::toNativeSeparators(basePath + "jami_x64_install.log");
+                process.startDetached("msiexec",
+                                      QStringList() << "/i" << msiPath << "/passive"
+                                                    << "/norestart"
+                                                    << "WIXNONUILAUNCH=1"
+                                                    << "/L*V" << logPath);
             },
             tempPath_);
     };
@@ -313,10 +314,10 @@ UpdateManager::downloadFile(const QUrl& url,
             resetDownload();
         }
         onDoneCallback(success, errorMessage);
-        Q_EMIT statusChanged(GetStatus::FINISHED);
+        Q_EMIT statusChanged(Status::FINISHED);
     });
 
-    Q_EMIT statusChanged(GetStatus::STARTED);
+    Q_EMIT statusChanged(Status::STARTED);
 }
 
 void
diff --git a/src/app/updatemanager.h b/src/app/updatemanager.h
index c28fe75a9..373c97fce 100644
--- a/src/app/updatemanager.h
+++ b/src/app/updatemanager.h
@@ -36,8 +36,8 @@ public:
                            QObject* parent = nullptr);
     ~UpdateManager();
 
-    enum GetStatus { STARTED, FINISHED };
-    Q_ENUM(GetStatus)
+    enum Status { STARTED, FINISHED };
+    Q_ENUM(Status)
 
     Q_INVOKABLE void checkForUpdates(bool quiet = false);
     Q_INVOKABLE void applyUpdates(bool beta = false);
@@ -53,7 +53,7 @@ public:
                       const QString& filePath);
 
 Q_SIGNALS:
-    void statusChanged(GetStatus status);
+    void statusChanged(UpdateManager::Status status);
     void downloadProgressChanged(qint64 bytesRead, qint64 totalBytes);
 
     void updateCheckReplyReceived(bool ok, bool found = false);
-- 
GitLab