From 374dfc712c85a4888510a911009c3cf11f480857 Mon Sep 17 00:00:00 2001 From: "justforlxz.com" Date: Tue, 2 Jul 2019 11:27:09 +0800 Subject: [PATCH] fix: can run twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dde-daemon针对截图做了特殊处理,可以在grabkeyboard的情况下依旧启动截图, 所以截图的startScreenshot函数被调用了两次,破坏了单例。 --- src/dbusservice/dbusscreenshotservice.cpp | 5 ++++- src/dbusservice/dbusscreenshotservice.h | 2 ++ src/main.cpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dbusservice/dbusscreenshotservice.cpp b/src/dbusservice/dbusscreenshotservice.cpp index 2318eb73..75ea15b6 100644 --- a/src/dbusservice/dbusscreenshotservice.cpp +++ b/src/dbusservice/dbusscreenshotservice.cpp @@ -56,6 +56,10 @@ DBusScreenshotService::~DBusScreenshotService() // destructor } +void DBusScreenshotService::setSingleInstance(bool instance) { + m_singleInstance = instance; +} + void DBusScreenshotService::StartScreenshot() { qDebug() << "DBus screenshot service! start screenshot"; if (!m_singleInstance) @@ -107,4 +111,3 @@ void DBusScreenshotService::SavePathScreenshot(const QString &in0) parent()->savePathScreenshot(in0); m_singleInstance = true; } - diff --git a/src/dbusservice/dbusscreenshotservice.h b/src/dbusservice/dbusscreenshotservice.h index 92c1411c..40c9913e 100644 --- a/src/dbusservice/dbusscreenshotservice.h +++ b/src/dbusservice/dbusscreenshotservice.h @@ -72,6 +72,8 @@ class DBusScreenshotService: public QDBusAbstractAdaptor DBusScreenshotService(Screenshot *parent); ~DBusScreenshotService(); + void setSingleInstance(bool instance); + inline Screenshot *parent() const { return static_cast(QObject::parent()); } diff --git a/src/main.cpp b/src/main.cpp index e9ebf7c6..2ce86586 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,6 +96,7 @@ int main(int argc, char *argv[]) qDebug() << "dbus register waiting!"; return a.exec(); } else { + dbusService.setSingleInstance(true); if (cmdParser.isSet(delayOption)) { qDebug() << "cmd delay screenshot"; w.delayScreenshot(cmdParser.value(delayOption).toInt());