Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dde-shell (0.0.19) unstable; urgency=medium

* feat: remove uos-ai plugin when uos ai uninstalled

-- tsic404 <liuheng@deepin.org> Mon, 13 May 2024 14:09:19 +0800

dde-shell (0.0.18) unstable; urgency=medium

* feat: add tray dci icons(Issue: https://github.com/linuxdeepin/developer-center/issues/8082)
Expand Down
13 changes: 12 additions & 1 deletion panels/dock/tray/plugins/uos-ai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ find_package(Qt6 REQUIRED COMPONENTS Svg DBus Widgets)
find_package(Dtk6Widget REQUIRED)
find_package(Dtk6Gui REQUIRED)

set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/dbus/org.desktopspec.ObjectManager1.xml
PROPERTIES INCLUDE dbus/types/am.h
CLASSNAME ObjectManager
)

qt_add_dbus_interfaces(
DBUS_INTERFACES
${CMAKE_CURRENT_SOURCE_DIR}/dbus/org.desktopspec.ObjectManager1.xml
)

add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} plugin-tray.qrc)
add_library(${PLUGIN_NAME} SHARED ${SRCS} ${DBUS_INTERFACES} plugin-tray.qrc)
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../quick-trays)
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
../../interfaces
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "https://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.desktopspec.DBus.ObjectManager">
<method name="GetManagedObjects">
<arg name="objpath_interfaces_and_properties" type="a{oa{sa{sv}}}" direction="out" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ObjectMap"/>
</method>

<signal name="InterfacesAdded">
<arg name="object_path" type="o" />
<arg name="interfaces_and_properties" type="a{sa{sv}}" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="ObjectInterfaceMap"/>
</signal>

<signal name="InterfacesRemoved">
<arg name="object_path" type="o" />
<arg name="interfaces" type="as" />
</signal>
</interface>
</node>
20 changes: 20 additions & 0 deletions panels/dock/tray/plugins/uos-ai/dbus/types/am.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

// from am global.h
#include <QMap>
#include <QString>
#include <QDBusObjectPath>

using ObjectInterfaceMap = QMap<QString, QVariantMap>;
using ObjectMap = QMap<QDBusObjectPath, ObjectInterfaceMap>;
using QStringMap = QMap<QString, QString>;
using PropMap = QMap<QString, QStringMap>;

Q_DECLARE_METATYPE(ObjectInterfaceMap)
Q_DECLARE_METATYPE(ObjectMap)
Q_DECLARE_METATYPE(QStringMap)
Q_DECLARE_METATYPE(PropMap)
41 changes: 40 additions & 1 deletion panels/dock/tray/plugins/uos-ai/uosaiplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "uosaiplugin.h"
#include "objectmanager1interface.h"

#include <DGuiApplicationHelper>
#include <DApplication>
Expand All @@ -17,6 +18,10 @@ using namespace uos_ai;
#define QUICK_ITEM_KEY QStringLiteral("quick_item_key")
#define PLUGIN_STATE_KEY "enable"

static const QString AM_DBUS_PATH = "org.desktopspec.ApplicationManager1";
static const QString UOS_AI_AM_PATH = "/org/desktopspec/ApplicationManager1/uos_2dai_2dassistant";
static ObjectManager desktopobjectManager(AM_DBUS_PATH, "/org/desktopspec/ApplicationManager1", QDBusConnection::sessionBus());

UosAiPlugin::UosAiPlugin(QObject *parent)
: QObject(parent)
, m_tipsLabel(new QLabel)
Expand All @@ -32,6 +37,40 @@ UosAiPlugin::UosAiPlugin(QObject *parent)
changeTheme();

connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &UosAiPlugin::changeTheme);
const auto reply = desktopobjectManager.GetManagedObjects();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *call){
QDBusPendingReply<ObjectMap> reply = *call;
if (reply.isError()) {
call->deleteLater();
return;
}

const auto objects = reply.value();
for (auto iter = objects.cbegin(); iter != objects.cend(); ++iter) {
const auto &objPath = iter.key();
if (objPath.path() == UOS_AI_AM_PATH) {
m_pluginLoaded = true;
break;
}
}
call->deleteLater();
});
watcher->waitForFinished();

connect(&desktopobjectManager, &ObjectManager::InterfacesRemoved, this, [this] (const QDBusObjectPath& path, const QStringList& interfaces) {
if (path.path() == UOS_AI_AM_PATH) {
m_pluginLoaded = false;
pluginStateSwitched();
}
});

connect(&desktopobjectManager, &ObjectManager::InterfacesAdded, this, [this] (const QDBusObjectPath& path, const ObjectInterfaceMap& info) {
if (path.path() == UOS_AI_AM_PATH) {
m_pluginLoaded = true;
pluginStateSwitched();
}
});
#ifdef USE_DOCK_API_V2
QDBusConnection::sessionBus().connect("com.deepin.copilot", "/com/deepin/copilot", "com.deepin.copilot", "windowVisibleChanged", this, SLOT(onUosAiVisibleChanged(bool)));
QDBusConnection::sessionBus().connect("com.deepin.copilot", "/com/deepin/copilot", "com.deepin.copilot", "windowActiveChanged", this, SLOT(onUosAiVisibleChanged(bool)));
Expand Down Expand Up @@ -139,7 +178,7 @@ void UosAiPlugin::pluginStateSwitched()

bool UosAiPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool();
return !(m_pluginLoaded && m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
}

#ifdef USE_V23_DOCK
Expand Down