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").
This commit is contained in:
Gary Wang 2025-01-03 18:57:25 +08:00
parent ff4f71c1e6
commit 6d7d0e4e1d
2 changed files with 10 additions and 1 deletions

View File

@ -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();
});

View File

@ -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);