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

@@ -9,7 +9,6 @@ import { Bluetooth } from "./bluetooth/index.js";
import { BatteryLabel } from "./battery/index.js";
import { Clock } from "./clock/index.js";
import { SysTray } from "./systray/index.js";
import { Power } from "./power/index.js";
import { BarItemBox } from "../shared/barItemBox.js";
@@ -52,9 +51,8 @@ const Right = () => {
BarItemBox(Bluetooth()),
BarItemBox(BatteryLabel()),
BarItemBox(SysTray()),
BarItemBox(Notifications()),
BarItemBox(Clock()),
BarItemBox(Power()),
BarItemBox(Notifications()),
],
});
};
@@ -86,7 +84,6 @@ const RightAlt = () => {
children: [
BarItemBox(Volume()),
BarItemBox(Clock()),
BarItemBox(Power()),
],
});
};

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: "󰑊",

View File

@@ -123,7 +123,13 @@ export default () => {
hexpand: true,
class_name: "notification-action-buttons menu",
on_primary_click: () => {
notif.invoke(action.id);
if (action.id.includes("scriptAction:-")) {
Utils.execAsync(
`${action.id.replace("scriptAction:-", "")}`,
).catch((err) => console.error(err));
} else {
notif.invoke(action.id);
}
},
child: Widget.Box({
hpack: "center",

View File

@@ -57,7 +57,13 @@ export default () => {
hexpand: true,
class_name: "notification-action-buttons",
on_primary_click: () => {
notif.invoke(action.id);
if (action.id.includes("scriptAction:-")) {
Utils.execAsync(
`${action.id.replace("scriptAction:-", "")}`,
).catch((err) => console.error(err));
} else {
notif.invoke(action.id);
}
},
child: Widget.Box({
hpack: "center",