nixos-configs/modules/ags/config/services/gpu-screen-recorder.ts

106 lines
2.8 KiB
TypeScript
Raw Normal View History

2024-11-12 14:15:00 -05:00
import { execAsync, subprocess } from 'astal';
import GObject, { register } from 'astal/gobject';
2024-12-19 17:46:57 -05:00
import { notifySend } from '../lib';
2024-11-12 14:15:00 -05:00
const APP_NAME = 'gpu-screen-recorder';
const ICON_NAME = 'nvidia';
@register()
2024-11-25 12:18:46 -05:00
export default class GpuScreenRecorder extends GObject.Object {
2024-11-12 14:15:00 -05:00
private _lastNotifID: number | undefined;
public constructor() {
super();
try {
subprocess(
['gsr-start'],
(path) => {
if (!this._lastNotifID) {
2024-11-25 12:18:46 -05:00
console.error('[GpuScreenRecorder] ID of warning notif not found');
2024-11-12 14:15:00 -05:00
setTimeout(() => {
this._onSaved(path);
}, 1000);
}
else {
2024-11-12 14:15:00 -05:00
this._onSaved(path);
}
},
() => { /**/ },
);
}
catch (_e) {
console.error('Missing dependency for gpu-screen-recorder');
}
2024-11-12 14:15:00 -05:00
}
2024-11-25 12:18:46 -05:00
private static _default: InstanceType<typeof GpuScreenRecorder> | undefined;
public static get_default() {
2024-11-25 12:18:46 -05:00
if (!GpuScreenRecorder._default) {
GpuScreenRecorder._default = new GpuScreenRecorder();
}
2024-11-25 12:18:46 -05:00
return GpuScreenRecorder._default;
}
2024-11-12 14:15:00 -05:00
public saveReplay() {
execAsync(['gpu-save-replay'])
.then(async() => {
this._lastNotifID = await notifySend({
appName: APP_NAME,
iconName: ICON_NAME,
title: 'Saving Replay',
body: 'Last 20 minutes',
});
})
.catch((err) => {
2024-11-25 12:18:46 -05:00
console.error(`[GpuScreenRecorder save-replay] ${err}`);
2024-11-12 14:15:00 -05:00
});
}
private _onSaved(path: string) {
notifySend({
appName: APP_NAME,
iconName: ICON_NAME,
replaceId: this._lastNotifID,
title: 'Replay Saved',
body: `Saved to ${path}`,
actions: [
{
id: 'folder',
label: 'Open Folder',
callback: () => execAsync([
'xdg-open',
path.substring(0, path.lastIndexOf('/')),
]).catch(print),
},
{
id: 'video',
label: 'Open Video',
callback: () => execAsync(['xdg-open', path]).catch(print),
},
{
id: 'kdenlive',
label: 'Edit in kdenlive',
callback: () => execAsync([
'bash',
'-c',
`kdenlive -i ${path}`,
]).catch(print),
},
],
});
}
}