Feat: Custom modules can now be created through a JSON file. (#887)

* Feat: Custom modules can now be created through a JSON file.

* Added the ability to consume labels and icons.

* Add all properties but styling.

* Wrap up implementation.

* Rename custom modules to basic modules to make way for new actually custom modules.
This commit is contained in:
Jas Singh
2025-04-07 01:52:39 -07:00
committed by GitHub
parent 483facfa56
commit 93235f0fb1
31 changed files with 820 additions and 377 deletions

View File

@@ -12,9 +12,20 @@ import { Astal, Gdk, Gtk } from 'astal/gtk3';
import AstalApps from 'gi://AstalApps?version=0.1';
import { exec, execAsync } from 'astal/process';
import AstalNotifd from 'gi://AstalNotifd?version=0.1';
import { Primitive } from './types/utils';
const notifdService = AstalNotifd.get_default();
/**
* Checks if a value is a primitive type.
*
* @param value - The value to check
* @returns True if the value is a primitive (null, undefined, string, number, boolean, symbol, or bigint)
*/
export function isPrimitive(value: unknown): value is Primitive {
return value === null || (typeof value !== 'object' && typeof value !== 'function');
}
/**
* Handles errors by throwing a new Error with a message.
*
@@ -102,7 +113,8 @@ export function icon(name: string | null, fallback = icons.missing): string {
if (lookUpIcon(icon)) return icon;
console.log(`no icon substitute "${icon}" for "${name}", fallback: "${fallback}"`);
console.log(`No icon substitute "${icon}" for "${name}", fallback: "${fallback}"`);
return fallback;
}
@@ -154,9 +166,10 @@ export async function sh(cmd: string | string[]): Promise<string> {
*
* @returns An array of JSX elements, one for each monitor.
*/
export function forMonitors(widget: (monitor: number) => JSX.Element): JSX.Element[] {
export async function forMonitors(widget: (monitor: number) => Promise<JSX.Element>): Promise<JSX.Element[]> {
const n = Gdk.Display.get_default()?.get_n_monitors() || 1;
return range(n, 0).flatMap(widget);
return Promise.all(range(n, 0).map(widget));
}
/**