Skip to content

Commit 30d0280

Browse files
committed
fix(dock): restore fashion mail card and real monitor stats
1 parent 367cf57 commit 30d0280

2 files changed

Lines changed: 61 additions & 20 deletions

File tree

panels/dock/fashionleftpluginprovider.cpp

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,9 +2822,11 @@ void FashionLeftPluginProvider::openWeatherPopup(int taskbarLeft, int taskbarTop
28222822

28232823
void FashionLeftPluginProvider::openMailClient()
28242824
{
2825-
refreshMailState();
28262825
if (!m_mailConfigured) {
2827-
return;
2826+
auto *sessionBusInterface = QDBusConnection::sessionBus().interface();
2827+
if (sessionBusInterface && sessionBusInterface->isServiceRegistered(MailService)) {
2828+
refreshMailState();
2829+
}
28282830
}
28292831

28302832
refreshMailClient();
@@ -3122,6 +3124,17 @@ void FashionLeftPluginProvider::refreshNotificationCount()
31223124

31233125
void FashionLeftPluginProvider::refreshMailState()
31243126
{
3127+
auto *sessionBusInterface = QDBusConnection::sessionBus().interface();
3128+
if (!sessionBusInterface || !sessionBusInterface->isServiceRegistered(MailService)) {
3129+
if (m_mailConfigured || m_mailUnreadCount != 0 || m_mailSummaryText != QStringLiteral("邮箱信息不可用")) {
3130+
m_mailConfigured = false;
3131+
m_mailUnreadCount = 0;
3132+
m_mailSummaryText = QStringLiteral("邮箱信息不可用");
3133+
emit mailStateChanged();
3134+
}
3135+
return;
3136+
}
3137+
31253138
QDBusInterface mailInterface(MailService,
31263139
MailPath,
31273140
MailInterface,
@@ -3252,10 +3265,17 @@ void FashionLeftPluginProvider::refreshSystemStats()
32523265

32533266
m_previousCpuTotalTime = totalCpuTime;
32543267
m_previousCpuIdleTime = idleCpuTime;
3268+
} else {
3269+
querySystemMonitorUsage("getCpuUsage", &nextCpuUsage);
32553270
}
32563271

32573272
int nextMemoryUsage = systemMemoryUsagePercent();
3258-
querySystemMonitorUsage("getMemoryUsage", &nextMemoryUsage);
3273+
// Prefer direct kernel counters. The daemon can expose stale placeholder values
3274+
// before it has refreshed its own cache.
3275+
if (nextMemoryUsage < 0) {
3276+
nextMemoryUsage = m_memoryUsage;
3277+
querySystemMonitorUsage("getMemoryUsage", &nextMemoryUsage);
3278+
}
32593279

32603280
const QStringList activeInterfaces = preferredNetworkInterfaces();
32613281
const quint64 receiveBytes = totalInterfaceBytes(true, activeInterfaces);
@@ -4148,6 +4168,12 @@ bool FashionLeftPluginProvider::readCpuTimes(quint64 *totalTime, quint64 *idleTi
41484168
for (qsizetype index = 1; index < fields.size(); ++index) {
41494169
total += fields.at(index).toULongLong();
41504170
}
4171+
if (fields.size() > 9) {
4172+
total -= fields.at(9).toULongLong();
4173+
}
4174+
if (fields.size() > 10) {
4175+
total -= fields.at(10).toULongLong();
4176+
}
41514177

41524178
const quint64 idle = fields.value(4).toULongLong() + fields.value(5).toULongLong();
41534179
*totalTime = total;
@@ -4159,26 +4185,53 @@ int FashionLeftPluginProvider::systemMemoryUsagePercent()
41594185
{
41604186
QFile file(QStringLiteral("/proc/meminfo"));
41614187
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
4162-
return 0;
4188+
return -1;
41634189
}
41644190

41654191
quint64 totalMemory = 0;
41664192
quint64 availableMemory = 0;
4167-
while (!file.atEnd()) {
4168-
const QString line = QString::fromUtf8(file.readLine());
4193+
quint64 freeMemory = 0;
4194+
quint64 bufferMemory = 0;
4195+
quint64 cachedMemory = 0;
4196+
quint64 reclaimableMemory = 0;
4197+
quint64 shmemMemory = 0;
4198+
while (true) {
4199+
const QByteArray rawLine = file.readLine();
4200+
if (rawLine.isEmpty()) {
4201+
break;
4202+
}
4203+
4204+
const QString line = QString::fromUtf8(rawLine);
41694205
if (line.startsWith(QStringLiteral("MemTotal:"))) {
41704206
totalMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
41714207
} else if (line.startsWith(QStringLiteral("MemAvailable:"))) {
41724208
availableMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
4209+
} else if (line.startsWith(QStringLiteral("MemFree:"))) {
4210+
freeMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
4211+
} else if (line.startsWith(QStringLiteral("Buffers:"))) {
4212+
bufferMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
4213+
} else if (line.startsWith(QStringLiteral("Cached:"))) {
4214+
cachedMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
4215+
} else if (line.startsWith(QStringLiteral("SReclaimable:"))) {
4216+
reclaimableMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
4217+
} else if (line.startsWith(QStringLiteral("Shmem:"))) {
4218+
shmemMemory = line.section(QLatin1Char(':'), 1).simplified().section(QLatin1Char(' '), 0, 0).toULongLong();
41734219
}
41744220

41754221
if (totalMemory > 0 && availableMemory > 0) {
41764222
break;
41774223
}
41784224
}
41794225

4226+
if (availableMemory == 0 && totalMemory > 0) {
4227+
const quint64 estimatedAvailableMemory = freeMemory + bufferMemory + cachedMemory + reclaimableMemory;
4228+
availableMemory = estimatedAvailableMemory > shmemMemory
4229+
? (estimatedAvailableMemory - shmemMemory)
4230+
: 0;
4231+
}
4232+
41804233
if (totalMemory == 0) {
4181-
return 0;
4234+
return -1;
41824235
}
41834236

41844237
const quint64 usedMemory = totalMemory > availableMemory ? (totalMemory - availableMemory) : 0;

panels/dock/package/FashionLeftDockArea.qml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Control {
8282
readonly property color aiIconTintColor: Panel.colorTheme === Dock.Dark ? Qt.rgba(1, 1, 1, 0.92) : Qt.rgba(0, 0, 0, 0.86)
8383
readonly property int weatherTextSpacing: root.tightSpacing - 2
8484
readonly property bool musicPageVisible: provider.musicAvailable
85-
readonly property bool mailPageVisible: provider.mailConfigured
85+
readonly property bool mailPageVisible: true
8686
readonly property bool aiPageVisible: provider.aiRunningCount > 0 && aiEntries.length > 0
8787
readonly property var pageIds: {
8888
const ids = ["weather"]
@@ -586,19 +586,7 @@ Control {
586586
return
587587
}
588588

589-
const fallbackPageId = root.normalizedPageId(root.mailAutoActive ? root.mailReturnPageId : root.manualPageId)
590-
if (root.currentPageId === "mail"
591-
|| root.transitionFromPageId === "mail"
592-
|| root.transitionToPageId === "mail") {
593-
root.showPage(fallbackPageId, false)
594-
}
595-
596-
if (root.manualPageId === "mail") {
597-
root.manualPageId = "weather"
598-
}
599-
600589
root.mailAutoActive = false
601-
root.previousMailUnreadCount = provider.mailUnreadCount
602590
}
603591

604592
function completeMailAutoFocus() {

0 commit comments

Comments
 (0)