mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
fix tray context menu race condition
This commit is contained in:
parent
87c64c04e8
commit
4ad92254c3
@ -7,7 +7,10 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
||||
|
||||
if(NOT WIN32)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
||||
endif()
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Widgets Network Svg LinguistTools QuickControls2)
|
||||
|
||||
|
||||
@ -239,11 +239,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
this->refresh_groups();
|
||||
|
||||
// Setup Tray
|
||||
tray = new QSystemTrayIcon(this); // 初始化托盘对象tray
|
||||
tray = new QSystemTrayIcon(this);
|
||||
tray->setIcon(Icon::GetTrayIcon(Icon::NONE));
|
||||
tray->setContextMenu(ui->menu_program); // 创建托盘菜单
|
||||
tray->show(); // 让托盘图标显示在系统托盘上
|
||||
tray->show();
|
||||
connect(tray, &QSystemTrayIcon::activated, this, [=](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Context)
|
||||
{
|
||||
QTimer::singleShot(100, this, [=]
|
||||
{
|
||||
ui->menu_program->popup(QCursor::pos());
|
||||
});
|
||||
}
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
if (this->isVisible()) {
|
||||
hide();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user