diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-25 21:42:10 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-25 21:42:10 +1100 |
| commit | 797756c6609c06e959ad691bc57b0e301e07cc11 (patch) | |
| tree | 1ec567ca007759098554f6bb7e9b6fb2fa675be3 /src/utils | |
| parent | launcher: todo subcommand (diff) | |
| download | caelestia-shell-797756c6609c06e959ad691bc57b0e301e07cc11.tar.gz caelestia-shell-797756c6609c06e959ad691bc57b0e301e07cc11.tar.bz2 caelestia-shell-797756c6609c06e959ad691bc57b0e301e07cc11.zip | |
launcher: todo notif uwsm app
Wasn't using it cause todoist desktop is broken with uwsm
But command works so use that
Also better app launch
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/system.ts | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/utils/system.ts b/src/utils/system.ts index 1c5f011..c318c64 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -1,11 +1,33 @@ -import { execAsync, GLib } from "astal"; +import { execAsync, GLib, type Gio } from "astal"; import type AstalApps from "gi://AstalApps"; import { osIcons } from "./icons"; +/** + * See https://specifications.freedesktop.org/desktop-entry-spec/latest/exec-variables.html + * @param exec The exec field in a desktop file + */ +const execToCmd = (app: AstalApps.Application) => { + let exec = app.executable.replace(/%[fFuUdDnNvm]/g, ""); // Remove useless field codes + exec = exec.replace(/%i/g, app.iconName ? `--icon ${app.iconName}` : ""); // Replace %i app icon + exec = exec.replace(/%c/g, app.name); // Replace %c with app name + exec = exec.replace(/%k/g, (app.app as Gio.DesktopAppInfo).get_filename() ?? ""); // Replace %k with desktop file path + return exec; +}; + export const launch = (app: AstalApps.Application) => { + let now = Date.now(); execAsync(["uwsm", "app", "--", app.entry]).catch(() => { - app.frequency--; // Decrement frequency cause launch also increments it - app.launch(); + // Try manual exec if launch fails (exits with error within 1 second) + if (Date.now() - now < 1000) { + now = Date.now(); + execAsync(["uwsm", "app", "--", execToCmd(app)]).catch(() => { + // Fallback to regular launch + if (Date.now() - now < 1000) { + app.frequency--; // Decrement frequency cause launch also increments it + app.launch(); + } + }); + } }); app.frequency++; }; |