nixos-configs/modules/ags/config/services/gpu-screen-recorder.ts
matt1432 3f121e0259
All checks were successful
Discord / discord commits (push) Has been skipped
feat(ags binto): add gpu-screen-recorder service
2024-03-24 20:30:17 -04:00

74 lines
1.9 KiB
TypeScript

const { execAsync, subprocess } = Utils;
const Notifications = await Service.import('notifications');
const APP_NAME = 'gpu-screen-recorder';
const START_APP_ID = 2345;
const ICON_NAME = 'nvidia';
class GSR extends Service {
static {
Service.register(this, {}, {});
}
#appID = START_APP_ID;
constructor() {
super();
subprocess(
['gsr-start'],
(path) => {
Notifications.getNotification(this.#appID)?.close();
const notifId = Notifications.Notify(
APP_NAME,
++this.#appID,
ICON_NAME,
'Replay Saved',
`Saved to ${path}`,
['folder', 'Open Folder', 'video', 'Open Video'],
{},
Notifications.popupTimeout,
);
Notifications.getNotification(notifId)?.connect(
'invoked',
(_, actionId: string) => {
if (actionId === 'folder') {
execAsync([
'xdg-open',
path.substring(0, path.lastIndexOf('/')),
]).catch(print);
}
else if (actionId === 'video') {
execAsync(['xdg-open', path]).catch(print);
}
},
);
},
logError,
);
}
saveReplay() {
execAsync(['gpu-save-replay']).then(() => {
Notifications.Notify(
APP_NAME,
this.#appID,
ICON_NAME,
'Saving Replay',
'Last 20 minutes',
[],
{},
Notifications.popupTimeout,
);
});
}
}
const gsrService = new GSR();
export default gsrService;