From b9b45580d961c428b67130270a9c0150b5de1f12 Mon Sep 17 00:00:00 2001 From: Alaskra <958328065@qq.com> Date: Sat, 21 May 2022 19:07:53 +0800 Subject: [PATCH 1/2] fix unexpected close when launch external app --- src/core/flameshot.cpp | 6 ++++++ src/main.cpp | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index 196e878932..8332466046 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -416,6 +416,12 @@ void Flameshot::exportCapture(QPixmap capture, if (!(tasks & CR::UPLOAD)) { emit captureTaken(capture); } + // hacks: close a window to trigger qt's quitOnLastWindowClose + // if not create tmp_window and close, the `flameshot gui` won't exit after + // click copy button + QWidget* tmp = new QWidget(); + tmp->show(); + tmp->close(); } // STATIC ATTRIBUTES diff --git a/src/main.cpp b/src/main.cpp index 1d4ddd1b03..37876f0278 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,11 +49,13 @@ void requestCaptureAndWait(const CaptureRequest& req) { Flameshot* flameshot = Flameshot::instance(); flameshot->requestCapture(req); - QObject::connect(flameshot, &Flameshot::captureTaken, [&](QPixmap) { + QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) { +#if defined(Q_OS_MACOS) // Only useful on MacOS because each instance hosts its own widgets if (!FlameshotDaemon::isThisInstanceHostingWidgets()) { qApp->exit(0); } +#endif }); QObject::connect(flameshot, &Flameshot::captureFailed, []() { AbstractLogger::info() << "Screenshot aborted."; From be3505dff0ba315083864636e9f69655f0edb37f Mon Sep 17 00:00:00 2001 From: Alaskra <958328065@qq.com> Date: Fri, 10 Jun 2022 14:11:16 +0800 Subject: [PATCH 2/2] update --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 37876f0278..ee5f1951e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,14 +49,14 @@ void requestCaptureAndWait(const CaptureRequest& req) { Flameshot* flameshot = Flameshot::instance(); flameshot->requestCapture(req); - QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) { #if defined(Q_OS_MACOS) - // Only useful on MacOS because each instance hosts its own widgets + // Only useful on MacOS because each instance hosts its own widgets + QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) { if (!FlameshotDaemon::isThisInstanceHostingWidgets()) { qApp->exit(0); } -#endif }); +#endif QObject::connect(flameshot, &Flameshot::captureFailed, []() { AbstractLogger::info() << "Screenshot aborted."; qApp->exit(1);