Look for gtk settings.ini in all the expected places

This should help with loading system-level default theme.
Based on https://developer.gnome.org/gtk3/stable/GtkSettings.html, "Description".
This commit is contained in:
Tomasz Kontusz 2020-07-20 08:53:06 +02:00 committed by futpib
parent 54e1ce4a37
commit e710a65c7b
2 changed files with 39 additions and 14 deletions

View File

@ -34,6 +34,10 @@ const getIconWithFallback = async name => {
return getIconWithFallback(fallbacks.get(name)); return getIconWithFallback(fallbacks.get(name));
} }
if (!result) {
console.warn('icon missing', name);
}
cache.set(name, result); cache.set(name, result);
return result; return result;

View File

@ -4,31 +4,52 @@ const path = require('path');
const ini = require('ini'); const ini = require('ini');
const gtkIniPath = path.join( const gtkIniPaths = [];
gtkIniPaths.push('/etc/gtk-3.0/settings.ini');
if (process.env.XDG_CONFIG_DIRS) {
gtkIniPaths.push(...process.env.XDG_CONFIG_DIRS.split(':')
.map(dir => path.join(dir, 'gtk-3.0', 'settings.ini')));
}
gtkIniPaths.push(path.join(
process.env.HOME, process.env.HOME,
process.env.XDG_CONFIG_HOME || '.config', process.env.XDG_CONFIG_HOME || '.config',
'gtk-3.0', 'gtk-3.0',
'settings.ini', 'settings.ini',
); ));
let gtk; const gtkInis = [];
try { try {
gtk = ini.parse(fs.readFileSync(gtkIniPath, 'utf-8')); gtkIniPaths.forEach(path => {
const gtk = ini.parse(fs.readFileSync(path, 'utf-8'));
gtkInis.push(gtk);
});
} catch (error) { } catch (error) {
console.warn(error); if (error.code !== 'ENOENT') {
console.warn(error);
}
} }
let themeName = 'Adwaita'; let themeName = 'Adwaita';
let iconThemeNames = [ 'Adwaita', 'hicolor' ]; const iconThemeNames = [ 'Adwaita', 'hicolor' ];
if (gtk) { gtkInis.forEach(gtk => {
iconThemeNames = [ if (gtk && gtk.Settings) {
gtk.Settings['gtk-icon-theme-name'], if (gtk.Settings['gtk-icon-theme-name']) {
gtk.Settings['gtk-fallback-icon-theme'], iconThemeNames[0] = gtk.Settings['gtk-icon-theme-name'];
'hicolor', }
].filter(Boolean);
themeName = gtk.Settings['gtk-theme-name'] || themeName; if (gtk.Settings['gtk-fallback-icon-theme']) {
} iconThemeNames[1] = gtk.Settings['gtk-fallback-icon-theme'];
}
if (gtk.Settings['gtk-theme-name']) {
themeName = gtk.Settings['gtk-theme-name'];
}
}
});
const themePaths = [ const themePaths = [
path.join( path.join(