chore(scripts/utils, scripts/style-handler): add filter() method, change stylesheet target directory

the `filter()` function can both filter a common array and at the same time, it can also filter an Accessor Array(Accessor<Array<T>> and return an Accessor when provided Array is an Accessor Array. Stylesheet directory changed to colorshell's cache dir, making sense, since it's a temporary file generated by the shell
This commit is contained in:
retrozinndev
2025-07-30 17:28:55 -03:00
parent 8e0bc424fd
commit ca187a26ed
3 changed files with 16 additions and 4 deletions
+2 -2
View File
@@ -8,8 +8,8 @@ import Gio from "gi://Gio?version=2.0";
const monitoringPaths = [ "./scripts", "./window", "./app.ts", "env.d.ts" ];
export function restartInstance(instanceName?: string): void {
execAsync(`astal -q ${ instanceName ?? App.instanceName ?? "astal" }`);
export function restartInstance(): void {
execAsync(`astal -q ${ App.instanceName ?? "astal" }`);
Gio.Subprocess.new(
( uwsmIsActive ?
[ "uwsm", "app", "--", "ags", "run" ]
+3 -1
View File
@@ -12,9 +12,11 @@ import GLib from "gi://GLib?version=2.0";
export class Stylesheet {
private static instance: Stylesheet;
#watchDelay: (AstalIO.Time|undefined);
#outputPath = Gio.File.new_for_path(`${GLib.get_user_state_dir()}/ags/style`);
#outputPath = Gio.File.new_for_path(`${GLib.get_user_cache_dir()}/colorshell/style`);
#styles = [ "./style", "./style.scss" ];
public get stylePath() { return this.#outputPath.get_path()!; }
public async compileSass(): Promise<void> {
console.log("Stylesheet: Compiling Sass");
+11 -1
View File
@@ -6,6 +6,7 @@ import { getSymbolicIcon } from "./apps";
import GLib from "gi://GLib?version=2.0";
import Gio from "gi://Gio?version=2.0";
import Xdp from "gi://Xdp?version=1.0";
/** gnim doesn't export this, so we need to do it again */
@@ -13,9 +14,9 @@ export type WidgetNodeType = Array<JSX.Element> | JSX.Element | number | string
export const decoder = new TextDecoder("utf-8"),
encoder = new TextEncoder();
export const time = createPoll(GLib.DateTime.new_now_local(), 500, () =>
GLib.DateTime.new_now_local());
export const XdgPortal = Xdp.Portal.new();
export function getHyprlandInstanceSig(): (string|null) {
return GLib.getenv("HYPRLAND_INSTANCE_SIGNATURE");
@@ -155,6 +156,15 @@ export function transformWidget<ValueType = unknown>(
: fn(v));
}
export function filter<ValueType = unknown, FilterReturnType = unknown>(
v: Accessor<Array<ValueType>>|Array<ValueType>,
fn: (v: ValueType, i: number, array: Array<ValueType>) => FilterReturnType
): Array<ValueType>|Accessor<Array<ValueType>> {
return ((v instanceof Accessor) ?
v(v => v.filter((it, i, arr) => fn(it, i, arr)))
: v.filter((it, i, arr) => fn(it, i, arr)));
}
export function makeDirectory(dir: string): void {
execAsync([ "mkdir", "-p", dir ]);
}