mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-18 20:50:09 +08:00
feat: auto hide/show dock icon on MacOS
This commit is contained in:
parent
312d6d3a27
commit
b0a6b23fdc
@ -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<void()> &callback, bool wait = false);
|
||||
|
||||
@ -21,6 +21,9 @@
|
||||
#ifdef Q_OS_WIN
|
||||
#include "include/sys/windows/guihelper.h"
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#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<void()> &callback, bool wait) {
|
||||
// any thread
|
||||
auto *timer = new QTimer();
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user