]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Updater: fix macOS
authortobtoht <tob@featherwallet.org>
Tue, 14 Mar 2023 14:21:42 +0000 (15:21 +0100)
committertobtoht <tob@featherwallet.org>
Tue, 14 Mar 2023 16:59:17 +0000 (17:59 +0100)
src/CMakeLists.txt
src/MainWindow.cpp
src/dialog/UpdateDialog.cpp

index b73cea6ea83aaf10f47bd2e4884963bcc41b1ec5..0235fb3aa519d5098c4bfe8029344bbb8c995207 100644 (file)
@@ -295,7 +295,7 @@ if(STATIC AND NOT Qt6_FOUND)
     endif()
 endif()
 
-if(STATIC AND UNIX AND Qt6_FOUND)
+if(STATIC AND UNIX AND NOT APPLE AND Qt6_FOUND)
     target_link_libraries(feather Qt6::QComposePlatformInputContextPlugin)
 endif()
 
index 8dc8119c9dbcbd54784ef76116865553bdfd6b8e..64c9dfa729c5a309b6caf5db0871fc371ce6ce11 100644 (file)
@@ -364,9 +364,6 @@ void MainWindow::initMenu() {
 #else
     ui->actionCheckForUpdates->setVisible(false);
 #endif
-#if defined(Q_OS_MACOS)
-    ui->actionCheckForUpdates->setVisible(false);
-#endif
 
     connect(ui->actionOfficialWebsite,   &QAction::triggered, [this](){Utils::externalLinkWarning(this, "https://featherwallet.org");});
     connect(ui->actionDonate_to_Feather, &QAction::triggered, this, &MainWindow::donateButtonClicked);
index 076c1a542a5113f0161a689372bcf572ee0e9ff4..e51bbaea33f2a18adad11c88e50d1e78ef162e38 100644 (file)
@@ -12,6 +12,7 @@
 #include "utils/NetworkManager.h"
 #include "utils/Updater.h"
 #include "utils/Utils.h"
+#include "utils/SemanticVersion.h"
 
 #include "zip.h"
 
@@ -251,17 +252,33 @@ void UpdateDialog::installUpdateMac() {
     QString appPath = Utils::applicationPath();
     QDir appDir(appPath);
     if (appPath.endsWith("Contents/MacOS")) {
-        appDir.cd("../../..");
+        appDir.cd("../..");
     }
+
+    if (appPath.contains("AppTranslocation")) {
+        this->onInstallError("Error: Application is translocated. Please move it to the Applications folder and try again.");
+        return;
+    }
+
+    if (!SemanticVersion::isValid(SemanticVersion::fromString(m_updater->version))) {
+        this->onInstallError(QString("Error: Invalid version: %1").arg(m_updater->version));
+        return;
+    }
+
     QString appName = QString("feather-%1").arg(m_updater->version);
     QString zipName = QString("%1.zip").arg(appName);
-    QString fPath = appDir.filePath(zipName);
 
+    QString downloadsPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+    if (downloadsPath.isEmpty()) {
+        this->onInstallError(QString("Error: Could not determine download location"));
+        return;
+    }
+
+    QString fPath = QString("%1/%2").arg(downloadsPath, zipName);
     QFile file(fPath);
     qDebug() << "Writing zip file to " << fPath;
-    if (!file.open(QIODevice::WriteOnly))
-    {
-        this->onInstallError(QString("Error: Could not write to application path: %1").arg(fPath));
+    if (!file.open(QIODevice::WriteOnly)) {
+        this->onInstallError(QString("Error: Could not write to download location: %1").arg(fPath));
         return;
     }
 
@@ -271,14 +288,20 @@ void UpdateDialog::installUpdateMac() {
     }
 
     QProcess unzip;
-    unzip.start("/usr/bin/unzip", {"-n", fPath, "-d", appDir.path()});
+    unzip.start("/usr/bin/unzip", {"-o", fPath, "-d", appDir.absolutePath()});
     unzip.waitForFinished();
 
-    m_updatePath = QString("%1.app/Contents/MacOS/feather").arg(appDir.filePath(appName));
+    if (unzip.exitStatus() != QProcess::NormalExit) {
+        this->onInstallError(QString("Error: Unable to extract: %1").arg(fPath));
+        return;
+    }
+
+    m_updatePath = QString("%1/Contents/MacOS/feather").arg(appDir.absolutePath());
+    qDebug() << "Update path: " << m_updatePath;
 
     file.remove();
 
-    this->setStatus("Installation successful. Do you want to restart Feather now?");
+    this->setStatus(QString("Installation successful: Do you want to restart Feather now?").arg(m_updatePath));
     ui->btn_restart->show();
 }