feat: 初始化项目骨架
- 创建插件元数据 package/metadata.json - 实现主插件类 GraphicsDriverApplet (D-Bus通信) - 实现GPU指示器类 GpuIndicator (设备信息解析) - 创建QML界面 driverview.qml (驱动管理UI) - 添加CMake构建配置 - 编写开发指南文档 docs/DEVELOPMENT.md
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
# 开发指南
|
||||
|
||||
## 环境准备
|
||||
|
||||
### 1. 克隆dde-shell仓库
|
||||
|
||||
```bash
|
||||
# 克隆dde-shell到本地
|
||||
git clone https://github.com/linuxdeepin/dde-shell.git ~/dde-shell
|
||||
|
||||
# 或者作为子模块引入
|
||||
git submodule add https://github.com/linuxdeepin/dde-shell.git third_party/dde-shell
|
||||
```
|
||||
|
||||
### 2. 安装构建依赖
|
||||
|
||||
```bash
|
||||
# Debian/Deepin系统
|
||||
sudo apt build-dep .
|
||||
|
||||
# 或手动安装依赖
|
||||
sudo apt install -y \
|
||||
cmake \
|
||||
g++ \
|
||||
qt6-base-dev \
|
||||
qt6-tools-dev \
|
||||
libdtk6-core-dev \
|
||||
libdtk6-widget-dev
|
||||
```
|
||||
|
||||
### 3. 配置CMake
|
||||
|
||||
```bash
|
||||
# 创建构建目录
|
||||
mkdir build && cd build
|
||||
|
||||
# 配置,指定dde-shell路径
|
||||
cmake .. -Ddde-shell_DIR=~/dde-shell/build
|
||||
```
|
||||
|
||||
## 开发步骤
|
||||
|
||||
### 步骤1: 获取D-Bus接口定义
|
||||
|
||||
查看deepin-graphics-driver-manager的D-Bus接口:
|
||||
|
||||
```bash
|
||||
# 克隆仓库
|
||||
git clone https://github.com/linuxdeepin/deepin-graphics-driver-manager.git
|
||||
|
||||
# 查看接口定义
|
||||
cat deepin-graphics-driver-manager/com.deepin.daemon.GraphicsDriver.xml
|
||||
```
|
||||
|
||||
接口方法:
|
||||
- `GetDevice()` - 获取显卡设备信息(返回JSON字符串)
|
||||
- `GetCurrDriverName()` - 获取当前驱动名称
|
||||
- `GetNewDriverName()` - 获取推荐驱动名称
|
||||
- `PrepareInstall(name, language)` - 准备安装驱动
|
||||
- `TestInstall()` - 测试安装
|
||||
- `RealInstall()` - 实际安装
|
||||
- `CancelInstall()` - 取消安装
|
||||
|
||||
信号:
|
||||
- `ReportProgress(ratio)` - 安装进度报告(ratio为百分比字符串)
|
||||
- `Cancel()` - 安装取消通知
|
||||
|
||||
### 步骤2: 适配D-Bus接口
|
||||
|
||||
编辑`graphicsdriverapplet.cpp`,根据实际接口调整:
|
||||
|
||||
```cpp
|
||||
// 检查D-Bus服务是否可用
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
if (!bus.isConnected()) {
|
||||
qWarning() << "Cannot connect to D-Bus session bus";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查服务是否存在
|
||||
QDBusInterface interface(
|
||||
"com.deepin.daemon.GraphicsDriver",
|
||||
"/com/deepin/daemon/GraphicsDriver",
|
||||
"com.deepin.daemon.GraphicsDriver",
|
||||
bus
|
||||
);
|
||||
|
||||
if (!interface.isValid()) {
|
||||
qWarning() << "GraphicsDriver service is not available";
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
### 步骤3: 完善GPU设备检测
|
||||
|
||||
根据`GetDevice()`返回的JSON格式,调整解析逻辑:
|
||||
|
||||
```json
|
||||
{
|
||||
"vendor": "NVIDIA",
|
||||
"model": "GeForce GTX 1660 Ti",
|
||||
"driverVersion": "470.103.01",
|
||||
"driverStatus": "installed",
|
||||
"drivers": [
|
||||
{
|
||||
"name": "nvidia-driver-470",
|
||||
"version": "470.103.01",
|
||||
"description": "NVIDIA Driver 470 (推荐)"
|
||||
},
|
||||
{
|
||||
"name": "nvidia-driver-460",
|
||||
"version": "460.103.01",
|
||||
"description": "NVIDIA Driver 460"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 步骤4: 添加图标资源
|
||||
|
||||
创建`icons/`目录并添加图标:
|
||||
|
||||
```bash
|
||||
mkdir icons
|
||||
|
||||
# 添加显卡图标(可以从deepin图标库获取)
|
||||
wget https://github.com/linuxdeepin/deepin-icon-theme/raw/master/icons/deepin/scalable/apps/graphics-card.svg -P icons/
|
||||
```
|
||||
|
||||
在QML中引用:
|
||||
|
||||
```qml
|
||||
Image {
|
||||
source: "qrc:/icons/graphics-card.svg"
|
||||
}
|
||||
```
|
||||
|
||||
### 步骤5: 测试插件
|
||||
|
||||
```bash
|
||||
# 构建
|
||||
cmake -Bbuild
|
||||
cmake --build build
|
||||
|
||||
# 安装到本地测试
|
||||
cmake --install build --prefix ~/.local
|
||||
|
||||
# 启动dde-shell测试模式
|
||||
dde-shell -t
|
||||
```
|
||||
|
||||
### 步骤6: 调试技巧
|
||||
|
||||
```bash
|
||||
# 查看D-Bus服务
|
||||
qdbus | grep GraphicsDriver
|
||||
|
||||
# 监听D-Bus信号
|
||||
dbus-monitor "interface='com.deepin.daemon.GraphicsDriver'"
|
||||
|
||||
# 查看插件日志
|
||||
QT_LOGGING_RULES="dde.shell*=true" dde-shell -t
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 1. 插件未加载
|
||||
|
||||
检查`metadata.json`格式是否正确:
|
||||
|
||||
```json
|
||||
{
|
||||
"Plugin": {
|
||||
"Version": "1.0",
|
||||
"Id": "org.deepin.ds.graphics-driver",
|
||||
"Url": "driverview.qml",
|
||||
"Category": "DDE"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. D-Bus连接失败
|
||||
|
||||
确认deepin-graphics-driver-manager服务已启动:
|
||||
|
||||
```bash
|
||||
# 检查服务状态
|
||||
systemctl status deepin-graphics-driver-manager
|
||||
|
||||
# 手动启动服务
|
||||
sudo deepin-graphics-driver-manager -d
|
||||
```
|
||||
|
||||
### 3. 权限问题
|
||||
|
||||
安装驱动需要root权限,确保PolicyKit配置正确:
|
||||
|
||||
```bash
|
||||
# 检查PolicyKit规则
|
||||
pkaction --action-id com.deepin.daemon.GraphicsDriver --verbose
|
||||
```
|
||||
|
||||
## 代码规范
|
||||
|
||||
### 命名规范
|
||||
|
||||
- 类名:`PascalCase`(如`GraphicsDriverApplet`)
|
||||
- 方法名:`camelCase`(如`refreshDeviceInfo`)
|
||||
- 常量:`UPPER_SNAKE_CASE`(如`DBUS_SERVICE`)
|
||||
- 成员变量:`m_`前缀(如`m_dbusInterface`)
|
||||
|
||||
### 文件组织
|
||||
|
||||
- 头文件:类声明、信号、槽、Q_PROPERTY
|
||||
- 实现文件:构造函数、方法实现、D_APPLET_CLASS宏
|
||||
- QML文件:界面布局、交互逻辑
|
||||
|
||||
## 发布流程
|
||||
|
||||
### 1. 版本号更新
|
||||
|
||||
更新`CMakeLists.txt`中的版本号:
|
||||
|
||||
```cmake
|
||||
project(dde-graphics-driver-applet VERSION 1.0.0 LANGUAGES CXX)
|
||||
```
|
||||
|
||||
### 2. 构建Debian包
|
||||
|
||||
```bash
|
||||
dpkg-buildpackage -uc -us -nc -b
|
||||
```
|
||||
|
||||
### 3. 测试安装
|
||||
|
||||
```bash
|
||||
sudo dpkg -i ../dde-graphics-driver-applet_1.0.0_amd64.deb
|
||||
```
|
||||
|
||||
### 4. 提交到官方仓库
|
||||
|
||||
```bash
|
||||
# Fork仓库后
|
||||
git remote add upstream https://github.com/linuxdeepin/dde-shell.git
|
||||
git push origin master
|
||||
# 创建Pull Request
|
||||
```
|
||||
|
||||
## 相关资源
|
||||
|
||||
- [dde-shell插件开发文档](https://github.com/linuxdeepin/dde-shell/tree/master/docs/plugin)
|
||||
- [deepin-graphics-driver-manager](https://github.com/linuxdeepin/deepin-graphics-driver-manager)
|
||||
- [DTK开发文档](https://linuxdeepin.github.io/dtk/)
|
||||
- [Qt D-Bus文档](https://doc.qt.io/qt-6/qtdbus-index.html)
|
||||
Reference in New Issue
Block a user