[App Sharing] 20.9 搞了下蓝牙设备显示电量,大家可以试一下 Resolved
Tofloor
poster avatar
deepin-superuser
deepin
2023-07-23 06:42
Author
效果预览

截图_选择区域_20230722222927.png

已知问题

电量并不会更新,只有初始化的时候获取到一个数,原因是电量更新的时候不会调用 updateDeviceState 方法,后续可能需要修改 dde-daemon 来配合

食用方法

下载安装即可

dde-dock_5.5.86.1-1+kt286_amd64.zip

实现方式(V23)

修改 dde-dock/plugins/bluetooth/componments/bluetoothadapteritem.cpp 中的 initActionList updateDeviceState 方法,将

m_labelAction->setText(m_device->alias());

修改为

// 获取设备电量
QDBusInterface interface("org.bluez", m_device->id(), "org.freedesktop.DBus.Properties", QDBusConnection::systemBus(), this);
QDBusReply reply = interface.call("Get", "org.bluez.Battery1", "Percentage");
if(reply.isValid()){
    qInfo() << "获取到的蓝牙电量:" << reply.value();
    m_labelAction->setText(m_device->alias() + " (电量:" + QString::number(reply.value().toInt()) + "%)");
} else {
    qInfo() << "获取蓝牙电量失败:" << reply.error().message();
    m_labelAction->setText(m_device->alias());
}
实现方式(20.9)

修改 dde-dock/plugins/bluetooth/componments/bluetoothadapteritem.cpp 中的 initActionList updateDeviceState 方法,将

m_standarditem->setText(m_device->alias());

修改为

// 获取设备电量
QDBusInterface interface("org.bluez", m_device->id(), "org.freedesktop.DBus.Properties", QDBusConnection::systemBus(), this);
QDBusReply reply = interface.call("Get", "org.bluez.Battery1", "Percentage");
if(reply.isValid()){
    qInfo() << "获取到的蓝牙电量:" << reply.value();
    m_standarditem->setText(m_device->alias() + " (电量:" + QString::number(reply.value().toInt()) + "%)");
} else {
    qInfo() << "获取蓝牙电量失败:" << reply.error().message();
    m_standarditem->setText(m_device->alias());
}
Reply Favorite View the author
All Replies
相对湿度
deepin
2023-07-23 06:50
#1

不错,挺好玩的,就是数值准不准确不清楚了,明天有空我插上数据线一直充电看看会不会到100%

Reply View the author
deepin-superuser
deepin
2023-07-23 06:54
#2
相对湿度

不错,挺好玩的,就是数值准不准确不清楚了,明天有空我插上数据线一直充电看看会不会到100%

这么说吧 这个只能显示个大概的 Windows上也一样,得看设备返回的准不准

例如我这个鼠标 一小时前 57% 一小时后 59% 😂

Reply View the author
谢克辉
deepin beta test group
2023-07-23 07:06
#3

厉害了,23可以用吗

Reply View the author
神末shenmo
deepin
Spark-App
2023-07-23 07:21
#4

better dde干脆开个SIG吧wwww

现在deepin 20.9已经冻结了,不会出现后续被上游强制更新上去的问题了

源的问题不行可以让星火解决,只要别太大了

Reply View the author
璀璨星空
deepin
2023-07-23 07:24
#5
神末shenmo

better dde干脆开个SIG吧wwww

现在deepin 20.9已经冻结了,不会出现后续被上游强制更新上去的问题了

源的问题不行可以让星火解决,只要别太大了

终究是星火抗下了所有

Reply View the author
deepin-superuser
deepin
2023-07-23 07:38
#6
神末shenmo

better dde干脆开个SIG吧wwww

现在deepin 20.9已经冻结了,不会出现后续被上游强制更新上去的问题了

源的问题不行可以让星火解决,只要别太大了

主要是我不能保证自己可以持续更新,而且未来我一定会用V23 到时候管 V20 的概率不大

Reply View the author
deepin-superuser
deepin
2023-07-23 07:40
#7
谢克辉

厉害了,23可以用吗

不行,但是你可以尝试自己在 V23 上编译一下 dde-dock

Reply View the author
deepin-superuser
deepin
2023-07-23 07:41
#8
神末shenmo

better dde干脆开个SIG吧wwww

现在deepin 20.9已经冻结了,不会出现后续被上游强制更新上去的问题了

源的问题不行可以让星火解决,只要别太大了

所以我更倾向于给官方提 PR

Reply View the author
神末shenmo
deepin
Spark-App
2023-07-23 07:46
#9
deepin-superuser

所以我更倾向于给官方提 PR

20肯定是不会有下一个版本了....23最开始都不是从20开发的,相当于是新项目了,提给20的话23也不会改。pr是没法合并了

后续维护没有就没有了,20也快EOL了,不会又任何更新,到时候社区大家也是去用23了,趁着20还是主流版本,继续better dde让社区大家爽一爽也无妨啦~

Reply View the author
2023开始学习
deepin
2023-07-23 08:33
#10

我下载了源码(https://github.com/linuxdeepin/dde-dock),发现没有这行代码,应该是更新了。你的是那个版本啊

Reply View the author
阿尼樱奈奈
Moderator
2023-07-23 11:40
#11

like这个点赞了,但可惜我试不了,因为我的电脑不支持蓝牙。

Reply View the author
deepin-superuser
deepin
2023-07-23 21:56
#12
2023开始学习

我下载了源码(https://github.com/linuxdeepin/dde-dock),发现没有这行代码,应该是更新了。你的是那个版本啊

我修改的是 20.9 里的 5.5.86.1-1 版本。github上是V23 的了

Reply View the author
deepin-superuser
deepin
2023-07-23 22:19
#13
2023开始学习

我下载了源码(https://github.com/linuxdeepin/dde-dock),发现没有这行代码,应该是更新了。你的是那个版本啊

V23 的是 dde-dock/plugins/bluetooth/componments/bluetoothadapteritem.cpp

m_labelAction->setText(m_device->alias());
Reply View the author
青稚
Moderator
2023-07-24 05:31
#14

可惜我的设备不支持蓝牙,但还是得点赞支持一下like

Reply View the author