Skip to content

Commit

Permalink
Add option --no-window; workaround for Nitrokey#349
Browse files Browse the repository at this point in the history
If the option --no-window is given the MainWindow is closed
immediately after it is shown. I have found no better solution for this.
  • Loading branch information
KaiHa committed Sep 15, 2018
1 parent ea8d907 commit 8133fe6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ int main(int argc, char *argv[]) {
w.set_debug_level(parser.value("debug-level").toInt());
}

if(parser.isSet("no-window")) {
w.hideOnStartup();
}


// csApplet()->setParent(&w);
int retcode = -1;
Expand Down Expand Up @@ -296,6 +300,8 @@ bool configureParser(const QApplication &a, QCommandLineParser &parser) {
"Load translation file with given name "
"and store this choice in settings file."),
"en"},
{"no-window",
QCoreApplication::translate("main", "Display no window.")},
});

parser.process(a);
Expand Down
16 changes: 16 additions & 0 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@ void MainWindow::closeEvent(QCloseEvent *event) {
}
}

void MainWindow::showEvent(QShowEvent *event) {
if (suppress_next_show){
suppress_next_show = false;
#ifdef Q_OS_MAC
QTimer::singleShot(0, this, SLOT(showMinimized()));
#else
QTimer::singleShot(0, this, SLOT(hide()));
#endif
}
}

void MainWindow::hideOnStartup()
{
suppress_next_show = true;
}

void MainWindow::generateComboBoxEntrys() {
//FIXME run in separate thread
int i;
Expand Down
4 changes: 4 additions & 0 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public :

protected:
void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent *event) override;

private:
Q_DISABLE_COPY(MainWindow);
Expand Down Expand Up @@ -221,8 +222,11 @@ private slots:
void set_debug_mode();
void set_debug_level(int debug_level);

void hideOnStartup();

private:
bool debug_mode = false;
bool suppress_next_show = false;

void showNotificationLabel();

Expand Down

0 comments on commit 8133fe6

Please sign in to comment.