fix issue about externalWidget launchapp (#2698)

This commit is contained in:
Alaskra
2022-06-30 06:59:57 +08:00
committed by GitHub
parent a8c7763d46
commit 44b19a90e1
4 changed files with 22 additions and 9 deletions

View File

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

View File

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

View File

@@ -49,14 +49,19 @@ void requestCaptureAndWait(const CaptureRequest& req)
{
Flameshot* flameshot = Flameshot::instance();
flameshot->requestCapture(req);
#if defined(Q_OS_MACOS)
// Only useful on MacOS because each instance hosts its own widgets
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);
}
});
#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);

View File

@@ -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: