From 6a53fc7edc991803ccd59d03ff5223684d1c8664 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 13 Sep 2021 20:09:55 +0300 Subject: [PATCH] Beta version 3.0.4: Add some theme loading logging. --- .../details/storage_settings_scheme.cpp | 5 +++ Telegram/SourceFiles/storage/localstorage.cpp | 44 +++++++++++++++++++ .../window/themes/window_theme.cpp | 13 +++--- cmake | 2 +- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 845749767..3b2216e21 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -618,6 +618,7 @@ bool ReadSetting( stream >> key; if (!CheckStreamStatus(stream)) return false; + DEBUG_LOG(("Theme: read key legacy: %1").arg(key)); context.themeKeyLegacy = key; context.legacyRead = true; } break; @@ -628,6 +629,10 @@ bool ReadSetting( stream >> keyDay >> keyNight >> nightMode; if (!CheckStreamStatus(stream)) return false; + DEBUG_LOG(("Theme: read keys (night: %1) day_key: %2, night_key: %3, " + ).arg(Logs::b(nightMode == 1) + ).arg(keyDay + ).arg(keyNight)); context.themeKeyDay = keyDay; context.themeKeyNight = keyNight; Window::Theme::SetNightModeValue(nightMode == 1); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 573a3e4ed..d52d1f195 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -125,6 +125,10 @@ bool CheckStreamStatus(QDataStream &stream) { void applyReadContext(ReadSettingsContext &&context) { ApplyReadFallbackConfig(context); + DEBUG_LOG(("Theme: applying context, legacy: %1, day: %2, night: %3" + ).arg(context.themeKeyLegacy + ).arg(context.themeKeyDay + ).arg(context.themeKeyNight)); _themeKeyLegacy = context.themeKeyLegacy; _themeKeyDay = context.themeKeyDay; _themeKeyNight = context.themeKeyNight; @@ -869,6 +873,7 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) { FileReadDescriptor theme; if (!ReadEncryptedFile(theme, key, _basePath, SettingsKey)) { + DEBUG_LOG(("Theme: Could not read file for key: %1").arg(key)); return {}; } @@ -893,6 +898,9 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) { object.pathRelative = tag; } if (theme.stream.status() != QDataStream::Ok) { + DEBUG_LOG(("Theme: Bad status for key: %1, tag: %2" + ).arg(key + ).arg(tag)); return {}; } @@ -932,6 +940,9 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) { >> field2; if (!ignoreCache) { if (theme.stream.status() != QDataStream::Ok) { + DEBUG_LOG(("Theme: Bad status for cache, key: %1, tag: %2" + ).arg(key + ).arg(tag)); return {}; } cache.paletteChecksum = cachePaletteChecksum; @@ -950,8 +961,12 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) { std::optional InitialLoadThemeUsingKey(FileKey key) { auto read = readThemeUsingKey(key); const auto result = read.object.pathAbsolute; + if (read.object.content.isEmpty()) { + DEBUG_LOG(("Theme: Could not read content for key: %1").arg(key)); + } if (read.object.content.isEmpty() || !Window::Theme::Initialize(std::move(read))) { + DEBUG_LOG(("Theme: Could not initialized for key: %1").arg(key)); return std::nullopt; } return result; @@ -961,13 +976,23 @@ void writeTheme(const Window::Theme::Saved &saved) { using namespace Window::Theme; if (_themeKeyLegacy) { + DEBUG_LOG(("Theme: skipping write, because legacy: %1" + ).arg(_themeKeyLegacy)); return; } auto &themeKey = IsNightMode() ? _themeKeyNight : _themeKeyDay; + DEBUG_LOG(("Theme: writing (night: %1), key_day: %2, key_night: %3" + ).arg(Logs::b(IsNightMode()) + ).arg(_themeKeyDay + ).arg(_themeKeyNight)); if (saved.object.content.isEmpty()) { if (themeKey) { + if (IsNightMode()) { + DEBUG_LOG(("Theme: cleared for night mode.")); + SetNightModeValue(false); + } ClearKey(themeKey, _basePath); themeKey = 0; writeSettings(); @@ -1032,17 +1057,36 @@ void InitialLoadTheme() { : (Window::Theme::IsNightMode() ? _themeKeyNight : _themeKeyDay); + DEBUG_LOG(("Theme: initial load (night: %1), " + "key_legacy: %2, key_day: %3, key_night: %4" + ).arg(Logs::b(Window::Theme::IsNightMode()) + ).arg(_themeKeyLegacy + ).arg(_themeKeyDay + ).arg(_themeKeyNight)); if (!key) { + if (Window::Theme::IsNightMode()) { + DEBUG_LOG(("Theme: zero key for night mode.")); + Window::Theme::SetNightModeValue(false); + } return; } else if (const auto path = InitialLoadThemeUsingKey(key)) { + DEBUG_LOG(("Theme: loaded with result: %1").arg(*path)); if (_themeKeyLegacy) { Window::Theme::SetNightModeValue(*path == Window::Theme::NightThemePath()); (Window::Theme::IsNightMode() ? _themeKeyNight : _themeKeyDay) = base::take(_themeKeyLegacy); + DEBUG_LOG(("Theme: now (night: %1), " + "key_legacy: %2, key_day: %3, key_night: %4 (path: %5)" + ).arg(Logs::b(Window::Theme::IsNightMode()) + ).arg(_themeKeyLegacy + ).arg(_themeKeyDay + ).arg(_themeKeyNight + ).arg(*path)); } } else { + DEBUG_LOG(("Theme: could not load, clearing..")); clearTheme(); } } diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 8a6665195..5a0c3341e 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -154,7 +154,6 @@ bool readNameAndValue(const char *&from, const char *end, QLatin1String *outName enum class SetResult { Ok, - Bad, NotFound, }; SetResult setColorSchemeValue( @@ -202,7 +201,7 @@ SetResult setColorSchemeValue( } else { LOG(("Theme Error: Unexpected internal error.")); } - return SetResult::Bad; + Unexpected("Value after palette.setColor()."); } bool loadColorScheme( @@ -215,9 +214,7 @@ bool loadColorScheme( value = unsupported.value(value, value); auto result = setColorSchemeValue(name, value, colorizer, out); - if (result == SetResult::Bad) { - return false; - } else if (result == SetResult::NotFound) { + if (result == SetResult::NotFound) { unsupported.insert(name, value); } return true; @@ -302,6 +299,7 @@ bool LoadTheme( return false; } if (!loadColorScheme(schemeContent, paletteColorizer, out)) { + DEBUG_LOG(("Theme: Could not loadColorScheme.")); return false; } if (!out) { @@ -311,6 +309,7 @@ bool LoadTheme( auto backgroundTiled = false; auto backgroundContent = QByteArray(); if (!loadBackground(file, &backgroundContent, &backgroundTiled)) { + DEBUG_LOG(("Theme: Could not loadBackground.")); return false; } @@ -347,6 +346,7 @@ bool LoadTheme( } else { // Looks like it is not a .zip theme. if (!loadColorScheme(editedPalette.value_or(content), paletteColorizer, out)) { + DEBUG_LOG(("Theme: Could not loadColorScheme from non-zip.")); return false; } if (!out) { @@ -422,6 +422,7 @@ bool InitializeFromSaved(Saved &&saved) { const auto colorizer = ColorizerForTheme(saved.object.pathAbsolute); if (!LoadTheme(saved.object.content, colorizer, editing, &saved.cache)) { + DEBUG_LOG(("Theme: Could not load from saved.")); return false; } if (editing) { @@ -1235,6 +1236,7 @@ bool Initialize(Saved &&saved) { Background()->setThemeObject(saved.object); return true; } + DEBUG_LOG(("Theme: Could not initialize from saved.")); return false; } @@ -1464,6 +1466,7 @@ bool ReadPaletteValues(const QByteArray &content, Fn