♻️ ags(runner): organize files separately from the main shell stuff

This commit is contained in:
retrozinndev
2025-03-12 22:11:18 -03:00
parent 65143468c5
commit 52cfd114d7
13 changed files with 62 additions and 109 deletions
+8 -7
View File
@@ -9,17 +9,18 @@ import { Time, timeout } from "astal/time";
import { OSD, OSDModes, setOSDMode } from "./window/OSD"; import { OSD, OSDModes, setOSDMode } from "./window/OSD";
import { ControlCenter } from "./window/ControlCenter"; import { ControlCenter } from "./window/ControlCenter";
import { Runner } from "./window/Runner"; import { Runner } from "./runner/Runner";
import { PluginApps } from "./scripts/runner/apps"; import { PluginApps } from "./runner/plugins/apps";
import { PluginShell } from "./scripts/runner/shell"; import { PluginShell } from "./runner/plugins/shell";
import { PluginWebSearch } from "./scripts/runner/websearch"; import { PluginWebSearch } from "./runner/plugins/websearch";
let osdTimer: (Time|undefined); let osdTimer: (Time|undefined);
const runnerPlugins: Array<Runner.Plugin> = [ const runnerPlugins: Array<Runner.Plugin> = [
new PluginApps(), PluginApps,
new PluginShell(), PluginShell,
new PluginWebSearch() PluginWebSearch
]; ];
App.start({ App.start({
@@ -1,14 +1,13 @@
import AstalHyprland from "gi://AstalHyprland"; import AstalHyprland from "gi://AstalHyprland";
import { getAstalApps } from "../apps";
import { ResultWidget, ResultWidgetProps } from "../../widget/runner/ResultWidget"; import { ResultWidget, ResultWidgetProps } from "../../widget/runner/ResultWidget";
import AstalApps from "gi://AstalApps"; import AstalApps from "gi://AstalApps";
import { Runner } from "../../window/Runner"; import { getAstalApps } from "../../scripts/apps";
import { Runner } from "../Runner";
export class PluginApps implements Runner.Plugin { export const PluginApps = {
// Do not provide prefix, so it's always ran. // Do not provide prefix, so it's always ran.
public readonly name = "Apps"; name: "Apps",
handle: (text: string) => {
public handle(text: string) {
return getAstalApps().fuzzy_query(text).map((app: AstalApps.Application) => return getAstalApps().fuzzy_query(text).map((app: AstalApps.Application) =>
new ResultWidget({ new ResultWidget({
title: app.get_name(), title: app.get_name(),
@@ -18,4 +17,4 @@ export class PluginApps implements Runner.Plugin {
} as ResultWidgetProps) } as ResultWidgetProps)
) || null; ) || null;
} }
} } as Runner.Plugin;
@@ -1,18 +1,18 @@
import { ResultWidget, ResultWidgetProps } from "../../widget/runner/ResultWidget"; import { ResultWidget, ResultWidgetProps } from "../../widget/runner/ResultWidget";
import AstalHyprland from "gi://AstalHyprland"; import AstalHyprland from "gi://AstalHyprland";
import { GLib } from "astal"; import { GLib } from "astal";
import { Runner } from "../../window/Runner"; import { Runner } from "../Runner";
export class PluginShell implements Runner.Plugin { export const PluginShell = {
public readonly prefix = '!'; prefix: '!',
#shell = GLib.getenv("SHELL") || "/usr/bin/env sh"; handle: (command: string): ResultWidget => {
const shell = GLib.getenv("SHELL") || "/usr/bin/env sh";
public handle(command: string): ResultWidget {
return new ResultWidget({ return new ResultWidget({
onClick: () => AstalHyprland.get_default().dispatch("exec", `${this.#shell} -c "${command}"`), onClick: () => AstalHyprland.get_default().dispatch("exec", `${shell} -c "${command}"`),
title: `Run: \`${command}\``, title: `Run: \`${command}\``,
description: this.#shell, description: shell,
icon: "utilities-terminal-symbolic" icon: "utilities-terminal-symbolic"
} as ResultWidgetProps) } as ResultWidgetProps)
} }
} } as Runner.Plugin;
+28
View File
@@ -0,0 +1,28 @@
import AstalHyprland from "gi://AstalHyprland";
import { ResultWidget, ResultWidgetProps } from "../../widget/runner/ResultWidget";
import { Runner } from "../Runner";
const searchEngines = {
duckduckgo: "https://duckduckgo.com/?q=",
google: "https://google.com/search?q=",
yahoo: "https://search.yahoo.com/search?p="
};
let engine: string = searchEngines.google;
export const PluginWebSearch = {
prefix: '?',
name: "Web Search",
handle: (search: string): ResultWidget => {
return new ResultWidget({
icon: "system-search-symbolic",
title: search || "Type your search...",
description: `Search the Web`,
onClick: () => AstalHyprland.get_default().dispatch(
"exec",
`xdg-open \"${engine + search}\"`
)
} as ResultWidgetProps);
}
} as Runner.Plugin;
+1 -1
View File
@@ -2,9 +2,9 @@ import { Gtk } from "astal/gtk3";
import { Windows } from "../windows"; import { Windows } from "../windows";
import { restartInstance } from "./reload-handler"; import { restartInstance } from "./reload-handler";
import { Wireplumber } from "./volume"; import { Wireplumber } from "./volume";
import { startRunnerDefault } from "../window/Runner";
import { AskPopup } from "../widget/AskPopup"; import { AskPopup } from "../widget/AskPopup";
import { execAsync } from "astal"; import { execAsync } from "astal";
import { startRunnerDefault } from "../runner/Runner";
export function handleArguments(request: string): any { export function handleArguments(request: string): any {
const args: Array<string> = request.split(" "); const args: Array<string> = request.split(" ");
+6
View File
@@ -134,6 +134,12 @@ class Notifications extends GObject.Object {
this.emit("notification-removed", notification.id); this.emit("notification-removed", notification.id);
} }
public toggleDoNotDisturb(): boolean {
if(AstalNotifd.get_default().dontDisturb) {
}
}
connect(signal: string, callback: (...args: any[]) => void): number { connect(signal: string, callback: (...args: any[]) => void): number {
return super.connect(signal, callback); return super.connect(signal, callback);
} }
-40
View File
@@ -1,40 +0,0 @@
import AstalHyprland from "gi://AstalHyprland";
import { ResultWidget, ResultWidgetProps } from "../../widget/runner/ResultWidget";
import { Runner } from "../../window/Runner";
const searchEngines = {
duckduckgo: "https://duckduckgo.com/?q=",
google: "https://google.com/search?q=",
yahoo: "https://search.yahoo.com/search?p="
};
let engine: string = searchEngines.google;
export class PluginWebSearch implements Runner.Plugin {
#engineString: string;
public readonly prefix = '?';
public readonly name = "Web Search";
constructor() {
switch(engine) {
case searchEngines.google:
this.#engineString = "Google";
case searchEngines.yahoo:
this.#engineString = "Yahoo";
case searchEngines.duckduckgo:
this.#engineString = "DuckDuckGo";
default: this.#engineString = "Web";
}
}
public handle(search: string): ResultWidget {
return new ResultWidget({
icon: "system-search-symbolic",
title: search || "",
description: `Search with ${this.#engineString}`,
onClick: () => AstalHyprland.get_default().dispatch(
"exec",
`xdg-open \"${engine + search}\"`
)
} as ResultWidgetProps);
}
}
+2 -1
View File
@@ -7,7 +7,8 @@ import { NotificationWidget } from "../Notification";
export const NotifHistory: Gtk.Widget = new Widget.Scrollable({ export const NotifHistory: Gtk.Widget = new Widget.Scrollable({
hscroll: Gtk.PolicyType.NEVER, hscroll: Gtk.PolicyType.NEVER,
vscroll: Gtk.PolicyType.AUTOMATIC, vscroll: Gtk.PolicyType.AUTOMATIC,
expand: true, vexpand: true,
hexpand: true,
child: new Widget.Box({ child: new Widget.Box({
className: "notifications", className: "notifications",
children: bind(Notifications.getDefault(), "history").as((history: Array<AstalNotifd.Notification>) => children: bind(Notifications.getDefault(), "history").as((history: Array<AstalNotifd.Notification>) =>
+1 -1
View File
@@ -1,6 +1,6 @@
import { register } from "astal"; import { register } from "astal";
import { Gtk, Widget } from "astal/gtk3"; import { Gtk, Widget } from "astal/gtk3";
import { closeRunner } from "../../window/Runner"; import { closeRunner } from "../../runner/Runner";
export { ResultWidget, ResultWidgetProps }; export { ResultWidget, ResultWidgetProps };
+2 -1
View File
@@ -18,10 +18,11 @@ export const ControlCenter: Widget.Window = PopupWindow({
halign: Gtk.Align.END, halign: Gtk.Align.END,
valign: Gtk.Align.START, valign: Gtk.Align.START,
visible: false, visible: false,
expand: true, vexpand: true,
child: new Widget.Box({ child: new Widget.Box({
orientation: Gtk.Orientation.VERTICAL, orientation: Gtk.Orientation.VERTICAL,
expand: true, expand: true,
vexpand: true,
children: [ children: [
new Widget.Box({ new Widget.Box({
className: "control-center-container", className: "control-center-container",
View File
-43
View File
@@ -1,43 +0,0 @@
import { Variable } from "astal";
import { Astal, Gdk, Gtk, Widget } from "astal/gtk3";
import { restartInstance } from "../scripts/reload-handler";
const { LEFT, RIGHT, TOP, BOTTOM } = Astal.WindowAnchor;
const wallpaper: Variable<string|undefined> = new Variable<string|undefined>(undefined);
const changeWallpaperButton = new Gtk.MenuItem();
changeWallpaperButton.set_label("Change wallpaper");
const reloadShellButton = new Gtk.MenuItem();
reloadShellButton.set_label("Reload Shell");
reloadShellButton.connect("activate", (_) => restartInstance());
const desktopMenuButtons: Array<Gtk.MenuItem> = [
changeWallpaperButton,
reloadShellButton
];
export const Wallpaper: Widget.Window = new Widget.Window({
namespace: "wallpaper",
layer: Astal.Layer.BACKGROUND,
anchor: LEFT | RIGHT | TOP | BOTTOM,
exclusivity: Astal.Exclusivity.IGNORE,
keymode: Astal.Keymode.NONE,
visible: true,
style: new Gtk.Style(),
css: ".wallpaper { all: unset; }",
monitor: 0, //Needs rework for all monitors
onButtonPressEvent: (_, event: Gdk.Event) => {
const [ , x, y ] = event.get_coords();
if(event.get_button()[1] === Gdk.BUTTON_SECONDARY)
desktopMenu.popup_at_pointer(Gdk.Event.peek());
}
} as Widget.WindowProps);
const desktopMenu: Gtk.Menu = new Gtk.Menu({
visible: true,
monitor: Wallpaper.monitor || 0
} as Gtk.Menu.ConstructorProps);
desktopMenuButtons.map((item: Gtk.MenuItem) =>
desktopMenu.insert(item, -1))