Implemented Wallpaper Selector and Matugen's Wallpaper based auto-theming. (#73)
* Implement matugen - WIP * Added matugen * Add types and cleanup code * Matugen implementation updates and added more options such as scheme and contrast. * Code cleanup and matugen settings renamed for clarity. * Makon maroon a primary matugen color. * Updates to handle variations of matugen colors * Finalizing matugen and wrapping up variations. * Minor styling updates of the settings dialog. * Do a swww dependency check. * Dependency logic update * Switch shouldn't double trigger notifications now when checking dependency. * Logic was inverted * Add matugen to dependency checker. * Fixed dependency checking conditional * Update dependency list in readme and check for matugen before doing matugen operations * Styling fixes * OSD Fix * Remove unused code from wallpaper service. * Color fixes for matugen. * Nix updates for new dependencies * Change default wallpaper to empty. * Added custom notification service for startup, cleaned up code and updated readme.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
/* eslint-disable max-len */
|
||||
import { type Opt } from "lib/option"
|
||||
import options from "options"
|
||||
import { bash, dependencies } from "lib/utils"
|
||||
import options from "options";
|
||||
import { bash, dependencies } from "lib/utils";
|
||||
import { MatugenColors } from "lib/types/options";
|
||||
import { initializeTrackers } from "./options_trackers";
|
||||
import { generateMatugenColors, replaceHexValues } from "./matugen/index";
|
||||
|
||||
const deps = [
|
||||
"font",
|
||||
@@ -10,53 +11,58 @@ const deps = [
|
||||
"bar.position",
|
||||
"bar.battery.charging",
|
||||
"bar.battery.blocks",
|
||||
]
|
||||
];
|
||||
|
||||
const $ = (name: string, value: string | Opt<any>) => `$${name}: ${value};`
|
||||
|
||||
function extractVariables(theme: any, prefix: string = ""): string[] {
|
||||
let result: string[] = [];
|
||||
function extractVariables(theme: typeof options.theme, prefix = "", matugenColors: MatugenColors | undefined) {
|
||||
let result = [] as string[];
|
||||
for (let key in theme) {
|
||||
if (theme.hasOwnProperty(key)) {
|
||||
const value = theme[key];
|
||||
|
||||
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 === 'object' && value !== null && !Array.isArray(value)) {
|
||||
// Check if the object contains an Opt value or is a nested object
|
||||
if (typeof value.value !== 'undefined') {
|
||||
result.push($(`${newPrefix}`, `${value.value}`));
|
||||
result.push(`$${newPrefix}: ${replacedValue};`);
|
||||
} else {
|
||||
result = result.concat(extractVariables(value, newPrefix));
|
||||
result = result.concat(extractVariables(value, newPrefix, matugenColors));
|
||||
}
|
||||
} else if (typeof value === 'function' && value.name === 'opt') {
|
||||
result.push($(`${newPrefix}`, value));
|
||||
result.push(`$${newPrefix}: ${replacedValue};`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const variables = () => [
|
||||
...extractVariables(options.theme),
|
||||
];
|
||||
|
||||
async function resetCss() {
|
||||
if (!dependencies("sass"))
|
||||
return
|
||||
if (!dependencies("sass")) return;
|
||||
|
||||
try {
|
||||
const matugenColors = await generateMatugenColors();
|
||||
|
||||
const variables = [
|
||||
...extractVariables(options.theme, '', matugenColors),
|
||||
];
|
||||
|
||||
const vars = `${TMP}/variables.scss`
|
||||
const css = `${TMP}/main.css`
|
||||
const scss = `${TMP}/entry.scss`
|
||||
const localScss = `${App.configDir}/scss/main.scss`;
|
||||
|
||||
await Utils.writeFile(variables().join("\n"), vars)
|
||||
const imports = [vars].map(f => `@import '${f}';`)
|
||||
const themeVariables = variables;
|
||||
const integratedVariables = themeVariables;
|
||||
|
||||
const imports = [vars].map(f => `@import '${f}';`);
|
||||
|
||||
await Utils.writeFile(integratedVariables.join("\n"), vars);
|
||||
|
||||
let mainScss = Utils.readFile(localScss);
|
||||
mainScss = `${imports}\n${mainScss}`;
|
||||
|
||||
await Utils.writeFile(mainScss, scss)
|
||||
await Utils.writeFile(mainScss, scss);
|
||||
|
||||
await bash(`sass --load-path=${App.configDir}/scss/ ${scss} ${css}`);
|
||||
|
||||
@@ -64,10 +70,12 @@ async function resetCss() {
|
||||
} catch (error) {
|
||||
error instanceof Error
|
||||
? logError(error)
|
||||
: console.error(error)
|
||||
: console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
Utils.monitorFile(`${App.configDir}/scss/style`, resetCss)
|
||||
options.handler(deps, resetCss)
|
||||
await resetCss()
|
||||
initializeTrackers(resetCss);
|
||||
|
||||
Utils.monitorFile(`${App.configDir}/scss/style`, resetCss);
|
||||
options.handler(deps, resetCss);
|
||||
await resetCss();
|
||||
|
||||
Reference in New Issue
Block a user