fix unexpected close when launch external app (#2617)

* fix unexpected close when launch external app

* update
This commit is contained in:
Alaskra
2022-06-10 21:46:21 +08:00
committed by GitHub
parent dd9fc45108
commit fb42ad5c25
2 changed files with 10 additions and 2 deletions

View File

@@ -411,6 +411,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

View File

@@ -49,12 +49,14 @@ void requestCaptureAndWait(const CaptureRequest& req)
{
Flameshot* flameshot = Flameshot::instance();
flameshot->requestCapture(req);
QObject::connect(flameshot, &Flameshot::captureTaken, [&](QPixmap) {
// Only useful on MacOS because each instance hosts its own widgets
#if defined(Q_OS_MACOS)
// 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
QObject::connect(flameshot, &Flameshot::captureFailed, []() {
AbstractLogger::info() << "Screenshot aborted.";
qApp->exit(1);