From d46b36860666583cd9645bfb1fa28d807973c324 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:37:43 +1100 Subject: schemes: update for scripts refactor --- src/modules/launcher/actions.tsx | 105 +++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 44 deletions(-) (limited to 'src/modules') diff --git a/src/modules/launcher/actions.tsx b/src/modules/launcher/actions.tsx index 0ded45f..c45273d 100644 --- a/src/modules/launcher/actions.tsx +++ b/src/modules/launcher/actions.tsx @@ -1,7 +1,6 @@ import { Apps } from "@/services/apps"; -import type { IPalette } from "@/services/palette"; import Palette from "@/services/palette"; -import Schemes from "@/services/schemes"; +import Schemes, { type Colours } from "@/services/schemes"; import Wallpapers from "@/services/wallpapers"; import { basename } from "@/utils/strings"; import { notify } from "@/utils/system"; @@ -30,6 +29,12 @@ const autocomplete = (entry: Widget.Entry, action: string) => { entry.set_position(-1); }; +const hasMode = (mode: "light" | "dark") => { + const scheme = Schemes.get_default().map[Palette.get_default().scheme]; + if (scheme.colours?.[mode]) return true; + return scheme.flavours?.[Palette.get_default().flavour ?? ""]?.colours?.[mode] !== undefined; +}; + const actions = (mode: Variable, entry: Widget.Entry): ActionMap => ({ apps: { icon: "apps", @@ -70,22 +75,22 @@ const actions = (mode: Variable, entry: Widget.Entry): ActionMap => ({ light: { icon: "light_mode", name: "Light", - description: "Change dynamic scheme to light mode", + description: "Change scheme to light mode", action: () => { execAsync(`caelestia wallpaper -T light -f ${STATE}/wallpaper/current`).catch(console.error); close(); }, - available: () => Palette.get_default().name === "dynamic", + available: () => hasMode("light"), }, dark: { icon: "dark_mode", name: "Dark", - description: "Change dynamic scheme to dark mode", + description: "Change scheme to dark mode", action: () => { execAsync(`caelestia wallpaper -T dark -f ${STATE}/wallpaper/current`).catch(console.error); close(); }, - available: () => Palette.get_default().name === "dynamic", + available: () => hasMode("dark"), }, scheme: { icon: "palette", @@ -244,44 +249,47 @@ const Action = ({ args, icon, name, description, action }: IAction & { args: str const Swatch = ({ colour }: { colour: string }) => ; -const Scheme = ({ name, colours }: { name: string; colours: IPalette }) => ( - - - -); + + + ); +}; const Wallpaper = ({ path, thumbnail }: { path: string; thumbnail?: string }) => ( @@ -334,8 +342,17 @@ export default class Actions extends Widget.Box implements LauncherContent { 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(); + const schemes = Object.values(Schemes.get_default().map) + .flatMap(s => (s.colours ? s.name : Object.values(s.flavours!).map(f => `${f.scheme}-${f.name}`))) + .filter(s => s !== undefined); + for (const { target } of fuzzysort.go(scheme, schemes, { all: true })) { + if (Schemes.get_default().map.hasOwnProperty(target)) + this.#content.add(); + else { + const [scheme, flavour] = target.split("-"); + this.#content.add(); + } + } } else if (action === "wallpaper") { const wallpaper = args[1] ?? ""; for (const { obj } of fuzzysort.go(wallpaper, Wallpapers.get_default().list, { all: true, key: "path" })) -- cgit v1.2.3-freya