♻️ ags(runner): separate search results steps into functions

This commit is contained in:
retrozinndev
2025-04-25 13:25:25 -03:00
parent ec353b81bd
commit e6bac1a425
+25 -14
View File
@@ -113,24 +113,31 @@ export namespace Runner {
resultsList.insert(widget, -1)); resultsList.insert(widget, -1));
} }
// Init plugins function cleanResults() {
plugins.forEach(plugin => plugin.init && plugin.init()); resultsList.get_children().map((listItem) => {
function updateResultsList(entryText: string) {
const calledPlugins: Array<Plugin> = getPlugins().filter((plugin) => plugin.prefix && entryText.startsWith(plugin.prefix) ?
plugin : null).concat(getPlugins().filter(plugin => plugin.prefix === undefined));
const widgets: Array<ResultWidget> = calledPlugins.map(plugin => plugin.handle(
plugin.prefix ? entryText.replace(plugin.prefix, "") : entryText
)).filter(value => value !== undefined && value !== null).flat(1);
// Remove all previous results
resultsList.get_children().map((listItem: Gtk.Widget) => {
resultsList.remove(listItem); resultsList.remove(listItem);
listItem.destroy(); listItem.destroy();
}); });
}
// Insert placeholder if somehow no results are found function getPluginResults(input: string): Array<ResultWidget> {
const calledPlugins: Array<Plugin> = getPlugins().filter((plugin) => plugin.prefix && input.startsWith(plugin.prefix) ?
plugin : null).concat(getPlugins().filter(plugin => plugin.prefix === undefined));
return calledPlugins.map(plugin => plugin.handle(
plugin.prefix ? input.replace(plugin.prefix, "") : input
)).filter(value => value !== undefined && value !== null).flat(1);
}
function updateResultsList(entryText: string) {
const widgets: Array<ResultWidget> = [];
// Remove all previous results
cleanResults();
widgets.push(...getPluginResults(entryText))
// Insert placeholder if there are no results
if(placeholder && widgets.length === 0) if(placeholder && widgets.length === 0)
widgets.push(...placeholder()); widgets.push(...placeholder());
@@ -165,6 +172,10 @@ export namespace Runner {
heightRequest: props?.height ?? 450, heightRequest: props?.height ?? 450,
marginTop: 240, marginTop: 240,
anchor: Astal.WindowAnchor.TOP | Astal.WindowAnchor.BOTTOM, anchor: Astal.WindowAnchor.TOP | Astal.WindowAnchor.BOTTOM,
setup: () => {
// Init plugins
plugins.forEach(plugin => plugin.init && plugin.init());
},
onKeyPressEvent: (_, event: Gdk.Event) => { onKeyPressEvent: (_, event: Gdk.Event) => {
const keyVal = event.get_keyval()[1]; const keyVal = event.get_keyval()[1];