diff --git a/src/modules/dock/dock.cpp b/src/modules/dock/dock.cpp index 91a2ca3..636b458 100644 --- a/src/modules/dock/dock.cpp +++ b/src/modules/dock/dock.cpp @@ -187,7 +187,7 @@ bool Dock::dockEntry(Entry *entry, bool moveToEnd) if (moveToEnd && SETTING->getDisplayMode() == DisplayMode::Fashion) m_entries->moveEntryToLast(entry); - entry->setPropIsDocked(true); + entry->setIsDocked(true); entry->updateMenu(); entry->updateMode(); return true; @@ -255,7 +255,7 @@ void Dock::undockEntry(Entry *entry, bool moveToEnd) m_entries->moveEntryToLast(entry); entry->updateIcon(); - entry->setPropIsDocked(false); + entry->setIsDocked(false); entry->updateName(); entry->updateMenu(); } else { @@ -528,20 +528,15 @@ bool Dock::requestDock(QString desktopFile, int index) return false; } - bool newCreated = false; Entry *entry = m_entries->getByInnerId(app->getInnerId()); - if (!entry) { - newCreated = true; + if (!entry) entry = new Entry(this, app, app->getInnerId()); - } if (!dockEntry(entry)) return false; - if (newCreated) { - entry->startExport(); - m_entries->append(entry); - } + entry->startExport(); + m_entries->append(entry); saveDockedApps(); return true; diff --git a/src/modules/dock/entries.cpp b/src/modules/dock/entries.cpp index 29a5e84..65de055 100644 --- a/src/modules/dock/entries.cpp +++ b/src/modules/dock/entries.cpp @@ -52,6 +52,10 @@ Entry *Entries::getByInnerId(QString innerId) void Entries::append(Entry *entry) { + // 如果当前应用在列表中存在(通常是该应用为最近打开应用但是关闭了最近打开应用的接口或者当前为高效模式) + if (m_items.contains(entry)) + m_items.removeOne(entry); + insert(entry, -1); } @@ -276,10 +280,10 @@ void Entries::removeLastRecent() if (unDockCount >= MAX_UNOPEN_RECENT_COUNT && unDockEntrys.size() > 0) { // 只有当最近使用区域的图标大于等于某个数值(3)的时候,并且存在没有子窗口的Entry,那么就移除该Entry Entry *entry = unDockEntrys[0]; - m_items.removeOne(entry); removeEntrys << entry; } for (Entry *entry : removeEntrys) { + m_items.removeOne(entry); removeCb(entry); delete entry; } diff --git a/src/modules/dock/entry.cpp b/src/modules/dock/entry.cpp index 5a392da..9bb0185 100644 --- a/src/modules/dock/entry.cpp +++ b/src/modules/dock/entry.cpp @@ -40,6 +40,7 @@ Entry::Entry(Dock *_dock, AppInfo *_app, QString _innerId, QObject *parent) , m_isActive(false) , m_isDocked(false) , m_innerId(_innerId) + , m_adapterEntry(nullptr) , m_current(nullptr) , m_currentWindow(0) , m_winIconPreferred(false) @@ -210,7 +211,12 @@ void Entry::startExport() return; } - new DBusAdaptorEntry(this); // export dbus by Adaptor + if (m_adapterEntry) { + qWarning() << "service " << getName() << " is running"; + return; + } + + m_adapterEntry = new DBusAdaptorEntry(this); // export dbus by Adaptor QDBusConnection con = QDBusConnection::sessionBus(); if (!con.registerService(dbusService)) { qWarning() << "register service Dock1 error:" << con.lastError().message(); @@ -230,8 +236,16 @@ void Entry::stopExport() return; } + if (!m_adapterEntry) { + qWarning() << "serice " << getName() << "is not running"; + return; + } + QDBusConnection con = QDBusConnection::sessionBus(); con.unregisterObject(path()); + + m_adapterEntry->deleteLater(); + m_adapterEntry = nullptr; } void Entry::setMenu(AppMenu *_menu) @@ -348,14 +362,6 @@ WindowInfoBase *Entry::getWindowInfoByWinId(XWindow windowId) return nullptr; } -void Entry::setPropIsDocked(bool docked) -{ - if (m_isDocked != docked) { - m_isDocked = docked; - Q_EMIT isDockedChanged(docked); - } -} - void Entry::setPropIcon(QString value) { if (value != m_icon) { diff --git a/src/modules/dock/entry.h b/src/modules/dock/entry.h index 275f41c..93958cf 100644 --- a/src/modules/dock/entry.h +++ b/src/modules/dock/entry.h @@ -37,6 +37,8 @@ // 单个应用类 class Dock; +class DBusAdaptorEntry; + class Entry: public QObject { Q_OBJECT @@ -67,7 +69,6 @@ public: void updateIsActive(); WindowInfoBase *getWindowInfoByPid(int pid); WindowInfoBase *getWindowInfoByWinId(XWindow windowId); - void setPropIsDocked(bool docked); void setPropIcon(QString value); void setPropName(QString value); void setPropIsActive(bool active); @@ -145,6 +146,8 @@ private: QString m_innerId; QString m_desktopFile; + DBusAdaptorEntry *m_adapterEntry; + // Dbus属性直接放到interface上 QMap m_windowInfoMap; // 该应用所有窗口 WindowInfoMap m_exportWindowInfos; // 该应用导出的窗口属性