Use own gtk theme finder
This commit is contained in:
parent
9208d42007
commit
b3896c047e
|
@ -20,7 +20,6 @@
|
|||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@jakejarrett/gtk-theme": "^1.1.2",
|
||||
"camelcase": "^5.0.0",
|
||||
"electron-store": "^2.0.0",
|
||||
"freedesktop-icons": "^0.1.0",
|
||||
|
|
82
utils/gtk-theme/index.js
Normal file
82
utils/gtk-theme/index.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const ini = require('ini');
|
||||
|
||||
const gtkIniPath = path.join(
|
||||
process.env.HOME,
|
||||
process.env.XDG_CONFIG_HOME || '.config',
|
||||
'gtk-3.0',
|
||||
'settings.ini',
|
||||
);
|
||||
|
||||
let gtk;
|
||||
try {
|
||||
gtk = ini.parse(fs.readFileSync(gtkIniPath, 'utf-8'));
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
|
||||
let themeName = 'Adwaita';
|
||||
let iconThemeNames = [ 'Adwaita', 'hicolor' ];
|
||||
|
||||
if (gtk) {
|
||||
iconThemeNames = [
|
||||
gtk.Settings['gtk-icon-theme-name'],
|
||||
gtk.Settings['gtk-fallback-icon-theme'],
|
||||
'hicolor',
|
||||
];
|
||||
themeName = gtk.Settings['gtk-theme-name'];
|
||||
}
|
||||
|
||||
const themePaths = [
|
||||
path.join(
|
||||
'/',
|
||||
'usr',
|
||||
'share',
|
||||
'themes',
|
||||
),
|
||||
path.join(
|
||||
process.env.HOME,
|
||||
process.env.XDG_CONFIG_HOME || '.themes',
|
||||
),
|
||||
path.join(
|
||||
process.env.HOME,
|
||||
'.local',
|
||||
'share',
|
||||
process.env.XDG_CONFIG_HOME || '.themes',
|
||||
),
|
||||
];
|
||||
|
||||
let css = '';
|
||||
|
||||
for (const themePath of themePaths) {
|
||||
const themeNamePath = path.join(themePath, themeName);
|
||||
|
||||
let dir;
|
||||
|
||||
try {
|
||||
dir = fs.readdirSync(themeNamePath);
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
try {
|
||||
css = fs.readFileSync(path.join(themeNamePath, 'gtk-3.0', 'gtk.css'), 'utf8');
|
||||
break;
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
iconThemeNames,
|
||||
css,
|
||||
};
|
24
utils/theme/default-colors.json
Normal file
24
utils/theme/default-colors.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"themeFgColor": "#eff0f1",
|
||||
"themeTextColor": "#eff0f1",
|
||||
"themeBgColor": "#31363b",
|
||||
"themeBaseColor": "#232629",
|
||||
"themeSelectedBgColor": "#3daee9",
|
||||
"themeSelectedFgColor": "#eff0f1",
|
||||
"insensitiveBgColor": "#2d3136",
|
||||
"insensitiveFgColor": "rgba(216, 218, 221, 0.35)",
|
||||
"insensitiveBaseColor": "rgba(216, 218, 221, 0.35)",
|
||||
"themeUnfocusedFgColor": "#eff0f1",
|
||||
"themeUnfocusedTextColor": "#eff0f1",
|
||||
"themeUnfocusedBgColor": "#31363b",
|
||||
"themeUnfocusedBaseColor": "#232629",
|
||||
"themeUnfocusedSelectedBgColor": "rgba(61, 174, 233, 0.5)",
|
||||
"themeUnfocusedSelectedFgColor": "#eff0f1",
|
||||
"borders": "#616569",
|
||||
"unfocusedBorders": "#616569",
|
||||
"insensitiveBorders": "rgba(88, 92, 95, 0.35)",
|
||||
"warningColor": "#f67400",
|
||||
"errorColor": "#da4453",
|
||||
"successColor": "#27ae60",
|
||||
"contentViewBg": "#232629"
|
||||
}
|
|
@ -1,46 +1,15 @@
|
|||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const ini = require('ini');
|
||||
|
||||
const { theme } = require('@jakejarrett/gtk-theme');
|
||||
const camelCase = require('camelcase');
|
||||
|
||||
const colors = {};
|
||||
const theme = require('../gtk-theme');
|
||||
|
||||
const colors = require('./default-colors.json');
|
||||
|
||||
theme.css.replace(/@define-color\s+([\w_]+?)\s+(.+?);/g, (_, name, value) => {
|
||||
colors[camelCase(name)] = value;
|
||||
});
|
||||
|
||||
const gtkIniPath = path.join(
|
||||
process.env.HOME,
|
||||
process.env.XDG_CONFIG_HOME || '.config',
|
||||
'gtk-3.0',
|
||||
'settings.ini',
|
||||
);
|
||||
|
||||
const iconThemeNames = (() => {
|
||||
let gtk;
|
||||
try {
|
||||
gtk = ini.parse(fs.readFileSync(gtkIniPath, 'utf-8'));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (gtk) {
|
||||
return [
|
||||
gtk.Settings['gtk-icon-theme-name'],
|
||||
gtk.Settings['gtk-fallback-icon-theme'],
|
||||
'hicolor',
|
||||
];
|
||||
}
|
||||
|
||||
return [ 'Adwaita', 'hicolor' ];
|
||||
})();
|
||||
|
||||
module.exports = {
|
||||
name: theme.theme_name,
|
||||
iconThemeNames,
|
||||
iconThemeNames: theme.iconThemeNames,
|
||||
colors,
|
||||
};
|
||||
|
|
|
@ -79,11 +79,6 @@
|
|||
dependencies:
|
||||
arrify "^1.0.1"
|
||||
|
||||
"@jakejarrett/gtk-theme@^1.1.2":
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@jakejarrett/gtk-theme/-/gtk-theme-1.1.2.tgz#f2c291d43476f4f5b42798cb6be276207f6791c9"
|
||||
integrity sha512-oZyD9j81d1zbL+BY8WvI1LKes+bHti3qTHrv3cFjL5pDSulwBHtX6Q1tCdGasKVNiE6L9KOgnjKCSIIElQgLKg==
|
||||
|
||||
"@ladjs/time-require@^0.1.4":
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/@ladjs/time-require/-/time-require-0.1.4.tgz#5c615d75fd647ddd5de9cf6922649558856b21a1"
|
||||
|
|
Loading…
Reference in New Issue
Block a user