launcher: fix wallpaper categories compact mode

Also fix undef errors for wallpapers and scheme
This commit is contained in:
2 * r + 2 * t 2025-03-16 17:23:19 +11:00
parent 1287b7dece
commit 8f3b369e86

View file

@ -5,7 +5,7 @@ import Wallpapers, { type ICategory, type IWallpaper } from "@/services/wallpape
import { basename } from "@/utils/strings"; import { basename } from "@/utils/strings";
import { notify } from "@/utils/system"; import { notify } from "@/utils/system";
import { setupCustomTooltip, type FlowBox } from "@/utils/widgets"; import { setupCustomTooltip, type FlowBox } from "@/utils/widgets";
import { execAsync, GLib, readFile, register, type Variable } from "astal"; import { bind, execAsync, GLib, readFile, register, type Variable } from "astal";
import { Gtk, Widget } from "astal/gtk3"; import { Gtk, Widget } from "astal/gtk3";
import { launcher as config } from "config"; import { launcher as config } from "config";
import fuzzysort from "fuzzysort"; import fuzzysort from "fuzzysort";
@ -313,11 +313,20 @@ const Category = ({ path, wallpapers }: ICategory) => (
vertical={config.wallpaper.style.get() !== "compact"} vertical={config.wallpaper.style.get() !== "compact"}
className={`wallpaper ${config.wallpaper.style.get()}`} className={`wallpaper ${config.wallpaper.style.get()}`}
> >
<box className="thumbnail"> {bind(config.wallpaper.style).as(s =>
{wallpapers.slice(0, 3).map(w => ( s === "compact" ? (
<box hexpand css={"background-image: url('" + (w.thumbnail ?? w.path) + "');"} /> <box
))} className="thumbnail"
</box> css={"background-image: url('" + (wallpapers[0].thumbnail ?? wallpapers[0].path) + "');"}
/>
) : (
<box className="thumbnail">
{wallpapers.slice(0, 3).map(w => (
<box hexpand css={"background-image: url('" + (w.thumbnail ?? w.path) + "');"} />
))}
</box>
)
)}
<label truncate label={basename(path)} /> <label truncate label={basename(path)} />
</box> </box>
</button> </button>
@ -365,7 +374,7 @@ export default class Actions extends Widget.Box implements LauncherContent {
} }
} }
} else if (action === "wallpaper") { } else if (action === "wallpaper") {
const random = args[1].toLowerCase() === "random"; const random = args[1]?.toLowerCase() === "random";
const term = (random ? args[2] : args[1]) ?? ""; const term = (random ? args[2] : args[1]) ?? "";
const list = random ? Wallpapers.get_default().categories : Wallpapers.get_default().list; const list = random ? Wallpapers.get_default().categories : Wallpapers.get_default().list;
@ -384,7 +393,7 @@ export default class Actions extends Widget.Box implements LauncherContent {
const args = search.split(" "); const args = search.split(" ");
const action = args[0].slice(1).toLowerCase(); const action = args[0].slice(1).toLowerCase();
if (action === "scheme" && args[1].toLowerCase() === "random") { if (action === "scheme" && args[1]?.toLowerCase() === "random") {
execAsync(`caelestia scheme`).catch(console.error); execAsync(`caelestia scheme`).catch(console.error);
close(); close();
} else this.#content.get_child_at_index(0)?.get_child()?.activate(); } else this.#content.get_child_at_index(0)?.get_child()?.activate();