Files
colorshell/ags/runner/plugins/wallpapers.ts
T
retrozinndev 467de2235a chore(runner): try a new approach to show results, make plugins return properties instead of the actual widget
returning the results as objects seems to be a better approach, also, the new way of showing results doesn't work for some reason(i didn't discover it yet lol)
2025-07-23 20:41:23 -03:00

45 lines
1.5 KiB
TypeScript

import { Wallpaper } from "../../scripts/wallpaper";
import { Runner } from "../Runner";
import Gio from "gi://Gio?version=2.0";
class _PluginWallpapers implements Runner.Plugin {
prefix = "#";
prioritize = true;
#files: (Array<string>|undefined);
init() {
this.#files = [];
const dir = Gio.File.new_for_path(Wallpaper.getDefault().wallpapersPath);
if(dir.query_file_type(null, null) === Gio.FileType.DIRECTORY) {
for(const file of dir.enumerate_children(
"standard::*",
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
null
)) {
this.#files.push(`${dir.get_path()}/${file.get_name()}`);
}
}
}
handle(search: string) {
if(this.#files!.length > 0)
return this.#files!.filter(file =>
// also not the best way to search, but it works
Runner.regExMatch(search, file.split('/')[file.split('/').length-1])
).map(path => ({
title: path.split('/')[path.split('/').length-1].replace(/\..*$/, ""),
actionClick: () => Wallpaper.getDefault().setWallpaper(path)
}));
return {
title: "No wallpapers found!",
description: "Define the $WALLPAPERS variable on Hyprland or create a ~/wallpapers directory",
icon: "image-missing-symbolic"
};
}
}
export const PluginWallpapers = new _PluginWallpapers();