launcher: fix random wallpaper + add random scheme

Also allow mixed case for scheme and wallpaper suboptions
This commit is contained in:
2 * r + 2 * t 2025-03-04 23:47:30 +11:00
parent 35364193e3
commit 3e10adce74

View file

@ -91,26 +91,13 @@ const actions = (mode: Variable<Mode>, entry: Widget.Entry): ActionMap => ({
icon: "palette", icon: "palette",
name: "Scheme", name: "Scheme",
description: "Change the current colour scheme", description: "Change the current colour scheme",
action: (...args) => { action: () => autocomplete(entry, "scheme"),
// If no args, autocomplete cmd
if (args.length === 0) return autocomplete(entry, "scheme");
execAsync(`caelestia scheme ${args[0]}`).catch(console.error);
close();
},
}, },
wallpaper: { wallpaper: {
icon: "image", icon: "image",
name: "Wallpaper", name: "Wallpaper",
description: "Change the current wallpaper", description: "Change the current wallpaper",
action: (...args) => { action: () => autocomplete(entry, "wallpaper"),
// If no args, autocomplete cmd
if (args.length === 0) return autocomplete(entry, "wallpaper");
if (args[0] === "random") execAsync("caelestia wallpaper").catch(console.error);
else execAsync(`caelestia wallpaper -f ${args[0]}`).catch(console.error);
close();
},
}, },
todo: { todo: {
icon: "checklist", icon: "checklist",
@ -289,7 +276,7 @@ export default class Actions extends Widget.Box implements LauncherContent {
updateContent(search: string): void { updateContent(search: string): void {
this.#content.foreach(c => c.destroy()); this.#content.foreach(c => c.destroy());
const args = search.split(" "); const args = search.split(" ");
const action = args[0].slice(1); const action = args[0].slice(1).toLowerCase();
if (action === "scheme") { if (action === "scheme") {
const scheme = args[1] ?? ""; const scheme = args[1] ?? "";
@ -306,7 +293,15 @@ export default class Actions extends Widget.Box implements LauncherContent {
} }
} }
handleActivate(): void { handleActivate(search: string): void {
const args = search.split(" ");
const action = args[0].slice(1).toLowerCase();
if ((action === "scheme" || action === "wallpaper") && args[1].toLowerCase() === "random") {
execAsync(`caelestia ${action}`).catch(console.error);
close();
}
this.#content.get_child_at_index(0)?.get_child()?.activate(); this.#content.get_child_at_index(0)?.get_child()?.activate();
} }
} }