From 6d7d0e4e1d9e5fb39cb9dab942a53a9608b45cea Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 3 Jan 2025 18:57:25 +0800 Subject: [PATCH] chore(macOS): change close-window behavior On macOS, now closing the window will actually hide the window instead of quit the application, thus it will match to some other macOS application's behavior. Additionally, since our binary is not signed, this could avoid seeing the request permission dialogs everytime user attempts to open an image file inside a private place (e.g. places like the "Downloads" folder and "access data from other apps"). --- app/main.cpp | 7 ++++++- app/mainwindow.cpp | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/main.cpp b/app/main.cpp index e940126..a1e442e 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -63,7 +63,12 @@ int main(int argc, char *argv[]) FileOpenEventHandler * fileOpenEventHandler = new FileOpenEventHandler(&a); a.installEventFilter(fileOpenEventHandler); a.connect(fileOpenEventHandler, &FileOpenEventHandler::fileOpen, [&w](const QUrl & url){ - if (w.isHidden()) w.showNormal(); + if (w.isHidden()) { + w.setWindowOpacity(1); + w.showNormal(); + } else { + w.activateWindow(); + } w.showUrls({url}); w.initWindowSize(); }); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index a836d70..9763573 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -71,7 +71,11 @@ MainWindow::MainWindow(QWidget *parent) m_exitAnimationGroup->addAnimation(m_fadeOutAnimation); m_exitAnimationGroup->addAnimation(m_floatUpAnimation); connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished, +#ifdef Q_OS_MAC + this, &QWidget::hide); +#else this, &QWidget::close); +#endif GraphicsScene * scene = new GraphicsScene(this);