Added strict type checking to the project. (#236)

* Implement strict typing (WIP).

* changes

* Finish type checks

* Fix notification icon, matugen settings and update tsconfig.

* OSD Styling updates and added the ability to configure OSD duration.
This commit is contained in:
Jas Singh
2024-09-09 00:44:51 -07:00
committed by GitHub
parent 41dbc3829a
commit bb3b3dfdfb
56 changed files with 468 additions and 240 deletions

View File

@@ -1,8 +1,10 @@
import options from "options";
import { bash, dependencies } from "lib/utils";
import { MatugenColors } from "lib/types/options";
import { MatugenColors, RecursiveOptionsObject } from "lib/types/options";
import { initializeTrackers } from "./options_trackers";
import { generateMatugenColors, replaceHexValues } from "../services/matugen/index";
import { isHexColor, isOpt, isRecursiveOptionsObject } from "globals/variables";
import { Opt } from "lib/option";
const deps = [
"font",
@@ -13,27 +15,37 @@ const deps = [
"bar.battery.blocks",
];
function extractVariables(theme: typeof options.theme, prefix = "", matugenColors: MatugenColors | undefined) {
function extractVariables(
theme: RecursiveOptionsObject,
prefix = "",
matugenColors?: MatugenColors
): string[] {
let result = [] as string[];
for (let key in theme) {
if (theme.hasOwnProperty(key)) {
const value = theme[key];
if (!theme.hasOwnProperty(key)) {
continue;
}
const newPrefix = prefix ? `${prefix}-${key}` : key;
const value = theme[key];
const isColor = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value.value);
const replacedValue = isColor && matugenColors !== undefined ? replaceHexValues(value.value, matugenColors) : value.value;
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
if (typeof value.value !== 'undefined') {
result.push(`$${newPrefix}: ${replacedValue};`);
} else {
result = result.concat(extractVariables(value, newPrefix, matugenColors));
}
} else if (typeof value === 'function' && value.name === 'opt') {
result.push(`$${newPrefix}: ${replacedValue};`);
}
const newPrefix = prefix ? `${prefix}-${key}` : key;
const isColor = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value.value);
const replacedValue = isColor && matugenColors !== undefined ? replaceHexValues(value.value, matugenColors) : value.value;
if (typeof value === 'function') {
result.push(`$${newPrefix}: ${replacedValue};`);
continue;
}
if (typeof value !== 'object' || value === null || Array.isArray(value)) continue;
if (typeof value.value !== 'undefined') {
result.push(`$${newPrefix}: ${replacedValue};`);
} else {
result = result.concat(extractVariables(value as RecursiveOptionsObject, newPrefix, matugenColors));
}
}
return result;
}

View File

@@ -31,8 +31,8 @@
border-radius: if($osd-orientation =="vertical", 0em 0em $osd-radius $osd-radius, $osd-radius 0em 0em $osd-radius );
.osd-icon {
font-size: 2em;
padding: if($osd-orientation =="vertical", 0.2em 0em, 0em 0.2em);
font-size: 2.1em;
padding: if($osd-orientation =="vertical", 0.2em 0em, 0em 0.4em);
color: $osd-icon;
}
}