forked from Shinonome/dots-hyprland
icons: add regex substitutions (#487)
This commit is contained in:
@@ -125,7 +125,13 @@ let configOptions = {
|
|||||||
'wps': "wps-office2019-kprometheus",
|
'wps': "wps-office2019-kprometheus",
|
||||||
'wpsoffice': "wps-office2019-kprometheus",
|
'wpsoffice': "wps-office2019-kprometheus",
|
||||||
'': "image-missing",
|
'': "image-missing",
|
||||||
}
|
},
|
||||||
|
regexSubstitutions: [
|
||||||
|
{
|
||||||
|
regex: /^steam_app_(\d+)$/,
|
||||||
|
replace: "steam_icon_$1",
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
'keybinds': {
|
'keybinds': {
|
||||||
// Format: Mod1+Mod2+key. CaSe SeNsItIvE!
|
// Format: Mod1+Mod2+key. CaSe SeNsItIvE!
|
||||||
|
|||||||
@@ -6,8 +6,23 @@ export function iconExists(iconName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function substitute(str) {
|
export function substitute(str) {
|
||||||
if(userOptions.icons.substitutions[str]) return userOptions.icons.substitutions[str];
|
// Normal substitutions
|
||||||
|
if (userOptions.icons.substitutions[str])
|
||||||
|
return userOptions.icons.substitutions[str];
|
||||||
|
|
||||||
if (!iconExists(str)) str = str.toLowerCase().replace(/\s+/g, '-'); // Turn into kebab-case
|
// Regex substitutions
|
||||||
|
for (let i = 0; i < userOptions.icons.regexSubstitutions.length; i++) {
|
||||||
|
const substitution = userOptions.icons.regexSubstitutions[i];
|
||||||
|
const replacedName = str.replace(
|
||||||
|
substitution.regex,
|
||||||
|
substitution.replace,
|
||||||
|
);
|
||||||
|
if (replacedName != str) return replacedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guess: convert to kebab case
|
||||||
|
if (!iconExists(str)) str = str.toLowerCase().replace(/\s+/g, "-");
|
||||||
|
|
||||||
|
// Original string
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ const { Box, Revealer } = Widget;
|
|||||||
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
||||||
import { getAllFiles, searchIcons } from './icons.js'
|
import { getAllFiles, searchIcons } from './icons.js'
|
||||||
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
|
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
|
||||||
|
import { substitute } from '../.miscutils/icons.js';
|
||||||
|
|
||||||
const icon_files = userOptions.icons.searchPaths.map(e => getAllFiles(e)).flat(1)
|
const icon_files = userOptions.icons.searchPaths.map(e => getAllFiles(e)).flat(1)
|
||||||
|
|
||||||
@@ -24,25 +25,6 @@ function clearTimes() {
|
|||||||
timers = []
|
timers = []
|
||||||
}
|
}
|
||||||
|
|
||||||
function substitute(str) {
|
|
||||||
const subs = [
|
|
||||||
{ from: 'code-url-handler', to: 'visual-studio-code' },
|
|
||||||
{ from: 'Code', to: 'visual-studio-code' },
|
|
||||||
{ from: 'GitHub Desktop', to: 'github-desktop' },
|
|
||||||
{ from: 'wps', to: 'wps-office2019-kprometheus' },
|
|
||||||
{ from: 'gnome-tweaks', to: 'org.gnome.tweaks' },
|
|
||||||
{ from: 'Minecraft* 1.20.1', to: 'minecraft' },
|
|
||||||
{ from: '', to: 'image-missing' },
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const { from, to } of subs) {
|
|
||||||
if (from === str)
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ExclusiveWindow(client) {
|
function ExclusiveWindow(client) {
|
||||||
const fn = [
|
const fn = [
|
||||||
(client) => !(client !== null && client !== undefined),
|
(client) => !(client !== null && client !== undefined),
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default (overviewMonitor = 0) => {
|
|||||||
|
|
||||||
const iconName = substitute(c);
|
const iconName = substitute(c);
|
||||||
const appIcon = iconExists(iconName) ? Widget.Icon({
|
const appIcon = iconExists(iconName) ? Widget.Icon({
|
||||||
icon: substitute(c),
|
icon: iconName,
|
||||||
size: Math.min(w, h) * userOptions.overview.scale / 2.5,
|
size: Math.min(w, h) * userOptions.overview.scale / 2.5,
|
||||||
}) : MaterialIcon('terminal', 'gigantic', {
|
}) : MaterialIcon('terminal', 'gigantic', {
|
||||||
css: `font-size: ${Math.min(w, h) * userOptions.overview.scale / 2.5}px`,
|
css: `font-size: ${Math.min(w, h) * userOptions.overview.scale / 2.5}px`,
|
||||||
|
|||||||
Reference in New Issue
Block a user