From a26380d56e0f73bd34bf18c7e17f3fc9dbbbd7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 3 Mar 2019 05:34:17 +0100 Subject: [PATCH] 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. https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/60 --- extensions/user-theme/extension.js | 44 ++++++++++++------------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/extensions/user-theme/extension.js b/extensions/user-theme/extension.js index 1a718d19..d00c0774 100644 --- a/extensions/user-theme/extension.js +++ b/extensions/user-theme/extension.js @@ -30,37 +30,29 @@ class ThemeManager { } _changeTheme() { - let _stylesheet = null; - let _themeName = this._settings.get_string(SETTINGS_KEY); + 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; - } - } - } + 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(); } }