From 9c547bae35140559e2cf8ab4c0f829b1c12b4ac6 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Tue, 20 Oct 2026 21:16:33 +0800 Subject: [PATCH] refactor: improve thememanager logging and date handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Remove unused QDebug include from sunrisesunset.cpp 2. Cache date.startOfDay() to avoid redundant computation 3. Remove debug qInfo logging of raw sunrise/sunset calculations 4. Add detailed structured logging when auto theme change is triggered 5. Log includes theme transition, current time, coordinates, UTC offset, sunrise and sunset times The changes reduce unnecessary debug output while adding more informative logging at the point where theme changes are actually applied, making it easier to diagnose auto-theme behavior. Log: Improved auto theme switching diagnostics with detailed change logging Influence: 1. Verify auto theme switching still works correctly at sunrise and sunset boundaries 2. Confirm theme change logs contain accurate timestamps, coordinates, and theme names 3. Test behavior across different UTC offsets and extreme latitudes 4. Ensure no functional regression from removing the debug log line in sunrise/sunset calculation 5. Verify sunrise/sunset datetime values remain correct after refactoring startOfDay caching refactor: 改进主题管理器日志和日期处理 1. 移除 sunrisesunset.cpp 中未使用的 QDebug 头文件 2. 缓存 date.startOfDay() 避免重复计算 3. 移除日出日落原始计算的调试日志 4. 在自动主题切换触发时添加详细的结构化日志 5. 日志包含主题切换、当前时间、坐标、UTC 偏移、日出和日落时间 这些改动减少了不必要的调试输出,同时在主题实际切换处添加了更有信息量的日 志,便于诊断自动主题切换行为。 Log: 通过详细的切换日志改进自动主题切换诊断能力 Influence: 1. 验证自动主题切换在日出和日落边界仍能正常工作 2. 确认主题切换日志包含准确的时间戳、坐标和主题名称 3. 测试不同 UTC 偏移和极端纬度下的行为 4. 确保移除日出日落计算中的调试日志未造成功能回归 5. 验证重构 startOfDay 缓存后日出日落时间值仍然正确 --- src/plugin-qt/thememanager/sunrisesunset.cpp | 10 +++++----- src/plugin-qt/thememanager/thememanager.cpp | 12 +++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/plugin-qt/thememanager/sunrisesunset.cpp b/src/plugin-qt/thememanager/sunrisesunset.cpp index f5123896..281a5f95 100644 --- a/src/plugin-qt/thememanager/sunrisesunset.cpp +++ b/src/plugin-qt/thememanager/sunrisesunset.cpp @@ -1,10 +1,9 @@ -// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later #include "sunrisesunset.h" -#include #include #include @@ -96,8 +95,9 @@ bool SunriseSunset::getSunriseSunset(double latitude, double longitude, double u if (sunsetUT <= -100) // 长昼 返回的sunrise-sunset区间用于判断当前是否为白天 sunsetUT = 100; - sunrise = date.startOfDay().addMSecs(static_cast(sunriseUT * 3600 * 1000)); - sunset = date.startOfDay().addMSecs(static_cast(sunsetUT * 3600 * 1000)); - qInfo() << __FUNCTION__ << date << latitude << longitude << sunriseUT << sunrise << sunsetUT << sunset; + const QDateTime startOfDay = date.startOfDay(); + sunrise = startOfDay.addMSecs(static_cast(sunriseUT * 3600 * 1000)); + sunset = startOfDay.addMSecs(static_cast(sunsetUT * 3600 * 1000)); + return true; } diff --git a/src/plugin-qt/thememanager/thememanager.cpp b/src/plugin-qt/thememanager/thememanager.cpp index 8df4e8b8..223df2f5 100644 --- a/src/plugin-qt/thememanager/thememanager.cpp +++ b/src/plugin-qt/thememanager/thememanager.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -158,6 +158,16 @@ void ThemeManager::autoSetTheme(double latitude, double longitude) } if (m_curThemeType != themeType) { + qInfo().noquote().nospace() + << "[thememanager] Auto theme change requested: from=" + << (m_curThemeType.isEmpty() ? QStringLiteral("unset") : m_curThemeType) + << ", to=" << themeType + << ", current_time=" << curr.toString(Qt::ISODate) + << ", latitude=" << latitude + << ", longitude=" << longitude + << ", utc_offset_hours=" << utcOffset + << ", sunrise=" << sunrise.toString(Qt::ISODate) + << ", sunset=" << sunset.toString(Qt::ISODate); m_curThemeType = themeType; doSetGlobalTheme(themeType); }