From 5c8a2b25bb200641bba2e3976662229069a9232a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Thu, 23 Dec 2021 22:07:24 +0100 Subject: [PATCH] Fix daemon persist bug and document instance() (#2185) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Haris Gušić --- src/core/flameshotdaemon.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/flameshotdaemon.cpp b/src/core/flameshotdaemon.cpp index 47f38dfc..7099e443 100644 --- a/src/core/flameshotdaemon.cpp +++ b/src/core/flameshotdaemon.cpp @@ -142,6 +142,18 @@ bool FlameshotDaemon::isThisInstanceHostingWidgets() return instance() && !instance()->m_widgets.isEmpty(); } +/** + * @brief Return the daemon instance. + * + * If this instance of flameshot is the daemon, a singleton instance of + * `FlameshotDaemon` is returned. As a side effect`start` will called if it + * wasn't called earlier. If this instance of flameshot is not the daemon, + * `nullptr` is returned. + * + * This strategy is used because the daemon needs to receive signals from D-Bus, + * for which an instance of a `QObject` is required. The singleton serves as + * that object. + */ FlameshotDaemon* FlameshotDaemon::instance() { // Because we don't use DBus on MacOS, each instance of flameshot is its own @@ -159,7 +171,7 @@ FlameshotDaemon* FlameshotDaemon::instance() */ void FlameshotDaemon::quitIfIdle() { - if (m_persist && !instance()) { + if (m_persist) { return; } if (!m_hostingClipboard && m_widgets.isEmpty()) {