From 2216e1414d626b65767d0bfa7a790858860e42c9 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Tue, 16 Apr 2024 08:27:36 -0400 Subject: [PATCH] fix(ags): launch apps detached from ags --- modules/ags/config/ts/applauncher/app-item.ts | 5 ++-- modules/ags/config/ts/applauncher/launch.ts | 26 +++++++++++++++++++ modules/ags/config/ts/applauncher/main.ts | 3 ++- modules/ags/config/ts/notifications/base.ts | 3 ++- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 modules/ags/config/ts/applauncher/launch.ts diff --git a/modules/ags/config/ts/applauncher/app-item.ts b/modules/ags/config/ts/applauncher/app-item.ts index 3db5d14..99b6336 100644 --- a/modules/ags/config/ts/applauncher/app-item.ts +++ b/modules/ags/config/ts/applauncher/app-item.ts @@ -2,8 +2,9 @@ const { Box, Icon, Label } = Widget; const { lookUpIcon } = Utils; import CursorBox from '../misc/cursorbox.ts'; +import { launchApp } from './launch.ts'; -// Types +/* Types */ import { Application } from 'types/service/applications.ts'; @@ -55,7 +56,7 @@ export default (app: Application) => { on_primary_click_release: () => { App.closeWindow('win-applauncher'); - app.launch(); + launchApp(app); }, child: Box({ diff --git a/modules/ags/config/ts/applauncher/launch.ts b/modules/ags/config/ts/applauncher/launch.ts new file mode 100644 index 0000000..f6bce09 --- /dev/null +++ b/modules/ags/config/ts/applauncher/launch.ts @@ -0,0 +1,26 @@ +/* Types */ +import { Application } from 'types/service/applications.ts'; + + +const bash = async(strings: TemplateStringsArray | string, ...values: unknown[]) => { + const cmd = typeof strings === 'string' ? + strings : + strings.flatMap((str, i) => `${str }${values[i] ?? ''}`) + .join(''); + + return Utils.execAsync(['bash', '-c', cmd]).catch((err) => { + console.error(cmd, err); + + return ''; + }); +}; + +export const launchApp = (app: Application) => { + const exe = app.executable + .split(/\s+/) + .filter((str) => !str.startsWith('%') && !str.startsWith('@')) + .join(' '); + + bash(`${exe} &`); + app.frequency += 1; +}; diff --git a/modules/ags/config/ts/applauncher/main.ts b/modules/ags/config/ts/applauncher/main.ts index 6ed14b2..0aa6805 100644 --- a/modules/ags/config/ts/applauncher/main.ts +++ b/modules/ags/config/ts/applauncher/main.ts @@ -5,6 +5,7 @@ import { Fzf, FzfResultItem } from 'fzf'; import PopupWindow from '../misc/popup.ts'; import AppItem from './app-item.ts'; +import { launchApp } from './launch.ts'; // Types import { ListBoxRow } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; @@ -72,7 +73,7 @@ const Applauncher = (window_name = 'applauncher') => { if (appList[0]) { App.closeWindow(`win-${window_name}`); - appList[0].launch(); + launchApp(appList[0]); } }, diff --git a/modules/ags/config/ts/notifications/base.ts b/modules/ags/config/ts/notifications/base.ts index 306590e..a633947 100644 --- a/modules/ags/config/ts/notifications/base.ts +++ b/modules/ags/config/ts/notifications/base.ts @@ -9,6 +9,7 @@ const { GLib } = imports.gi; import Gesture from './gesture.ts'; import CursorBox from '../misc/cursorbox.ts'; +import { launchApp } from '../applauncher/launch.ts'; // Types import { Notification as NotifObj } from 'types/service/notifications.ts'; @@ -89,7 +90,7 @@ const NotificationIcon = (notif: NotifObj) => { else { Hyprland.messageAsync('dispatch workspace empty') .then(() => { - app.launch(); + launchApp(app); }); } });