Skip to content

Commit f598b90

Browse files
saturnericCopilot
andcommitted
fix(ui): defer startup wizard until visible
* Triggers the startup wizard after the window is loaded instead of on first show, reducing timing-related focus issues * Skips the startup wizard when the main window is not yet visible to avoid opening it too early * Improves wizard activation by deferring raise/activate and applying a macOS-specific dialog flag for better modality behavior Co-authored-by: Copilot <copilot@github.com>
1 parent c26cb5f commit f598b90

3 files changed

Lines changed: 34 additions & 19 deletions

File tree

src/ui/main_window/MainWindow.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ void MainWindow::Init() noexcept {
167167
connect(m_key_list_, &KeyList::SignalRefreshDatabase, this,
168168
[=]() { slot_update_engine_status(); });
169169

170+
connect(this, &MainWindow::SignalLoaded, this, [this]() {
171+
QTimer::singleShot(100, this,
172+
[self = QPointer<MainWindow>(this)]() -> void {
173+
if (self == nullptr) return;
174+
self->slot_maybe_show_wizard();
175+
});
176+
});
177+
170178
// restore settings and window state
171179
restore_settings();
172180

@@ -175,8 +183,9 @@ void MainWindow::Init() noexcept {
175183
// size.
176184
RestoreSettingsOnce();
177185

186+
// If no previous state is saved, apply a default layout after the event
187+
// loop starts.
178188
const bool state_restored = restoreWindowState();
179-
180189
QTimer::singleShot(0, this, [this, state_restored]() -> void {
181190
if (!state_restored) {
182191
apply_default_layout();
@@ -274,15 +283,6 @@ void MainWindow::closeEvent(QCloseEvent* event) {
274283
GeneralMainWindow::closeEvent(event);
275284
}
276285

277-
void MainWindow::showEvent(QShowEvent* event) {
278-
GeneralMainWindow::showEvent(event);
279-
280-
if (wizard_checked_) return;
281-
wizard_checked_ = true;
282-
283-
QTimer::singleShot(0, this, [this]() -> void { slot_maybe_show_wizard(); });
284-
}
285-
286286
auto MainWindow::create_action(const QString& id, const QString& name,
287287
const QString& icon, const QString& too_tip,
288288
const QContainer<QKeySequence>& shortcuts)

src/ui/main_window/MainWindow.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ class GF_UI_EXPORT MainWindow : public GeneralMainWindow {
139139
*/
140140
void closeEvent(QCloseEvent* event) override;
141141

142-
/**
143-
* @brief
144-
*
145-
* @param event
146-
*/
147-
void showEvent(QShowEvent* event) override;
148-
149142
public slots:
150143

151144
/**
@@ -331,6 +324,10 @@ class GF_UI_EXPORT MainWindow : public GeneralMainWindow {
331324
*/
332325
void slot_find();
333326

327+
/**
328+
* @brief
329+
*
330+
*/
334331
void slot_start_wizard();
335332

336333
/**

src/ui/main_window/MainWindowSlotUI.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,35 @@ void MainWindow::slot_start_wizard() {
4848
auto* wizard = new Wizard(this);
4949
wizard->setAttribute(Qt::WA_DeleteOnClose);
5050
wizard->setWindowModality(Qt::ApplicationModal);
51+
52+
#ifdef Q_OS_MACOS
53+
wizard->setWindowFlag(Qt::Dialog, true);
54+
#endif
55+
5156
wizard->open();
52-
wizard->raise();
53-
wizard->activateWindow();
57+
58+
QTimer::singleShot(0, wizard, [wizard]() {
59+
wizard->raise();
60+
wizard->activateWindow();
61+
});
5462
}
5563

5664
void MainWindow::slot_maybe_show_wizard() {
65+
if (wizard_checked_) {
66+
return;
67+
}
68+
wizard_checked_ = true;
69+
5770
if (!show_wizard_on_startup_) {
5871
LOG_D() << "Wizard on startup is disabled. Skipping wizard.";
5972
return;
6073
}
6174

75+
if (!isVisible()) {
76+
LOG_W() << "Main window is not visible yet. Skipping startup wizard.";
77+
return;
78+
}
79+
6280
slot_start_wizard();
6381
}
6482

0 commit comments

Comments
 (0)