feat: C++后端功能扩展(链路速率/刷新间隔/TCP连接数/WiFi信号)

P7 链路速率:读 /sys/class/net/<iface>/speed,无线失败时降级解析 iw bitrate,
弹窗接口名旁显示(>=1000 显示 Gbps)
P5 可配置刷新间隔:新增 refreshInterval 属性,设置窗口可选 1/2/5 秒并持久化
P3 TCP 连接数:统计 /proc/net/tcp 与 tcp6 的 ESTABLISHED 连接数,弹窗展示
P6 WiFi 信号强度:读 /proc/net/wireless 的 level(dBm),弹窗接口信息区展示
所有读取均优雅降级(文件缺失/读取失败返回默认值),不改动速度计算逻辑
This commit is contained in:
2026-08-09 00:07:41 +08:00
parent 34e163c6d2
commit 640cc2ab84
6 changed files with 371 additions and 7 deletions
+9
View File
@@ -124,4 +124,13 @@ QtObject {
var idx = str.indexOf(' ')
return idx < 0 ? "" : str.substring(idx + 1)
}
// 格式化链路协商速率(Mbps 输入):>=1000 显示 Gbps(保留 1 位小数),否则显示 Mbps
// 设计原因:有线常见 1000/2500 Mbps,无线常见 866 Mbps,按阈值切换单位更易读
function formatLinkSpeed(mbps) {
if (mbps >= 1000) {
return (mbps / 1000).toFixed(1) + " Gbps"
}
return mbps.toFixed(0) + " Mbps"
}
}
+49 -2
View File
@@ -51,6 +51,13 @@ Control {
readonly property real rxDropped: applet ? (applet.rxDropped || 0) : 0
readonly property real txDropped: applet ? (applet.txDropped || 0) : 0
// 活动接口的链路协商速率(Mbps),由 C++ 后端低频检测;0 表示不可用
readonly property int linkSpeed: applet ? (applet.linkSpeed || 0) : 0
// 当前活动接口的 TCP ESTABLISHED 连接数,由 C++ 后端每秒统计
readonly property int tcpConnections: applet ? (applet.tcpConnections || 0) : 0
// 活动接口的 WiFi 信号强度(dBm,负值),由 C++ 后端低频检测;0 表示不可用
readonly property int wifiSignal: applet ? (applet.wifiSignal || 0) : 0
// 用户自定义字体色:非空时覆盖 primaryText,空串回退 DTK 调色板派生
// 仅作用于主要文字(接口名、速度数值、累计数值、chip 未选中文字)
// secondaryText/tertiaryText/强调色不跟随,保持系统主题层次不崩
@@ -141,7 +148,7 @@ Control {
// 内容用 anchors.top 顶部对齐,接口名行始终在顶部同一垂直位置
Item {
Layout.fillWidth: true
Layout.preferredHeight: 60
Layout.preferredHeight: 76
visible: popup.ready
ColumnLayout {
@@ -165,9 +172,18 @@ Control {
// 接口名:跟随用户 textColor(primaryText),Spec 5.1 节要求
Text {
text: popup.activeInterface
font.pixelSize: 13
font.pixelSize: Math.round(13 * popup.fontScale)
color: popup.primaryText
}
// 链路协商速率:speed>=1000 显示 Gbps,否则 Mbps;无速率时隐藏
Text {
text: popup.linkSpeed > 0 ? "· " + common.formatLinkSpeed(popup.linkSpeed) : ""
font.pixelSize: Math.round(12 * popup.fontScale)
color: popup.tertiaryText
visible: popup.linkSpeed > 0
}
}
}
// 行2:IPv4 标签 + 地址 + 复制图标
@@ -291,6 +307,19 @@ Control {
}
}
}
// 行4:WiFi 信号强度(dBm),仅无线接口有信号时显示
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: 6
visible: popup.wifiSignal < 0
Text {
text: qsTr("Signal") + " " + popup.wifiSignal.toFixed(0) + " dBm"
font.pixelSize: Math.round(12 * popup.fontScale)
color: popup.tertiaryText
}
}
}
}
@@ -525,6 +554,24 @@ Control {
Item { Layout.fillWidth: true }
}
// TCP 连接数:仅在连接数>0 时显示,紧跟包统计下方
// 设计原因:连接数反映当前网络会话活跃度,是用户关心的即时信息
RowLayout {
Layout.fillWidth: true
spacing: 8
visible: popup.ready && popup.tcpConnections > 0
Item { Layout.fillWidth: true }
Text {
text: qsTr("Connections") + " " + popup.tcpConnections.toFixed(0)
font.pixelSize: Math.round(12 * popup.fontScale)
color: popup.tertiaryText
}
Item { Layout.fillWidth: true }
}
// 分隔线3
Rectangle {
Layout.fillWidth: true
+53 -3
View File
@@ -59,11 +59,11 @@ Window {
property string uninstallButtonText: qsTr("Uninstall Plugin")
width: 350
height: 390
height: 450
minimumWidth: 350
maximumWidth: 350
minimumHeight: 390
maximumHeight: 390
minimumHeight: 450
maximumHeight: 450
visible: false
flags: Qt.FramelessWindowHint | Qt.Window
// NonModal:不阻塞桌面其他区域,用户可同时操作任务栏
@@ -345,6 +345,56 @@ Window {
onColorSelected: if (applet) applet.textColor = color
}
// 刷新间隔选择区:1 秒 / 2 秒 / 5 秒
// 设计原因:用户可能觉得每秒刷新开销大或过于频繁,提供更长的间隔选项;
// 选择结果通过 applet.refreshInterval 持久化并即时生效,
// 速度计算基于真实流逝时间(elapsedSec),改变间隔不影响计算正确性
Text {
text: qsTr("Refresh Interval")
font.pixelSize: 13
font.weight: Font.Bold
color: root.textSecondary
}
// 三个间隔选项按钮:1 秒 / 2 秒 / 5 秒
RowLayout {
Layout.fillWidth: true
spacing: 8
Repeater {
model: [1000, 2000, 5000]
Rectangle {
id: intervalOption
Layout.fillWidth: true
Layout.preferredHeight: 34
radius: 8
// 选中态蓝色填充边框,未选中态卡片背景,hover 态加深
color: applet && applet.refreshInterval === modelData
? root.selBg : (intervalMouse.containsMouse ? root.hoverBg : root.cardBg)
border.width: 1
border.color: applet && applet.refreshInterval === modelData
? root.selBorder : root.lineColor
Text {
anchors.centerIn: parent
text: (modelData / 1000) + "s"
font.pixelSize: 13
color: applet && applet.refreshInterval === modelData
? root.selText : root.textPrimary
}
MouseArea {
id: intervalMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: if (applet) applet.refreshInterval = modelData
}
}
}
}
Item { Layout.preferredHeight: 4 }
// 卸载插件按钮:文字可动态切换(复制命令后显示提示)