From 3f121e025922ac3f57851a5dfad9607e0df4e9ec Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sun, 24 Mar 2024 20:30:17 -0400 Subject: [PATCH] feat(ags binto): add gpu-screen-recorder service --- devices/binto/modules/gpu-replay.nix | 8 +- modules/ags/config/binto.ts | 7 +- .../config/services/gpu-screen-recorder.ts | 74 +++++++++++++++++++ modules/ags/config/ts/notifications/popup.ts | 2 - 4 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 modules/ags/config/services/gpu-screen-recorder.ts diff --git a/devices/binto/modules/gpu-replay.nix b/devices/binto/modules/gpu-replay.nix index c8fbed0..b87676d 100644 --- a/devices/binto/modules/gpu-replay.nix +++ b/devices/binto/modules/gpu-replay.nix @@ -9,7 +9,6 @@ inherit (lib) concatStringsSep removePrefix; hyprPkgs = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.finalPackage; - # TODO: manage this with ags gsr = pkgs.stdenv.mkDerivation { name = "gpu-screen-recorder"; version = gpu-screen-recorder-src.rev; @@ -74,7 +73,6 @@ in { name = "gpu-save-replay"; runtimeInputs = [procps]; text = '' - # TODO: add notif on success pkill --signal SIGUSR1 -f gpu-screen-recorder ''; }) @@ -110,11 +108,7 @@ in { ]; wayland.windowManager.hyprland.settings = { - bind = [",F8, exec, gpu-save-replay"]; - - exec-once = [ - "sleep 10; tmux new-session -s gsr -d gsr-start" - ]; + bind = [",F8, exec, ags -r 'GSR.saveReplay()'"]; }; }; } diff --git a/modules/ags/config/binto.ts b/modules/ags/config/binto.ts index e9bd200..729c372 100644 --- a/modules/ags/config/binto.ts +++ b/modules/ags/config/binto.ts @@ -1,5 +1,6 @@ -import Pointers from './services/pointers.ts'; import Brightness from './services/brightness.ts'; +import GSR from './services/gpu-screen-recorder.ts'; +import Pointers from './services/pointers.ts'; import AppLauncher from './ts/applauncher/main.ts'; import Bar from './ts/bar/binto.ts'; @@ -13,10 +14,10 @@ App.config({ icons: './icons', onConfigParsed: () => { - globalThis.Pointers = Pointers; - Brightness.capsName = 'input30::capslock'; globalThis.Brightness = Brightness; + globalThis.Pointers = Pointers; + globalThis.GSR = GSR; }, windows: () => [ diff --git a/modules/ags/config/services/gpu-screen-recorder.ts b/modules/ags/config/services/gpu-screen-recorder.ts new file mode 100644 index 0000000..6310633 --- /dev/null +++ b/modules/ags/config/services/gpu-screen-recorder.ts @@ -0,0 +1,74 @@ +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; diff --git a/modules/ags/config/ts/notifications/popup.ts b/modules/ags/config/ts/notifications/popup.ts index 9df8456..253cd1d 100644 --- a/modules/ags/config/ts/notifications/popup.ts +++ b/modules/ags/config/ts/notifications/popup.ts @@ -52,8 +52,6 @@ export default () => Box({ return; } - console.log(notif.attribute.hovered); - // If notif isn't hovered or was closed, slide away if (!notif.attribute.hovered || force) { notif.attribute.slideAway('Left');