Skip to content

Commit 8bffd97

Browse files
committed
Qt: Lock system when automatic updater shows
Prevents messyness when launching in fullscreen+big picture.
1 parent e25f287 commit 8bffd97

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

‎src/duckstation-qt/autoupdaterdialog.cpp‎

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,45 @@ void AutoUpdaterDialog::httpPollTimerPoll()
271271
}
272272
}
273273

274-
void AutoUpdaterDialog::queueUpdateCheck(bool display_message)
274+
void AutoUpdaterDialog::lockAndExec()
275275
{
276-
m_display_messages = display_message;
276+
// pause+unfullscreen system. annoyingly, need to reparent if we were fullscreen
277+
MainWindow::SystemLock lock = g_main_window->pauseAndLockSystem();
278+
QWidget* prev_parent = qobject_cast<QWidget*>(parent());
279+
const bool needs_parent_change = (prev_parent && lock.getDialogParent() != prev_parent);
280+
if (needs_parent_change)
281+
{
282+
setParent(lock.getDialogParent());
283+
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
284+
285+
// ensure we're at the front
286+
QTimer::singleShot(20, Qt::TimerType::CoarseTimer, this, SLOT(raise()));
287+
}
288+
289+
const int result = exec();
290+
291+
if (needs_parent_change)
292+
setParent(prev_parent);
293+
294+
// cancel resume if we're exiting anyway
295+
if (result)
296+
lock.cancelResume();
297+
}
277298

299+
void AutoUpdaterDialog::queueUpdateCheck(bool display_errors)
300+
{
278301
#ifdef UPDATE_CHECKER_SUPPORTED
279302
if (!ensureHttpReady())
280303
{
281304
emit updateCheckCompleted();
282305
return;
283306
}
284307

285-
m_http->CreateRequest(LATEST_TAG_URL, std::bind(&AutoUpdaterDialog::getLatestTagComplete, this, std::placeholders::_1,
286-
std::placeholders::_2, std::placeholders::_4));
308+
m_http->CreateRequest(LATEST_TAG_URL,
309+
[this, display_errors](s32 status_code, const Error& error, const std::string& content_type,
310+
std::vector<u8> response) {
311+
getLatestTagComplete(status_code, error, std::move(response), display_errors);
312+
});
287313
#else
288314
emit updateCheckCompleted();
289315
#endif
@@ -304,7 +330,8 @@ void AutoUpdaterDialog::queueGetLatestRelease()
304330
#endif
305331
}
306332

307-
void AutoUpdaterDialog::getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response)
333+
void AutoUpdaterDialog::getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response,
334+
bool display_errors)
308335
{
309336
#ifdef UPDATE_CHECKER_SUPPORTED
310337
const std::string selected_tag(getCurrentUpdateTag());
@@ -337,26 +364,29 @@ void AutoUpdaterDialog::getLatestTagComplete(s32 status_code, const Error& error
337364
}
338365
else
339366
{
340-
if (m_display_messages)
367+
if (display_errors)
368+
{
341369
QMessageBox::information(this, tr("Automatic Updater"),
342370
tr("No updates are currently available. Please try again later."));
371+
}
372+
343373
emit updateCheckCompleted();
344374
return;
345375
}
346376
}
347377

348-
if (m_display_messages)
378+
if (display_errors)
349379
reportError(fmt::format("{} release not found in JSON", selected_tag));
350380
}
351381
else
352382
{
353-
if (m_display_messages)
383+
if (display_errors)
354384
reportError("JSON is not an array");
355385
}
356386
}
357387
else
358388
{
359-
if (m_display_messages)
389+
if (display_errors)
360390
reportError(fmt::format("Failed to download latest tag info: {}", error.GetDescription()));
361391
}
362392

@@ -412,7 +442,7 @@ void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, const Error& e
412442
queueGetChanges();
413443

414444
// We have to defer this, because it comes back through the timer/HTTP callback...
415-
QMetaObject::invokeMethod(this, "exec", Qt::QueuedConnection);
445+
QMetaObject::invokeMethod(this, "lockAndExec", Qt::QueuedConnection);
416446
}
417447
else
418448
{
@@ -522,8 +552,6 @@ void AutoUpdaterDialog::downloadUpdateClicked()
522552
return;
523553
m_ui.downloadAndInstall->setEnabled(false);
524554

525-
m_display_messages = true;
526-
527555
std::optional<bool> download_result;
528556
QtModalProgressCallback progress(this);
529557
progress.SetTitle(tr("Automatic Updater").toUtf8().constData());
@@ -573,7 +601,7 @@ void AutoUpdaterDialog::downloadUpdateClicked()
573601
{
574602
// updater started. since we're a modal on the main window, we have to queue this.
575603
QMetaObject::invokeMethod(g_main_window, "requestExit", Qt::QueuedConnection, Q_ARG(bool, true));
576-
done(0);
604+
done(1);
577605
}
578606
else
579607
{

‎src/duckstation-qt/autoupdaterdialog.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class AutoUpdaterDialog final : public QDialog
4040
void updateCheckCompleted();
4141

4242
public Q_SLOTS:
43-
void queueUpdateCheck(bool display_message);
43+
void queueUpdateCheck(bool display_errors);
4444
void queueGetLatestRelease();
4545

4646
private Q_SLOTS:
4747
void httpPollTimerPoll();
48+
void lockAndExec();
4849

4950
void downloadUpdateClicked();
5051
void skipThisUpdateClicked();
@@ -58,7 +59,7 @@ private Q_SLOTS:
5859
bool updateNeeded() const;
5960
std::string getCurrentUpdateTag() const;
6061

61-
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response);
62+
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response, bool display_errors);
6263
void getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response);
6364

6465
void queueGetChanges();
@@ -80,6 +81,5 @@ private Q_SLOTS:
8081
QString m_download_url;
8182
int m_download_size = 0;
8283

83-
bool m_display_messages = false;
8484
bool m_update_will_break_save_states = false;
8585
};

0 commit comments

Comments
 (0)