diff --git a/include/global/Utils.hpp b/include/global/Utils.hpp index fdaa977..2febd78 100644 --- a/include/global/Utils.hpp +++ b/include/global/Utils.hpp @@ -169,6 +169,8 @@ int MessageBoxInfo(const QString &title, const QString &text); void ActivateWindow(QWidget *w); +void HideWindow(QWidget *w); + // void runOnUiThread(const std::function &callback, bool wait = false); diff --git a/src/global/Utils.cpp b/src/global/Utils.cpp index 468ff83..ee7429e 100644 --- a/src/global/Utils.cpp +++ b/src/global/Utils.cpp @@ -21,6 +21,9 @@ #ifdef Q_OS_WIN #include "include/sys/windows/guihelper.h" #endif +#ifdef Q_OS_MAC +#include +#endif QStringList SplitLines(const QString &_string) { return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts); @@ -257,11 +260,22 @@ void ActivateWindow(QWidget *w) { w->setVisible(true); #ifdef Q_OS_WIN Windows_QWidget_SetForegroundWindow(w); +#elif defined(Q_OS_MAC) + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); #endif w->raise(); w->activateWindow(); } +void HideWindow(QWidget *w) { + w->hide(); +#ifdef Q_OS_MAC + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToUIElementApplication); +#endif +} + void runOnUiThread(const std::function &callback, bool wait) { // any thread auto *timer = new QTimer(); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index c75e90d..d31c311 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -383,7 +383,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->actionStart_with_system->setChecked(AutoRun_IsEnabled()); ui->actionAllow_LAN->setChecked(QStringList{"::", "0.0.0.0"}.contains(Configs::dataStore->inbound_address)); - connect(ui->actionHide_window, &QAction::triggered, this, [=, this](){ this->hide(); }); + connect(ui->actionHide_window, &QAction::triggered, this, [=, this](){ HideWindow(this); }); connect(ui->menu_open_config_folder, &QAction::triggered, this, [=,this] { QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath())); }); connect(ui->menu_add_from_clipboard2, &QAction::triggered, ui->menu_add_from_clipboard, &QAction::trigger); connect(ui->actionRestart_Proxy, &QAction::triggered, this, [=,this] { if (Configs::dataStore->started_id>=0) profile_start(Configs::dataStore->started_id); }); @@ -638,7 +638,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi void MainWindow::closeEvent(QCloseEvent *event) { if (tray->isVisible()) { - hide(); + HideWindow(this); event->ignore(); } else { on_menu_exit_triggered(); @@ -969,7 +969,7 @@ void MainWindow::prepare_exit() mu_exit.unlock(); return; } - hide(); + HideWindow(this); Configs::dataStore->prepare_exit = true; // RegisterHiddenMenuShortcuts(true);