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
This commit is contained in:
parent
b7fa29274a
commit
797756c660
2 changed files with 26 additions and 4 deletions
|
|
@ -527,7 +527,7 @@ const Results = ({ entry, mode }: { entry: Widget.Entry; mode: Variable<Mode> })
|
||||||
c => c.class === "Todoist"
|
c => c.class === "Todoist"
|
||||||
);
|
);
|
||||||
if (client) client.focus();
|
if (client) client.focus();
|
||||||
else Gio.DesktopAppInfo.new("todoist.desktop")?.launch([], null);
|
else execAsync("uwsm app -- todoist").catch(console.error);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,33 @@
|
||||||
import { execAsync, GLib } from "astal";
|
import { execAsync, GLib, type Gio } from "astal";
|
||||||
import type AstalApps from "gi://AstalApps";
|
import type AstalApps from "gi://AstalApps";
|
||||||
import { osIcons } from "./icons";
|
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) => {
|
export const launch = (app: AstalApps.Application) => {
|
||||||
|
let now = Date.now();
|
||||||
execAsync(["uwsm", "app", "--", app.entry]).catch(() => {
|
execAsync(["uwsm", "app", "--", app.entry]).catch(() => {
|
||||||
app.frequency--; // Decrement frequency cause launch also increments it
|
// Try manual exec if launch fails (exits with error within 1 second)
|
||||||
app.launch();
|
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++;
|
app.frequency++;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue