Skip to content

Commit e026117

Browse files
committed
Qt: Make auto updater window-modal
1 parent 1ba3efa commit e026117

File tree

10 files changed

+78
-90
lines changed

10 files changed

+78
-90
lines changed

src/duckstation-qt/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ set(SRCS
2121
audiosettingswidget.h
2222
audiosettingswidget.ui
2323
audiostretchsettingsdialog.ui
24-
autoupdaterwindow.cpp
25-
autoupdaterwindow.h
26-
autoupdaterwindow.ui
24+
autoupdaterdialog.cpp
25+
autoupdaterdialog.h
26+
autoupdaterdialog.ui
2727
biossettingswidget.cpp
2828
biossettingswidget.h
2929
biossettingswidget.ui

src/duckstation-qt/autoupdaterwindow.cpp renamed to src/duckstation-qt/autoupdaterdialog.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
22
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
33

4-
#include "autoupdaterwindow.h"
4+
#include "autoupdaterdialog.h"
55
#include "mainwindow.h"
66
#include "qthost.h"
77
#include "qtprogresscallback.h"
@@ -36,7 +36,7 @@
3636
#include <QtWidgets/QProgressDialog>
3737
#include <QtWidgets/QPushButton>
3838

39-
#include "moc_autoupdaterwindow.cpp"
39+
#include "moc_autoupdaterdialog.cpp"
4040

4141
// Interval at which HTTP requests are polled.
4242
static constexpr u32 HTTP_POLL_INTERVAL = 10;
@@ -105,7 +105,7 @@ static constexpr const std::pair<const char*, const char*> s_update_channels[] =
105105

106106
LOG_CHANNEL(Host);
107107

108-
AutoUpdaterWindow::AutoUpdaterWindow(Error* const error) : QWidget()
108+
AutoUpdaterDialog::AutoUpdaterDialog(QWidget* const parent, Error* const error) : QDialog(parent)
109109
{
110110
m_ui.setupUi(this);
111111
QFont title_font(m_ui.titleLabel->font());
@@ -115,21 +115,21 @@ AutoUpdaterWindow::AutoUpdaterWindow(Error* const error) : QWidget()
115115
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
116116
setDownloadSectionVisibility(false);
117117

118-
connect(m_ui.downloadAndInstall, &QPushButton::clicked, this, &AutoUpdaterWindow::downloadUpdateClicked);
119-
connect(m_ui.skipThisUpdate, &QPushButton::clicked, this, &AutoUpdaterWindow::skipThisUpdateClicked);
120-
connect(m_ui.remindMeLater, &QPushButton::clicked, this, &AutoUpdaterWindow::remindMeLaterClicked);
118+
connect(m_ui.downloadAndInstall, &QPushButton::clicked, this, &AutoUpdaterDialog::downloadUpdateClicked);
119+
connect(m_ui.skipThisUpdate, &QPushButton::clicked, this, &AutoUpdaterDialog::skipThisUpdateClicked);
120+
connect(m_ui.remindMeLater, &QPushButton::clicked, this, &AutoUpdaterDialog::remindMeLaterClicked);
121121

122122
m_http = HTTPDownloader::Create(Host::GetHTTPUserAgent(), error);
123123

124124
m_http_poll_timer = new QTimer(this);
125-
m_http_poll_timer->connect(m_http_poll_timer, &QTimer::timeout, this, &AutoUpdaterWindow::httpPollTimerPoll);
125+
m_http_poll_timer->connect(m_http_poll_timer, &QTimer::timeout, this, &AutoUpdaterDialog::httpPollTimerPoll);
126126
}
127127

128-
AutoUpdaterWindow::~AutoUpdaterWindow() = default;
128+
AutoUpdaterDialog::~AutoUpdaterDialog() = default;
129129

130-
AutoUpdaterWindow* AutoUpdaterWindow::create(Error* const error)
130+
AutoUpdaterDialog* AutoUpdaterDialog::create(QWidget* const parent, Error* const error)
131131
{
132-
AutoUpdaterWindow* const win = new AutoUpdaterWindow(error);
132+
AutoUpdaterDialog* const win = new AutoUpdaterDialog(parent, error);
133133
if (!win->m_http)
134134
{
135135
delete win;
@@ -139,7 +139,7 @@ AutoUpdaterWindow* AutoUpdaterWindow::create(Error* const error)
139139
return win;
140140
}
141141

142-
void AutoUpdaterWindow::warnAboutUnofficialBuild()
142+
void AutoUpdaterDialog::warnAboutUnofficialBuild()
143143
{
144144
//
145145
// To those distributing their own builds or packages of DuckStation, and seeing this message:
@@ -231,7 +231,7 @@ void AutoUpdaterWindow::warnAboutUnofficialBuild()
231231
#endif
232232
}
233233

234-
std::vector<std::pair<QString, QString>> AutoUpdaterWindow::getChannelList()
234+
std::vector<std::pair<QString, QString>> AutoUpdaterDialog::getChannelList()
235235
{
236236
std::vector<std::pair<QString, QString>> ret;
237237
ret.reserve(std::size(s_update_channels));
@@ -240,17 +240,17 @@ std::vector<std::pair<QString, QString>> AutoUpdaterWindow::getChannelList()
240240
return ret;
241241
}
242242

243-
std::string AutoUpdaterWindow::getDefaultTag()
243+
std::string AutoUpdaterDialog::getDefaultTag()
244244
{
245245
return UPDATER_RELEASE_CHANNEL;
246246
}
247247

248-
std::string AutoUpdaterWindow::getCurrentUpdateTag()
248+
std::string AutoUpdaterDialog::getCurrentUpdateTag()
249249
{
250250
return Host::GetBaseStringSettingValue("AutoUpdater", "UpdateTag", UPDATER_RELEASE_CHANNEL);
251251
}
252252

253-
void AutoUpdaterWindow::setDownloadSectionVisibility(bool visible)
253+
void AutoUpdaterDialog::setDownloadSectionVisibility(bool visible)
254254
{
255255
m_ui.downloadProgress->setVisible(visible);
256256
m_ui.downloadStatus->setVisible(visible);
@@ -260,7 +260,7 @@ void AutoUpdaterWindow::setDownloadSectionVisibility(bool visible)
260260
m_ui.remindMeLater->setVisible(!visible);
261261
}
262262

263-
void AutoUpdaterWindow::reportError(const std::string_view msg)
263+
void AutoUpdaterDialog::reportError(const std::string_view msg)
264264
{
265265
// if we're visible, use ourselves.
266266
QWidget* const parent = (isVisible() ? static_cast<QWidget*>(this) : g_main_window);
@@ -274,7 +274,7 @@ void AutoUpdaterWindow::reportError(const std::string_view msg)
274274
msgbox->open();
275275
}
276276

277-
void AutoUpdaterWindow::ensureHttpPollingActive()
277+
void AutoUpdaterDialog::ensureHttpPollingActive()
278278
{
279279
if (m_http_poll_timer->isActive())
280280
return;
@@ -284,7 +284,7 @@ void AutoUpdaterWindow::ensureHttpPollingActive()
284284
m_http_poll_timer->start();
285285
}
286286

287-
void AutoUpdaterWindow::httpPollTimerPoll()
287+
void AutoUpdaterDialog::httpPollTimerPoll()
288288
{
289289
m_http->PollRequests();
290290

@@ -295,7 +295,7 @@ void AutoUpdaterWindow::httpPollTimerPoll()
295295
}
296296
}
297297

298-
void AutoUpdaterWindow::queueUpdateCheck(bool display_errors)
298+
void AutoUpdaterDialog::queueUpdateCheck(bool display_errors)
299299
{
300300
ensureHttpPollingActive();
301301
m_http->CreateRequest(LATEST_TAG_URL,
@@ -305,15 +305,15 @@ void AutoUpdaterWindow::queueUpdateCheck(bool display_errors)
305305
});
306306
}
307307

308-
void AutoUpdaterWindow::queueGetLatestRelease()
308+
void AutoUpdaterDialog::queueGetLatestRelease()
309309
{
310310
ensureHttpPollingActive();
311311
std::string url = fmt::format(LATEST_RELEASE_URL, getCurrentUpdateTag());
312-
m_http->CreateRequest(std::move(url), std::bind(&AutoUpdaterWindow::getLatestReleaseComplete, this,
312+
m_http->CreateRequest(std::move(url), std::bind(&AutoUpdaterDialog::getLatestReleaseComplete, this,
313313
std::placeholders::_1, std::placeholders::_2, std::placeholders::_4));
314314
}
315315

316-
void AutoUpdaterWindow::getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response,
316+
void AutoUpdaterDialog::getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response,
317317
bool display_errors)
318318
{
319319
const std::string selected_tag(getCurrentUpdateTag());
@@ -375,7 +375,7 @@ void AutoUpdaterWindow::getLatestTagComplete(s32 status_code, const Error& error
375375
emit updateCheckCompleted(false);
376376
}
377377

378-
void AutoUpdaterWindow::getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response)
378+
void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response)
379379
{
380380
if (status_code == HTTPDownloader::HTTP_STATUS_OK)
381381
{
@@ -444,15 +444,15 @@ void AutoUpdaterWindow::getLatestReleaseComplete(s32 status_code, const Error& e
444444
emit updateCheckCompleted(false);
445445
}
446446

447-
void AutoUpdaterWindow::queueGetChanges()
447+
void AutoUpdaterDialog::queueGetChanges()
448448
{
449449
ensureHttpPollingActive();
450450
std::string url = fmt::format(CHANGES_URL, g_scm_hash_str, getCurrentUpdateTag());
451-
m_http->CreateRequest(std::move(url), std::bind(&AutoUpdaterWindow::getChangesComplete, this, std::placeholders::_1,
451+
m_http->CreateRequest(std::move(url), std::bind(&AutoUpdaterDialog::getChangesComplete, this, std::placeholders::_1,
452452
std::placeholders::_2, std::placeholders::_4));
453453
}
454454

455-
void AutoUpdaterWindow::getChangesComplete(s32 status_code, const Error& error, std::vector<u8> response)
455+
void AutoUpdaterDialog::getChangesComplete(s32 status_code, const Error& error, std::vector<u8> response)
456456
{
457457
if (status_code == HTTPDownloader::HTTP_STATUS_OK)
458458
{
@@ -521,7 +521,7 @@ void AutoUpdaterWindow::getChangesComplete(s32 status_code, const Error& error,
521521
}
522522
}
523523

524-
void AutoUpdaterWindow::downloadUpdateClicked()
524+
void AutoUpdaterDialog::downloadUpdateClicked()
525525
{
526526
// Prevent multiple clicks of the button.
527527
if (m_download_progress_callback)
@@ -579,7 +579,7 @@ void AutoUpdaterWindow::downloadUpdateClicked()
579579
m_download_progress_callback);
580580
}
581581

582-
bool AutoUpdaterWindow::updateNeeded() const
582+
bool AutoUpdaterDialog::updateNeeded() const
583583
{
584584
QString last_checked_sha = QString::fromStdString(Host::GetBaseStringSettingValue("AutoUpdater", "LastVersion"));
585585

@@ -596,19 +596,19 @@ bool AutoUpdaterWindow::updateNeeded() const
596596
return true;
597597
}
598598

599-
void AutoUpdaterWindow::skipThisUpdateClicked()
599+
void AutoUpdaterDialog::skipThisUpdateClicked()
600600
{
601601
Host::SetBaseStringSettingValue("AutoUpdater", "LastVersion", m_latest_sha.toUtf8().constData());
602602
Host::CommitBaseSettingChanges();
603603
close();
604604
}
605605

606-
void AutoUpdaterWindow::remindMeLaterClicked()
606+
void AutoUpdaterDialog::remindMeLaterClicked()
607607
{
608608
close();
609609
}
610610

611-
void AutoUpdaterWindow::closeEvent(QCloseEvent* event)
611+
void AutoUpdaterDialog::closeEvent(QCloseEvent* event)
612612
{
613613
emit closed();
614614
QWidget::closeEvent(event);
@@ -619,7 +619,7 @@ void AutoUpdaterWindow::closeEvent(QCloseEvent* event)
619619
static constexpr char UPDATER_EXECUTABLE[] = "updater.exe";
620620
static constexpr char UPDATER_ARCHIVE_NAME[] = "update.zip";
621621

622-
bool AutoUpdaterWindow::doesUpdaterNeedElevation(const std::string& application_dir) const
622+
bool AutoUpdaterDialog::doesUpdaterNeedElevation(const std::string& application_dir) const
623623
{
624624
// Try to create a dummy text file in the updater directory. If it fails, we probably won't have write permission.
625625
const std::string dummy_path = Path::Combine(application_dir, "update.txt");
@@ -632,7 +632,7 @@ bool AutoUpdaterWindow::doesUpdaterNeedElevation(const std::string& application_
632632
return false;
633633
}
634634

635-
bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
635+
bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& update_data)
636636
{
637637
const std::string& application_dir = EmuFolders::AppRoot;
638638
const std::string update_zip_path = Path::Combine(EmuFolders::DataRoot, UPDATER_ARCHIVE_NAME);
@@ -669,7 +669,7 @@ bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
669669
return doUpdate(application_dir, update_zip_path, updater_path, program_path);
670670
}
671671

672-
bool AutoUpdaterWindow::extractUpdater(const std::string& zip_path, const std::string& destination_path,
672+
bool AutoUpdaterDialog::extractUpdater(const std::string& zip_path, const std::string& destination_path,
673673
const std::string_view check_for_file, Error* error)
674674
{
675675
unzFile zf = MinizipHelpers::OpenUnzFile(zip_path.c_str());
@@ -747,7 +747,7 @@ bool AutoUpdaterWindow::extractUpdater(const std::string& zip_path, const std::s
747747
return true;
748748
}
749749

750-
bool AutoUpdaterWindow::doUpdate(const std::string& application_dir, const std::string& zip_path,
750+
bool AutoUpdaterDialog::doUpdate(const std::string& application_dir, const std::string& zip_path,
751751
const std::string& updater_path, const std::string& program_path)
752752
{
753753
const std::wstring wupdater_path = StringUtil::UTF8StringToWideString(updater_path);
@@ -774,7 +774,7 @@ bool AutoUpdaterWindow::doUpdate(const std::string& application_dir, const std::
774774
return true;
775775
}
776776

777-
void AutoUpdaterWindow::cleanupAfterUpdate()
777+
void AutoUpdaterDialog::cleanupAfterUpdate()
778778
{
779779
// If we weren't portable, then updater executable gets left in the application directory.
780780
if (EmuFolders::AppRoot == EmuFolders::DataRoot)
@@ -796,7 +796,7 @@ void AutoUpdaterWindow::cleanupAfterUpdate()
796796

797797
#elif defined(__APPLE__)
798798

799-
bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
799+
bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& update_data)
800800
{
801801
std::optional<std::string> bundle_path = CocoaTools::GetNonTranslocatedBundlePath();
802802
if (!bundle_path.has_value())
@@ -857,13 +857,13 @@ bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
857857
return true;
858858
}
859859

860-
void AutoUpdaterWindow::cleanupAfterUpdate()
860+
void AutoUpdaterDialog::cleanupAfterUpdate()
861861
{
862862
}
863863

864864
#elif defined(__linux__)
865865

866-
bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
866+
bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& update_data)
867867
{
868868
const char* appimage_path = std::getenv("APPIMAGE");
869869
if (!appimage_path || !FileSystem::FileExists(appimage_path))
@@ -982,7 +982,7 @@ bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
982982
return true;
983983
}
984984

985-
void AutoUpdaterWindow::cleanupAfterUpdate()
985+
void AutoUpdaterDialog::cleanupAfterUpdate()
986986
{
987987
// Remove old/backup AppImage.
988988
const char* appimage_path = std::getenv("APPIMAGE");
@@ -1001,12 +1001,12 @@ void AutoUpdaterWindow::cleanupAfterUpdate()
10011001

10021002
#else
10031003

1004-
bool AutoUpdaterWindow::processUpdate(const std::vector<u8>& update_data)
1004+
bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& update_data)
10051005
{
10061006
return false;
10071007
}
10081008

1009-
void AutoUpdaterWindow::cleanupAfterUpdate()
1009+
void AutoUpdaterDialog::cleanupAfterUpdate()
10101010
{
10111011
}
10121012

src/duckstation-qt/autoupdaterwindow.h renamed to src/duckstation-qt/autoupdaterdialog.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,29 @@
33

44
#pragma once
55

6-
#include "common/types.h"
6+
#include "ui_autoupdaterdialog.h"
77

8-
#include "ui_autoupdaterwindow.h"
8+
#include "common/types.h"
99

10-
#include <span>
10+
#include <QtCore/QTimer>
1111
#include <string>
1212
#include <string_view>
1313
#include <vector>
1414

15-
#include <QtCore/QDateTime>
16-
#include <QtCore/QStringList>
17-
#include <QtCore/QTimer>
18-
1915
class Error;
2016
class HTTPDownloader;
2117
class QtProgressCallback;
2218

2319
class EmuThread;
2420

25-
class AutoUpdaterWindow final : public QWidget
21+
class AutoUpdaterDialog final : public QDialog
2622
{
2723
Q_OBJECT
2824

2925
public:
30-
~AutoUpdaterWindow();
26+
~AutoUpdaterDialog();
3127

32-
static AutoUpdaterWindow* create(Error* const error);
28+
static AutoUpdaterDialog* create(QWidget* const parent, Error* const error);
3329

3430
void queueUpdateCheck(bool display_errors);
3531
void queueGetLatestRelease();
@@ -53,7 +49,7 @@ class AutoUpdaterWindow final : public QWidget
5349
void closeEvent(QCloseEvent* event) override;
5450

5551
private:
56-
explicit AutoUpdaterWindow(Error* const error);
52+
AutoUpdaterDialog(QWidget* const parent, Error* const error);
5753

5854
void setDownloadSectionVisibility(bool visible);
5955

@@ -65,7 +61,6 @@ class AutoUpdaterWindow final : public QWidget
6561
void skipThisUpdateClicked();
6662
void remindMeLaterClicked();
6763

68-
6964
bool updateNeeded() const;
7065

7166
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response, bool display_errors);
@@ -84,7 +79,7 @@ class AutoUpdaterWindow final : public QWidget
8479
const std::string_view check_for_file, Error* error);
8580
#endif
8681

87-
Ui::AutoUpdaterWindow m_ui;
82+
Ui::AutoUpdaterDialog m_ui;
8883

8984
std::unique_ptr<HTTPDownloader> m_http;
9085
QTimer* m_http_poll_timer = nullptr;

0 commit comments

Comments
 (0)