From b90927915f8baadf4a152a0dec6848df4b46e816 Mon Sep 17 00:00:00 2001 From: Jokul Date: Sat, 18 Jul 2026 11:32:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DQML=E4=B8=8D=E8=AF=86?= =?UTF-8?q?=E5=88=ABqint64=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将Q_PROPERTY类型从qint64改为double - 将QML属性类型从qint64改为real - 修复插件无法加载的问题 --- AGENTS.md | 78 ++++++++++++++++++++++++++++++++++++++++ networkmonitorapplet.cpp | 16 ++++----- networkmonitorapplet.h | 16 ++++----- package/networkview.qml | 8 ++--- 4 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..69338ea --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,78 @@ +# AGENTS.md + +Guidance for AI agents working in this repo. Verified against `CMakeLists.txt`, +`package/metadata.json`, and the installed macro file at +`/usr/lib/x86_64-linux-gnu/cmake/DDEShell/DDEShellPackageMacros.cmake`. + +## What this is + +A **pure-QML dde-shell applet** (deepin desktop shell panel widget). There is no +C++ and no `.so` plugin — the entire applet is `package/main.qml` + +`package/metadata.json`, installed as a data package via dde-shell's CMake macros. + +- Applet ID: `space.jokul.JNetApplet`. +- Root element of `main.qml` must be `AppletItem` from `import org.deepin.ds 1.0`. + +## Build & install + +Requires the `DDEShell` CMake package (from the `dde-shell` dev package) at configure +time. Standard flow: + +```sh +cmake -B build +cmake --build build +sudo cmake --install build # -> /usr/share/dde-shell/space.jokul.JNetApplet/ +``` + +`cmake --install` needs `sudo` because the default `DDE_SHELL_PACKAGE_INSTALL_DIR` +is `/usr/share/dde-shell` (a CMake CACHE variable on this system). For a user-local +install instead: + +```sh +cmake -B build -DCMAKE_INSTALL_PREFIX=$HOME/.local +cmake --build build && cmake --install build # -> ~/.local/share/dde-shell/space.jokul.JNetApplet/ +``` + +There is no test, lint, typecheck, or CI target. Verification is manual: install, +then restart `dde-shell` (it discovers applets by scanning the install dir for +`metadata.json`). The build also stages a copy at `build/packages/space.jokul.JNetApplet/` +for previewing the QML without installing. + +## Identifier correspondence (keep in sync when renaming) + +| Where | Field | Value | +|---|---|---| +| `CMakeLists.txt` | `ds_install_package(PACKAGE …)` | `space.jokul.JNetApplet` | +| `package/metadata.json` | `Plugin.Id` | `space.jokul.JNetApplet` | + +The CMake `PACKAGE` becomes the install subdirectory name; `Plugin.Id` is the runtime +identifier. They don't technically have to match, but every official dde-shell applet +keeps them identical — treat them as required to match. + +`Plugin.Url` (`main.qml`) is a path **relative to `package/`**, not an identifier. +Keep it pointing at the entry QML. + +## Required metadata fields (QML applet) + +`metadata.json` must contain `Plugin.Version`, `Plugin.Id`, and `Plugin.Url`. The +current file is complete — don't drop any. (`Plugin.Url` is omitted only for +widget-based, non-QML plugins.) + +## Package layout is fixed by the macro + +`ds_install_package` reads `package/` relative to `CMAKE_CURRENT_SOURCE_DIR` by +default (overridable via `PACKAGE_ROOT_DIR`, not used here). Keep the directory named +`package/` with `metadata.json` at its root. + +## Adding translations (not yet set up) + +If i18n is needed, use the `ds_handle_package(PACKAGE )` macro from the same +DDEShell package. It expects `.ts` files at `translations/_.ts` and +installs compiled `.qm` to `${DDE_SHELL_TRANSLATION_INSTALL_DIR}//translations/`. +Do not invent a different translation workflow. + +## Conventions + +- QML files carry SPDX headers (`SPDX-FileCopyrightText` + + `SPDX-License-Identifier: LGPL-3.0-or-later`). Preserve on new/edited QML files. +- Default branch is `master` (not `main`). diff --git a/networkmonitorapplet.cpp b/networkmonitorapplet.cpp index fb6fb29..410d3ca 100644 --- a/networkmonitorapplet.cpp +++ b/networkmonitorapplet.cpp @@ -51,24 +51,24 @@ bool NetworkMonitorApplet::init() return DApplet::init(); } -qint64 NetworkMonitorApplet::downloadSpeed() const +double NetworkMonitorApplet::downloadSpeed() const { - return m_downloadSpeed; + return static_cast(m_downloadSpeed); } -qint64 NetworkMonitorApplet::uploadSpeed() const +double NetworkMonitorApplet::uploadSpeed() const { - return m_uploadSpeed; + return static_cast(m_uploadSpeed); } -qint64 NetworkMonitorApplet::totalDownload() const +double NetworkMonitorApplet::totalDownload() const { - return m_totalDownload; + return static_cast(m_totalDownload); } -qint64 NetworkMonitorApplet::totalUpload() const +double NetworkMonitorApplet::totalUpload() const { - return m_totalUpload; + return static_cast(m_totalUpload); } QStringList NetworkMonitorApplet::networkInterfaces() const diff --git a/networkmonitorapplet.h b/networkmonitorapplet.h index 86cf0fa..975dea1 100644 --- a/networkmonitorapplet.h +++ b/networkmonitorapplet.h @@ -30,10 +30,10 @@ class NetworkMonitorApplet : public DApplet { Q_OBJECT - Q_PROPERTY(qint64 downloadSpeed READ downloadSpeed NOTIFY speedChanged) - Q_PROPERTY(qint64 uploadSpeed READ uploadSpeed NOTIFY speedChanged) - Q_PROPERTY(qint64 totalDownload READ totalDownload NOTIFY totalChanged) - Q_PROPERTY(qint64 totalUpload READ totalUpload NOTIFY totalChanged) + Q_PROPERTY(double downloadSpeed READ downloadSpeed NOTIFY speedChanged) + Q_PROPERTY(double uploadSpeed READ uploadSpeed NOTIFY speedChanged) + Q_PROPERTY(double totalDownload READ totalDownload NOTIFY totalChanged) + Q_PROPERTY(double totalUpload READ totalUpload NOTIFY totalChanged) Q_PROPERTY(QStringList networkInterfaces READ networkInterfaces NOTIFY interfacesChanged) Q_PROPERTY(QStringList interfaceStats READ interfaceStats NOTIFY statsChanged) Q_PROPERTY(bool ready READ ready NOTIFY readyChanged) @@ -46,10 +46,10 @@ public: virtual bool load() override; virtual bool init() override; - qint64 downloadSpeed() const; - qint64 uploadSpeed() const; - qint64 totalDownload() const; - qint64 totalUpload() const; + double downloadSpeed() const; + double uploadSpeed() const; + double totalDownload() const; + double totalUpload() const; QStringList networkInterfaces() const; QStringList interfaceStats() const; bool ready() const; diff --git a/package/networkview.qml b/package/networkview.qml index 76767d3..e29f734 100644 --- a/package/networkview.qml +++ b/package/networkview.qml @@ -21,10 +21,10 @@ AppletItem { readonly property var applet: Applet readonly property bool ready: applet ? applet.ready : false - readonly property qint64 downloadSpeed: applet ? applet.downloadSpeed : 0 - readonly property qint64 uploadSpeed: applet ? applet.uploadSpeed : 0 - readonly property qint64 totalDownload: applet ? applet.totalDownload : 0 - readonly property qint64 totalUpload: applet ? applet.totalUpload : 0 + readonly property real downloadSpeed: applet ? applet.downloadSpeed : 0 + readonly property real uploadSpeed: applet ? applet.uploadSpeed : 0 + readonly property real totalDownload: applet ? applet.totalDownload : 0 + readonly property real totalUpload: applet ? applet.totalUpload : 0 readonly property string activeInterface: applet ? (applet.activeInterface || "") : "" readonly property var networkInterfaces: applet ? (applet.networkInterfaces || []) : [] readonly property var interfaceStats: applet ? (applet.interfaceStats || []) : []