ags(runner): add initialText property to runner

This commit is contained in:
retrozinndev
2025-04-26 22:36:57 -03:00
parent 6244cf5f6a
commit 52d1884003
2 changed files with 25 additions and 7 deletions
+21 -5
View File
@@ -7,10 +7,11 @@ import { Windows } from "../windows";
export let runnerInstance: (Gtk.Window|null) = null;
export function startRunnerDefault() {
export function startRunnerDefault(initialText?: string) {
return Runner.openRunner({
entryPlaceHolder: "Start typing...",
showResultsPlaceHolderOnStartup: false,
initialText
} as Runner.RunnerProps,
() => [
new ResultWidget({
@@ -43,6 +44,7 @@ export namespace Runner {
width?: number;
height?: number;
entryPlaceHolder?: string;
initialText?: string;
showResultsPlaceHolderOnStartup?: boolean;
};
@@ -61,6 +63,8 @@ export namespace Runner {
readonly handle: (inputText: string) => (ResultWidget|Array<ResultWidget>|null|undefined);
/** ran on runner close */
readonly onClose?: () => void;
/** hide other plugins when using this plugin **/
prioritize?: boolean;
}
export function addPlugin(plugin: Runner.Plugin, force?: boolean) {
@@ -121,12 +125,20 @@ export namespace Runner {
}
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));
let calledPlugins: Array<Plugin> = getPlugins().filter((plugin) =>
plugin.prefix ? (input.startsWith(plugin.prefix) ? true : false) : true
).sort((plugin) => plugin.prefix != null ? 0 : 1);
for(const plugin of calledPlugins) {
if(plugin.prioritize) {
calledPlugins = [ plugin ];
break;
}
}
return calledPlugins.map(plugin => plugin.handle(
plugin.prefix ? input.replace(plugin.prefix, "") : input
)).filter(value => value !== undefined && value !== null).flat(1);
plugin.prefix ? input.replace(plugin.prefix, "") : input)
).filter(value => value !== undefined && value !== null).flat(1);
}
function updateResultsList(entryText: string) {
@@ -175,6 +187,10 @@ export namespace Runner {
setup: () => {
// Init plugins
plugins.forEach(plugin => plugin.init && plugin.init());
if(props?.initialText) {
searchEntry.set_text(props.initialText);
searchEntry.set_position(searchEntry.textLength);
}
},
onKeyPressEvent: (_, event: Gdk.Event) => {
const keyVal = event.get_keyval()[1];
+4 -2
View File
@@ -2,7 +2,7 @@ import { Wireplumber } from "./volume";
import { Windows } from "../windows";
import { restartInstance } from "./reload-handler";
import { startRunnerDefault } from "../runner/Runner";
import { runnerInstance, startRunnerDefault } from "../runner/Runner";
import { showWorkspaceNumbers } from "../widget/bar/Workspaces";
import { timeout } from "astal";
@@ -31,7 +31,9 @@ export function handleArguments(request: string): any {
`${name}: ${Windows.isVisible(name) ? "open" : "closed" }`).join('\n');
case "runner":
startRunnerDefault();
!runnerInstance ?
startRunnerDefault(args[1] || undefined)
: runnerInstance.close();
return "Opening runner..."
case "show-ws-numbers":