Commit a26380d5 authored by Florian Müllner's avatar Florian Müllner

user-theme: Clarify some code

Commit 2582ab accidentally pointed out that the current theme loading code
obfuscates which directories are searched for themes. Rewrite it with modern
JS features to make it more obvious.

!60
parent ab334d95
Pipeline #65223 passed with stages
in 46 seconds
......@@ -30,37 +30,29 @@ class ThemeManager {
}
_changeTheme() {
let _stylesheet = null;
let _themeName = this._settings.get_string(SETTINGS_KEY);
if (_themeName) {
let _userCssStylesheet = GLib.build_filenamev([
GLib.get_home_dir(), '.themes', _themeName, 'gnome-shell', 'gnome-shell.css'
]);
let file = Gio.file_new_for_path(_userCssStylesheet);
if (file.query_exists(null))
_stylesheet = _userCssStylesheet;
else {
let sysdirs = GLib.get_system_data_dirs();
sysdirs.unshift(GLib.get_user_data_dir());
for (let i = 0; i < sysdirs.length; i++) {
_userCssStylesheet = GLib.build_filenamev([
sysdirs[i], 'themes', _themeName, 'gnome-shell', 'gnome-shell.css'
]);
let file = Gio.file_new_for_path(_userCssStylesheet);
if (file.query_exists(null)) {
_stylesheet = _userCssStylesheet;
break;
}
}
}
let stylesheet = null;
let themeName = this._settings.get_string(SETTINGS_KEY);
if (themeName) {
let stylesheetPaths = [
[GLib.get_home_dir(), '.themes'],
[GLib.get_user_data_dir(), 'themes'],
...GLib.get_system_data_dirs().map(dir => [dir, 'themes'])
].map(themeDir => GLib.build_filenamev([
...themeDir, themeName, 'gnome-shell', 'gnome-shell.css'
]));
stylesheet = stylesheetPaths.find(path => {
let file = Gio.file_new_for_path(path);
return file.query_exists(null);
});
}
if (_stylesheet)
global.log(`loading user theme: ${_stylesheet}`);
if (stylesheet)
global.log(`loading user theme: ${stylesheet}`);
else
global.log('loading default theme (Adwaita)');
Main.setThemeStylesheet(_stylesheet);
Main.setThemeStylesheet(stylesheet);
Main.loadTheme();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment