feat(users/Profpatsch/alacritty): add dbus theme change
For trying out a bunch of themes in quick succession. Also note down a few of the cooler themes. Change-Id: I0da80cc0945dba03d3592f28f4c34df4b5969e82 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12893 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
parent
1ec787a417
commit
c283116c2e
2 changed files with 56 additions and 4 deletions
|
@ -20,7 +20,7 @@ const { setTimeout } = require('node:timers/promises');
|
||||||
const { promisify } = require('util');
|
const { promisify } = require('util');
|
||||||
const { pseudoRandomBytes } = require('crypto');
|
const { pseudoRandomBytes } = require('crypto');
|
||||||
const { execFile } = require('node:child_process');
|
const { execFile } = require('node:child_process');
|
||||||
const { readdir } = require('fs/promises');
|
const { readdir, realpath, access } = require('fs/promises');
|
||||||
|
|
||||||
// NB: this code is like 80% copilot generated, and seriously missing error handling.
|
// NB: this code is like 80% copilot generated, and seriously missing error handling.
|
||||||
// It might break at any time, but for now it seems to work lol.
|
// It might break at any time, but for now it seems to work lol.
|
||||||
|
@ -33,8 +33,8 @@ let darkThemeName = process.argv[3] ?? 'alacritty_0_12';
|
||||||
let lightThemeName = process.argv[4] ?? 'dayfox';
|
let lightThemeName = process.argv[4] ?? 'dayfox';
|
||||||
assert(themeDir, 'Theme directory is required');
|
assert(themeDir, 'Theme directory is required');
|
||||||
|
|
||||||
const darkTheme = getThemePathSync(darkThemeName);
|
let darkTheme = getThemePathSync(darkThemeName);
|
||||||
const lightTheme = getThemePathSync(lightThemeName);
|
let lightTheme = getThemePathSync(lightThemeName);
|
||||||
|
|
||||||
console.log(`Dark theme: ${darkTheme}`);
|
console.log(`Dark theme: ${darkTheme}`);
|
||||||
console.log(`Light theme: ${lightTheme}`);
|
console.log(`Light theme: ${lightTheme}`);
|
||||||
|
@ -291,8 +291,10 @@ if (!process.env.XDG_CONFIG_HOME) {
|
||||||
process.env.XDG_CONFIG_HOME = process.env.HOME + '/.config';
|
process.env.XDG_CONFIG_HOME = process.env.HOME + '/.config';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** get the path of the theme config file synchronously
|
||||||
|
*
|
||||||
* @param {string} theme
|
* @param {string} theme
|
||||||
|
* @returns {string}
|
||||||
* */
|
* */
|
||||||
function getThemePathSync(theme) {
|
function getThemePathSync(theme) {
|
||||||
const path = `${themeDir}/${theme}.toml`;
|
const path = `${themeDir}/${theme}.toml`;
|
||||||
|
@ -301,6 +303,22 @@ function getThemePathSync(theme) {
|
||||||
return absolutePath;
|
return absolutePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** get the path of the theme config file
|
||||||
|
*
|
||||||
|
* @param {string} theme
|
||||||
|
* @returns {Promise<string | null>} null if the theme file does not exist
|
||||||
|
* */
|
||||||
|
async function getThemePath(theme) {
|
||||||
|
const path = `${themeDir}/${theme}.toml`;
|
||||||
|
try {
|
||||||
|
const absolutePath = await realpath(path);
|
||||||
|
await access(absolutePath);
|
||||||
|
return absolutePath;
|
||||||
|
} catch (err) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** write new color scheme
|
/** write new color scheme
|
||||||
*
|
*
|
||||||
* @param {'prefer-dark' | 'prefer-light'} cs
|
* @param {'prefer-dark' | 'prefer-light'} cs
|
||||||
|
@ -407,6 +425,10 @@ async function exportColorSchemeDbusInterface() {
|
||||||
name: 'de.profpatsch.alacritty.ColorScheme',
|
name: 'de.profpatsch.alacritty.ColorScheme',
|
||||||
methods: {
|
methods: {
|
||||||
SetColorScheme: ['s', ''],
|
SetColorScheme: ['s', ''],
|
||||||
|
// first argument: 'dark' | 'light'
|
||||||
|
// second argument: the theme name (one of the themes in the theme directory)
|
||||||
|
// will only be applied during the run-time of this program, and reset on restart
|
||||||
|
SetColorSchemeTheme: ['ss', ''],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -416,6 +438,28 @@ async function exportColorSchemeDbusInterface() {
|
||||||
console.log(`SetColorScheme called with ${cs}`);
|
console.log(`SetColorScheme called with ${cs}`);
|
||||||
writeAlacrittyColorConfigIfDifferent(cs);
|
writeAlacrittyColorConfigIfDifferent(cs);
|
||||||
},
|
},
|
||||||
|
SetColorSchemeTheme: async function (
|
||||||
|
/** @type {string} */ cs,
|
||||||
|
/** @type {string} */ theme,
|
||||||
|
) {
|
||||||
|
console.log(`SetColorSchemeTheme called with ${cs} and theme ${theme}`);
|
||||||
|
if (cs !== 'dark' && cs !== 'light') {
|
||||||
|
console.warn(`Invalid color scheme ${cs}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const themePath = await getThemePath(theme);
|
||||||
|
if (themePath === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cs === 'dark') {
|
||||||
|
darkTheme = themePath;
|
||||||
|
}
|
||||||
|
if (cs === 'light') {
|
||||||
|
lightTheme = themePath;
|
||||||
|
}
|
||||||
|
console.log(`Setting color scheme ${cs} with theme ${themePath}`);
|
||||||
|
writeAlacrittyColorConfig(cs === 'dark' ? 'prefer-dark' : 'prefer-light');
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
ayu_mirage
|
||||||
|
catppuccin
|
||||||
|
gruvbox_dark
|
||||||
|
inferno
|
||||||
|
monokai_pro
|
||||||
|
|
||||||
|
|
||||||
|
night_owlish_light
|
Loading…
Reference in a new issue