mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
fix issue about externalWidget launchapp (#2698)
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
|
||||
Flameshot::Flameshot()
|
||||
: m_captureWindow(nullptr)
|
||||
, m_haveExternalWidget(false)
|
||||
#if defined(Q_OS_MACOS)
|
||||
, m_HotkeyScreenshotCapture(nullptr)
|
||||
, m_HotkeyScreenshotHistory(nullptr)
|
||||
@@ -411,12 +412,15 @@ 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();
|
||||
}
|
||||
|
||||
void Flameshot::setExternalWidget(bool b)
|
||||
{
|
||||
m_haveExternalWidget = b;
|
||||
}
|
||||
bool Flameshot::haveExternalWidget()
|
||||
{
|
||||
return m_haveExternalWidget;
|
||||
}
|
||||
|
||||
// STATIC ATTRIBUTES
|
||||
|
||||
@@ -47,6 +47,8 @@ public slots:
|
||||
public:
|
||||
static void setOrigin(Origin origin);
|
||||
static Origin origin();
|
||||
void setExternalWidget(bool b);
|
||||
bool haveExternalWidget();
|
||||
|
||||
signals:
|
||||
void captureTaken(QPixmap p);
|
||||
@@ -62,6 +64,7 @@ private:
|
||||
|
||||
// class members
|
||||
static Origin m_origin;
|
||||
bool m_haveExternalWidget;
|
||||
|
||||
QPointer<CaptureWidget> m_captureWindow;
|
||||
QPointer<InfoWindow> m_infoWindow;
|
||||
|
||||
@@ -49,14 +49,19 @@ 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
|
||||
QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) {
|
||||
if (!FlameshotDaemon::isThisInstanceHostingWidgets()) {
|
||||
qApp->exit(0);
|
||||
}
|
||||
});
|
||||
#else
|
||||
// if this instance is not daemon, make sure it exit after caputre finish
|
||||
if (FlameshotDaemon::instance() == nullptr && !Flameshot::instance()->haveExternalWidget()) {
|
||||
qApp->exit(0);
|
||||
}
|
||||
#endif
|
||||
});
|
||||
QObject::connect(flameshot, &Flameshot::captureFailed, []() {
|
||||
AbstractLogger::info() << "Screenshot aborted.";
|
||||
qApp->exit(1);
|
||||
|
||||
@@ -1200,6 +1200,7 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r)
|
||||
w->setAttribute(Qt::WA_DeleteOnClose);
|
||||
w->activateWindow();
|
||||
w->show();
|
||||
Flameshot::instance()->setExternalWidget(true);
|
||||
}
|
||||
break;
|
||||
case CaptureTool::REQ_INCREASE_TOOL_SIZE:
|
||||
|
||||
Reference in New Issue
Block a user