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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_subdirectory(frame)
add_subdirectory(shell)
add_subdirectory(example)
add_subdirectory(panels)
add_subdirectory(applets)

configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/misc/DDEShellConfig.cmake.in"
Expand Down
5 changes: 5 additions & 0 deletions applets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

add_subdirectory(dde-am)
15 changes: 15 additions & 0 deletions applets/dde-am/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

add_library(dde-am SHARED
amapplet.cpp
amapplet.h
)

target_link_libraries(dde-am PRIVATE
dde-shell-frame
Qt${QT_MAJOR_VERSION}::DBus
)

ds_install_package(PACKAGE org.deepin.ds.dde-am TARGET dde-am)
88 changes: 88 additions & 0 deletions applets/dde-am/amapplet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "amapplet.h"

#include "pluginfactory.h"

#include <QDBusConnection>
#include <QDBusError>
#include <QDebug>

#include <DConfig>
#include <DUtil>

DCORE_USE_NAMESPACE
DS_BEGIN_NAMESPACE
namespace am {

AMApplet::AMApplet(QObject *parent)
: DApplet(parent)
{
}

AMApplet::~AMApplet()
{
}

bool AMApplet::load()
{
// the signal maybe loss when AM is crashed.
auto conn = QDBusConnection::sessionBus();
bool ret = conn.connect("org.desktopspec.ApplicationManager1",
"/org/desktopspec/ApplicationManager1",
"org.desktopspec.DBus.ObjectManager",
"InterfacesRemoved",
this,
SLOT(onInterfacesRemoved(QDBusObjectPath,QStringList))
);
if (!ret) {
qWarning() << "Failed to connect InterfacesReoved signal for AM" << conn.lastError().message();
return false;
}
return DApplet::load();
}


static QString unescapeAppIdFromObjectPath(const QString &path)
{
if (path.isEmpty()) return {};
const auto startIndex = QString("/org/desktopspec/ApplicationManager1").size();
auto endIndex = path.indexOf("/", startIndex + 1);
const auto id = endIndex <= -1 ? path.mid(startIndex + 1) :
path.sliced(startIndex + 1, endIndex - (startIndex + 1));
return DUtil::unescapeFromObjectPath(id);
}

void AMApplet::onInterfacesRemoved(const QDBusObjectPath &objPath, const QStringList &interfaces)
{
const QString &path(objPath.path());
qDebug() << "InterfacesRemoved by AM, path:" << path;

const QString &appId = unescapeAppIdFromObjectPath(path);
updateAppsLaunchedTimes(appId);
}

void AMApplet::updateAppsLaunchedTimes(const QString &appId)
{
std::unique_ptr<DConfig> config(DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am"));
if (!config->isValid()) {
qWarning() << "DConfig is invalid when updating launched times.";
return;
}

const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
auto value = config->value(AppsLaunchedTimes).toMap();
if (auto iter = value.find(appId); iter != value.end()) {
value.remove(appId);
config->setValue(AppsLaunchedTimes, value);
qDebug() << "Reset launched times for the app:" << appId;
}
}

D_APPLET_CLASS(AMApplet)
}
DS_END_NAMESPACE

#include "amapplet.moc"
30 changes: 30 additions & 0 deletions applets/dde-am/amapplet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "applet.h"

#include <QDBusObjectPath>

DS_BEGIN_NAMESPACE
namespace am {
class AMApplet : public DApplet
{
Q_OBJECT
public:
explicit AMApplet(QObject *parent = nullptr);
~AMApplet();

virtual bool load() override;

private slots:
void onInterfacesRemoved(const QDBusObjectPath &objPath, const QStringList &interfaces);

private:
void updateAppsLaunchedTimes(const QString &appId);
};

}
DS_END_NAMESPACE
7 changes: 7 additions & 0 deletions applets/dde-am/package/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Plugin": {
"Version": "1.0",
"Id": "org.deepin.ds.dde-am",
"Category": "DDE"
}
}