nixos-configs/nixosModules/ags/config/widgets/applauncher/launch.ts

28 lines
693 B
TypeScript
Raw Permalink Normal View History

2024-10-18 00:44:45 -04:00
import { execAsync } from 'astal';
2024-10-22 13:09:39 -04:00
import AstalApps from 'gi://AstalApps';
2024-10-18 00:44:45 -04:00
const bash = async(strings: TemplateStringsArray | string, ...values: unknown[]) => {
const cmd = typeof strings === 'string' ?
strings :
strings.flatMap((str, i) => `${str}${values[i] ?? ''}`)
.join('');
return execAsync(['bash', '-c', cmd]).catch((err) => {
console.error(cmd, err);
return '';
});
};
export const launchApp = (app: AstalApps.Application) => {
const exe = app.executable
.split(/\s+/)
.filter((str) => !str.startsWith('%') && !str.startsWith('@'))
.join(' ');
bash(`${exe} &`);
app.frequency += 1;
};