diff --git a/CMakeLists.txt b/CMakeLists.txt index 851000f..cbcd7dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,9 +139,16 @@ else() list(APPEND HEADERS src/core/caps_lock_voice_hotkey.h src/core/wayland_text_injector.h) add_compile_definitions(PLATFORM_LINUX) endif() -add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} - src/ui/resources/styles/styles.qrc -) +# Windows 使用 WIN32 标志隐藏启动控制台 +if(WIN32) + add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} + src/ui/resources/styles/styles.qrc + ) +else() + add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} + src/ui/resources/styles/styles.qrc + ) +endif() target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src diff --git a/src/ui/main_window.cpp b/src/ui/main_window.cpp index c0ed8fb..ad0f94c 100644 --- a/src/ui/main_window.cpp +++ b/src/ui/main_window.cpp @@ -194,9 +194,10 @@ void MainWindow::loadStyleSheet() { } void MainWindow::closeEvent(QCloseEvent* event) { - LOG_INFO(kTag, "主窗口关闭"); - doExit(); - QMainWindow::closeEvent(event); + // 关闭按钮隐藏到托盘,不退出程序 + LOG_INFO(kTag, "主窗口隐藏到托盘"); + hide(); + event->ignore(); } void MainWindow::doExit() {