Implemented screen recording functionality for record button in dashboard.

This commit is contained in:
Jas Singh
2024-07-08 02:54:38 -07:00
parent 251a4da2bc
commit 11986dd5a6
9 changed files with 108 additions and 74 deletions

View File

@@ -1,10 +1,30 @@
const hyprland = await Service.import("hyprland");
const Shortcuts = () => {
const handleClick = (action) => {
const isRecording = Variable(false, {
poll: [
1000,
`${App.configDir}/services/screen_record.sh status`,
(out) => {
if (out === "recording") {
return true;
}
return false;
},
],
});
const handleClick = (action, resolver) => {
App.closeWindow("dashboardmenu");
Utils.execAsync(action)
.then(res => res)
.catch(err => err);
}
.then((res) => {
if (typeof resolver === "function") {
return resolver(res);
}
return res;
})
.catch((err) => err);
};
return Widget.Box({
class_name: "shortcuts-container",
hpack: "fill",
@@ -72,7 +92,7 @@ const Shortcuts = () => {
children: [
Widget.Button({
class_name: "dashboard-button colorpicker top-button",
on_primary_click: () => handleClick("hyprpicker"),
on_primary_click: () => handleClick("hyprpicker -a"),
child: Widget.Label({
class_name: "button-label",
label: "",
@@ -80,7 +100,10 @@ const Shortcuts = () => {
}),
Widget.Button({
class_name: "dashboard-button settings",
on_primary_click: () => handleClick('bash -c "kitty -e nvim $HOME/.config/hypr/hyprland.conf"'),
on_primary_click: () =>
handleClick(
'bash -c "kitty -e nvim $HOME/.config/hypr/hyprland.conf"',
),
child: Widget.Label({
class_name: "button-label",
label: "󰒓",
@@ -94,15 +117,32 @@ const Shortcuts = () => {
children: [
Widget.Button({
class_name: "dashboard-button snapshot top-button",
on_primary_click: () => handleClick("grimblast --notify copysave area"),
on_primary_click: () =>
handleClick("grimblast --notify copysave area"),
child: Widget.Label({
class_name: "button-label",
label: "󰄀",
}),
}),
Widget.Button({
class_name: "dashboard-button record",
on_primary_click: () => handleClick("rofi -show drun"),
class_name: isRecording
.bind("value")
.as((v) => `dashboard-button record ${v ? "active" : ""}`),
setup: (self) => {
self.hook(isRecording, () => {
self.on_primary_click = () => {
App.closeWindow("dashboardmenu");
if (isRecording.value === true) {
return Utils.execAsync(
`${App.configDir}/services/screen_record.sh stop`,
).catch((err) => console.error(err));
}
return Utils.execAsync(
`${App.configDir}/services/screen_record.sh start ${hyprland.active.monitor.name}`,
).catch((err) => console.error(err));
};
});
},
child: Widget.Label({
class_name: "button-label",
label: "󰑊",