@@ -2822,9 +2822,11 @@ void FashionLeftPluginProvider::openWeatherPopup(int taskbarLeft, int taskbarTop
28222822
28232823void 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
31233125void 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 ;
0 commit comments