2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Beta version 3.0.4: Add some theme loading logging.

This commit is contained in:
John Preston
2021-09-13 20:09:55 +03:00
parent 889c3293e7
commit 6a53fc7edc
4 changed files with 58 additions and 6 deletions

View File

@@ -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);

View File

@@ -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<QString> 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();
}
}