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; stream >> key;
if (!CheckStreamStatus(stream)) return false; if (!CheckStreamStatus(stream)) return false;
DEBUG_LOG(("Theme: read key legacy: %1").arg(key));
context.themeKeyLegacy = key; context.themeKeyLegacy = key;
context.legacyRead = true; context.legacyRead = true;
} break; } break;
@ -628,6 +629,10 @@ bool ReadSetting(
stream >> keyDay >> keyNight >> nightMode; stream >> keyDay >> keyNight >> nightMode;
if (!CheckStreamStatus(stream)) return false; 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.themeKeyDay = keyDay;
context.themeKeyNight = keyNight; context.themeKeyNight = keyNight;
Window::Theme::SetNightModeValue(nightMode == 1); Window::Theme::SetNightModeValue(nightMode == 1);

View file

@ -125,6 +125,10 @@ bool CheckStreamStatus(QDataStream &stream) {
void applyReadContext(ReadSettingsContext &&context) { void applyReadContext(ReadSettingsContext &&context) {
ApplyReadFallbackConfig(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; _themeKeyLegacy = context.themeKeyLegacy;
_themeKeyDay = context.themeKeyDay; _themeKeyDay = context.themeKeyDay;
_themeKeyNight = context.themeKeyNight; _themeKeyNight = context.themeKeyNight;
@ -869,6 +873,7 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
FileReadDescriptor theme; FileReadDescriptor theme;
if (!ReadEncryptedFile(theme, key, _basePath, SettingsKey)) { if (!ReadEncryptedFile(theme, key, _basePath, SettingsKey)) {
DEBUG_LOG(("Theme: Could not read file for key: %1").arg(key));
return {}; return {};
} }
@ -893,6 +898,9 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
object.pathRelative = tag; object.pathRelative = tag;
} }
if (theme.stream.status() != QDataStream::Ok) { if (theme.stream.status() != QDataStream::Ok) {
DEBUG_LOG(("Theme: Bad status for key: %1, tag: %2"
).arg(key
).arg(tag));
return {}; return {};
} }
@ -932,6 +940,9 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
>> field2; >> field2;
if (!ignoreCache) { if (!ignoreCache) {
if (theme.stream.status() != QDataStream::Ok) { if (theme.stream.status() != QDataStream::Ok) {
DEBUG_LOG(("Theme: Bad status for cache, key: %1, tag: %2"
).arg(key
).arg(tag));
return {}; return {};
} }
cache.paletteChecksum = cachePaletteChecksum; cache.paletteChecksum = cachePaletteChecksum;
@ -950,8 +961,12 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
std::optional<QString> InitialLoadThemeUsingKey(FileKey key) { std::optional<QString> InitialLoadThemeUsingKey(FileKey key) {
auto read = readThemeUsingKey(key); auto read = readThemeUsingKey(key);
const auto result = read.object.pathAbsolute; 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() if (read.object.content.isEmpty()
|| !Window::Theme::Initialize(std::move(read))) { || !Window::Theme::Initialize(std::move(read))) {
DEBUG_LOG(("Theme: Could not initialized for key: %1").arg(key));
return std::nullopt; return std::nullopt;
} }
return result; return result;
@ -961,13 +976,23 @@ void writeTheme(const Window::Theme::Saved &saved) {
using namespace Window::Theme; using namespace Window::Theme;
if (_themeKeyLegacy) { if (_themeKeyLegacy) {
DEBUG_LOG(("Theme: skipping write, because legacy: %1"
).arg(_themeKeyLegacy));
return; return;
} }
auto &themeKey = IsNightMode() auto &themeKey = IsNightMode()
? _themeKeyNight ? _themeKeyNight
: _themeKeyDay; : _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 (saved.object.content.isEmpty()) {
if (themeKey) { if (themeKey) {
if (IsNightMode()) {
DEBUG_LOG(("Theme: cleared for night mode."));
SetNightModeValue(false);
}
ClearKey(themeKey, _basePath); ClearKey(themeKey, _basePath);
themeKey = 0; themeKey = 0;
writeSettings(); writeSettings();
@ -1032,17 +1057,36 @@ void InitialLoadTheme() {
: (Window::Theme::IsNightMode() : (Window::Theme::IsNightMode()
? _themeKeyNight ? _themeKeyNight
: _themeKeyDay); : _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 (!key) {
if (Window::Theme::IsNightMode()) {
DEBUG_LOG(("Theme: zero key for night mode."));
Window::Theme::SetNightModeValue(false);
}
return; return;
} else if (const auto path = InitialLoadThemeUsingKey(key)) { } else if (const auto path = InitialLoadThemeUsingKey(key)) {
DEBUG_LOG(("Theme: loaded with result: %1").arg(*path));
if (_themeKeyLegacy) { if (_themeKeyLegacy) {
Window::Theme::SetNightModeValue(*path Window::Theme::SetNightModeValue(*path
== Window::Theme::NightThemePath()); == Window::Theme::NightThemePath());
(Window::Theme::IsNightMode() (Window::Theme::IsNightMode()
? _themeKeyNight ? _themeKeyNight
: _themeKeyDay) = base::take(_themeKeyLegacy); : _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 { } else {
DEBUG_LOG(("Theme: could not load, clearing.."));
clearTheme(); clearTheme();
} }
} }

View file

@ -154,7 +154,6 @@ bool readNameAndValue(const char *&from, const char *end, QLatin1String *outName
enum class SetResult { enum class SetResult {
Ok, Ok,
Bad,
NotFound, NotFound,
}; };
SetResult setColorSchemeValue( SetResult setColorSchemeValue(
@ -202,7 +201,7 @@ SetResult setColorSchemeValue(
} else { } else {
LOG(("Theme Error: Unexpected internal error.")); LOG(("Theme Error: Unexpected internal error."));
} }
return SetResult::Bad; Unexpected("Value after palette.setColor().");
} }
bool loadColorScheme( bool loadColorScheme(
@ -215,9 +214,7 @@ bool loadColorScheme(
value = unsupported.value(value, value); value = unsupported.value(value, value);
auto result = setColorSchemeValue(name, value, colorizer, out); auto result = setColorSchemeValue(name, value, colorizer, out);
if (result == SetResult::Bad) { if (result == SetResult::NotFound) {
return false;
} else if (result == SetResult::NotFound) {
unsupported.insert(name, value); unsupported.insert(name, value);
} }
return true; return true;
@ -302,6 +299,7 @@ bool LoadTheme(
return false; return false;
} }
if (!loadColorScheme(schemeContent, paletteColorizer, out)) { if (!loadColorScheme(schemeContent, paletteColorizer, out)) {
DEBUG_LOG(("Theme: Could not loadColorScheme."));
return false; return false;
} }
if (!out) { if (!out) {
@ -311,6 +309,7 @@ bool LoadTheme(
auto backgroundTiled = false; auto backgroundTiled = false;
auto backgroundContent = QByteArray(); auto backgroundContent = QByteArray();
if (!loadBackground(file, &backgroundContent, &backgroundTiled)) { if (!loadBackground(file, &backgroundContent, &backgroundTiled)) {
DEBUG_LOG(("Theme: Could not loadBackground."));
return false; return false;
} }
@ -347,6 +346,7 @@ bool LoadTheme(
} else { } else {
// Looks like it is not a .zip theme. // Looks like it is not a .zip theme.
if (!loadColorScheme(editedPalette.value_or(content), paletteColorizer, out)) { if (!loadColorScheme(editedPalette.value_or(content), paletteColorizer, out)) {
DEBUG_LOG(("Theme: Could not loadColorScheme from non-zip."));
return false; return false;
} }
if (!out) { if (!out) {
@ -422,6 +422,7 @@ bool InitializeFromSaved(Saved &&saved) {
const auto colorizer = ColorizerForTheme(saved.object.pathAbsolute); const auto colorizer = ColorizerForTheme(saved.object.pathAbsolute);
if (!LoadTheme(saved.object.content, colorizer, editing, &saved.cache)) { if (!LoadTheme(saved.object.content, colorizer, editing, &saved.cache)) {
DEBUG_LOG(("Theme: Could not load from saved."));
return false; return false;
} }
if (editing) { if (editing) {
@ -1235,6 +1236,7 @@ bool Initialize(Saved &&saved) {
Background()->setThemeObject(saved.object); Background()->setThemeObject(saved.object);
return true; return true;
} }
DEBUG_LOG(("Theme: Could not initialize from saved."));
return false; return false;
} }
@ -1464,6 +1466,7 @@ bool ReadPaletteValues(const QByteArray &content, Fn<bool(QLatin1String name, QL
auto name = QLatin1String(""); auto name = QLatin1String("");
auto value = QLatin1String(""); auto value = QLatin1String("");
if (!readNameAndValue(from, end, &name, &value)) { if (!readNameAndValue(from, end, &name, &value)) {
DEBUG_LOG(("Theme: Could not readNameAndValue."));
return false; return false;
} }
if (name.size() == 0) { // End of content reached. if (name.size() == 0) { // End of content reached.

2
cmake

@ -1 +1 @@
Subproject commit 2827dd851edfca602cbb98cae6b3dbd123c4aa39 Subproject commit c94b46f2fd99341a8217fe74b250bd0d0827b060