From 57613cc2a4e2e0d3c5fd3ee6ae0541b8fccf1d1e Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 14 Feb 2026 12:04:05 +0100 Subject: [PATCH] fix: check for portable updater before running it (#6801) Reviewed-by: pajlada --- CHANGELOG.md | 1 + src/singletons/Updates.cpp | 25 +++++++++++++++++++++---- src/singletons/Updates.hpp | 4 ++++ src/widgets/dialogs/UpdateDialog.cpp | 12 ++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd50e17..eff5d4c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ - Bugfix: Disable "Sort Tabs Alphabetically" action when notebook layout is locked. (#6710) - Bugfix: Fix highlight mentions not updating when username changes. (#6723, #6739) - Bugfix: Fixed Return and Enter being treated as different keys on Mac OS. (#6726) +- Bugfix: Fixed portable updates not showing an error if the updater is not present. (#6801) - Dev: Nightly builds are now defined through a build flag rather than the Modes file. (#6798) - Dev: Update release documentation. (#6498) - Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493) diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index 1e1ed760..b7e33f96 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -198,10 +198,19 @@ void Updates::installUpdates() file.flush(); file.close(); - QProcess::startDetached( - combinePath(QCoreApplication::applicationDirPath(), - "updater.1/ChatterinoUpdater.exe"), - {filename, "restart"}); + auto updaterPath = Updates::portableUpdaterPath(); + if (!QFile::exists(updaterPath)) + { + this->setStatus_(MissingPortableUpdater); + return; + } + bool ok = + QProcess::startDetached(updaterPath, {filename, "restart"}); + if (!ok) + { + this->setStatus_(RunUpdaterFailed); + return; + } QApplication::exit(0); }) @@ -399,6 +408,12 @@ Updates::Status Updates::getStatus() const return this->status_; } +QString Updates::portableUpdaterPath() +{ + return combinePath(QCoreApplication::applicationDirPath(), + "updater.1/ChatterinoUpdater.exe"); +} + bool Updates::shouldShowUpdateButton() const { switch (this->getStatus()) @@ -422,6 +437,8 @@ bool Updates::isError() const case SearchFailed: case DownloadFailed: case WriteFileFailed: + case MissingPortableUpdater: + case RunUpdaterFailed: return true; default: diff --git a/src/singletons/Updates.hpp b/src/singletons/Updates.hpp index e5d46940..1138e7e6 100644 --- a/src/singletons/Updates.hpp +++ b/src/singletons/Updates.hpp @@ -36,6 +36,8 @@ public: Downloading, DownloadFailed, WriteFileFailed, + MissingPortableUpdater, + RunUpdaterFailed, }; static bool isDowngradeOf(const QString &online, const QString ¤t); @@ -51,6 +53,8 @@ public: void installUpdates(); Status getStatus() const; + static QString portableUpdaterPath(); + bool shouldShowUpdateButton() const; bool isError() const; bool isDowngrade() const; diff --git a/src/widgets/dialogs/UpdateDialog.cpp b/src/widgets/dialogs/UpdateDialog.cpp index 1d871600..d4d0906e 100644 --- a/src/widgets/dialogs/UpdateDialog.cpp +++ b/src/widgets/dialogs/UpdateDialog.cpp @@ -97,6 +97,18 @@ void UpdateDialog::updateStatusChanged(Updates::Status status) } break; + case Updates::MissingPortableUpdater: { + this->ui_.label->setText("The portable updater (expected in " % + Updates::portableUpdaterPath() % + ") was not found."); + } + break; + + case Updates::RunUpdaterFailed: { + this->ui_.label->setText("Failed to run the updater."); + } + break; + default:; } }