From 31138ffd9348990fc3221352fc40d48dfcd59141 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 1 Mar 2025 19:08:15 +1100 Subject: launcher: scheme autocomplete --- src/modules/launcher/actions.tsx | 85 ++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 12 deletions(-) (limited to 'src/modules/launcher') diff --git a/src/modules/launcher/actions.tsx b/src/modules/launcher/actions.tsx index 52910ea..75f1092 100644 --- a/src/modules/launcher/actions.tsx +++ b/src/modules/launcher/actions.tsx @@ -1,4 +1,6 @@ import { Apps } from "@/services/apps"; +import type { IPalette } from "@/services/palette"; +import Schemes from "@/services/schemes"; import { notify } from "@/utils/system"; import { setupCustomTooltip, type FlowBox } from "@/utils/widgets"; import { execAsync, GLib, readFile, register, type Variable } from "astal"; @@ -19,6 +21,11 @@ interface ActionMap { [k: string]: IAction; } +const autocomplete = (entry: Widget.Entry, action: string) => { + entry.set_text(`${config.actionPrefix.get()}${action} `); + entry.set_position(-1); +}; + const actions = (mode: Variable, entry: Widget.Entry): ActionMap => ({ apps: { icon: "apps", @@ -62,27 +69,32 @@ const actions = (mode: Variable, entry: Widget.Entry): ActionMap => ({ description: "Change the current colour scheme", action: (...args) => { // If no args, autocomplete cmd - if (args.length === 0) { - entry.set_text(`${config.actionPrefix.get()}scheme `); - entry.set_position(-1); - return; - } + if (args.length === 0) return autocomplete(entry, "scheme"); execAsync(`caelestia scheme ${args[0]}`).catch(console.error); close(); }, }, + wallpaper: { + icon: "image", + name: "Wallpaper", + description: "Change the current wallpaper", + action: (...args) => { + // 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: { icon: "checklist", name: "Todo", description: "Create a todo in Todoist", action: (...args) => { // If no args, autocomplete cmd - if (args.length === 0) { - entry.set_text(`${config.actionPrefix.get()}todo `); - entry.set_position(-1); - return; - } + if (args.length === 0) return autocomplete(entry, "todo"); // If tod not installed, notify if (!GLib.find_program_in_path("tod")) { @@ -165,6 +177,47 @@ const Action = ({ args, icon, name, description, action }: IAction & { args: str ); +const Swatch = ({ colour }: { colour: string }) => ; + +const Scheme = ({ name, colours }: { name: string; colours: IPalette }) => ( + + + +); + @register() export default class Actions extends Widget.Box implements LauncherContent { #map: ActionMap; @@ -190,8 +243,16 @@ export default class Actions extends Widget.Box implements LauncherContent { updateContent(search: string): void { this.#content.foreach(c => c.destroy()); const args = search.split(" "); - for (const { target } of fuzzysort.go(args[0].slice(1), this.#list, { all: true })) - this.#content.add(); + const action = args[0].slice(1); + + if (action === "scheme") { + const scheme = args[1] ?? ""; + for (const { target } of fuzzysort.go(scheme, Object.keys(Schemes.get_default().map), { all: true })) + this.#content.add(); + } else { + for (const { target } of fuzzysort.go(action, this.#list, { all: true })) + this.#content.add(); + } } handleActivate(): void { -- cgit v1.2.3-freya