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/4] 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/4] 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); From 2ab3ce2057b90ec37a77e14c6f5ca8a3f5f1b467 Mon Sep 17 00:00:00 2001 From: Alaskra <958328065@qq.com> Date: Fri, 17 Jun 2022 20:53:00 +0800 Subject: [PATCH 3/4] another way to fix launchapp crash --- src/core/flameshot.cpp | 14 ++++++++------ src/core/flameshot.h | 2 ++ src/widgets/capture/capturewidget.cpp | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index 8332466046..a92fae020f 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -39,6 +39,7 @@ Flameshot::Flameshot() : m_captureWindow(nullptr) + , m_have_external_widgets(false) #if defined(Q_OS_MACOS) , m_HotkeyScreenshotCapture(nullptr) , m_HotkeyScreenshotHistory(nullptr) @@ -416,12 +417,13 @@ 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(); + if (!m_have_external_widgets) + qApp->quit(); +} + +void Flameshot::setExternalWidgets() +{ + m_have_external_widgets = true; } // STATIC ATTRIBUTES diff --git a/src/core/flameshot.h b/src/core/flameshot.h index c738a73730..02f6cf30b6 100644 --- a/src/core/flameshot.h +++ b/src/core/flameshot.h @@ -47,6 +47,7 @@ public slots: public: static void setOrigin(Origin origin); static Origin origin(); + void setExternalWidgets(); signals: void captureTaken(QPixmap p); @@ -59,6 +60,7 @@ public slots: private: Flameshot(); bool resolveAnyConfigErrors(); + bool m_have_external_widgets; // class members static Origin m_origin; diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 8dfbe03eeb..42d56cf0e2 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -1205,6 +1205,7 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r) w->setAttribute(Qt::WA_DeleteOnClose); w->activateWindow(); w->show(); + Flameshot::instance()->setExternalWidgets(); } break; case CaptureTool::REQ_INCREASE_TOOL_SIZE: From 7775cfd0627567c2643a306d9d68f673dfc1d19e Mon Sep 17 00:00:00 2001 From: Alaskra <958328065@qq.com> Date: Fri, 17 Jun 2022 21:18:36 +0800 Subject: [PATCH 4/4] format --- src/core/flameshot.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index 7d9c9b0afe..cdc2c4d0d8 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -419,7 +419,6 @@ void Flameshot::exportCapture(QPixmap capture, void Flameshot::setExternalWidgets() { m_have_external_widgets = true; - } // STATIC ATTRIBUTES