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
257bd917e6
commit
fce3cf02be
@ -169,6 +169,8 @@ int MessageBoxInfo(const QString &title, const QString &text);
|
|||||||
|
|
||||||
void ActivateWindow(QWidget *w);
|
void ActivateWindow(QWidget *w);
|
||||||
|
|
||||||
|
void HideWindow(QWidget *w);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
void runOnUiThread(const std::function<void()> &callback, bool wait = false);
|
void runOnUiThread(const std::function<void()> &callback, bool wait = false);
|
||||||
|
|||||||
@ -21,6 +21,9 @@
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include "include/sys/windows/guihelper.h"
|
#include "include/sys/windows/guihelper.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
QStringList SplitLines(const QString &_string) {
|
QStringList SplitLines(const QString &_string) {
|
||||||
return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
|
return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||||
@ -257,11 +260,22 @@ void ActivateWindow(QWidget *w) {
|
|||||||
w->setVisible(true);
|
w->setVisible(true);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
Windows_QWidget_SetForegroundWindow(w);
|
Windows_QWidget_SetForegroundWindow(w);
|
||||||
|
#elif defined(Q_OS_MAC)
|
||||||
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
#endif
|
#endif
|
||||||
w->raise();
|
w->raise();
|
||||||
w->activateWindow();
|
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) {
|
void runOnUiThread(const std::function<void()> &callback, bool wait) {
|
||||||
// any thread
|
// any thread
|
||||||
auto *timer = new QTimer();
|
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->actionStart_with_system->setChecked(AutoRun_IsEnabled());
|
||||||
ui->actionAllow_LAN->setChecked(QStringList{"::", "0.0.0.0"}.contains(Configs::dataStore->inbound_address));
|
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_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->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); });
|
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) {
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||||
if (tray->isVisible()) {
|
if (tray->isVisible()) {
|
||||||
hide();
|
HideWindow(this);
|
||||||
event->ignore();
|
event->ignore();
|
||||||
} else {
|
} else {
|
||||||
on_menu_exit_triggered();
|
on_menu_exit_triggered();
|
||||||
@ -969,7 +969,7 @@ void MainWindow::prepare_exit()
|
|||||||
mu_exit.unlock();
|
mu_exit.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hide();
|
HideWindow(this);
|
||||||
Configs::dataStore->prepare_exit = true;
|
Configs::dataStore->prepare_exit = true;
|
||||||
//
|
//
|
||||||
RegisterHiddenMenuShortcuts(true);
|
RegisterHiddenMenuShortcuts(true);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user