Added notification popups
This commit is contained in:
@@ -30,7 +30,6 @@ const Network = () => {
|
||||
isVisible: true,
|
||||
props: {
|
||||
on_primary_click: (_, event) => {
|
||||
console.log(JSON.stringify(network, null, 2));
|
||||
const clickPos = event.get_root_coords();
|
||||
const coords = [clickPos[1], clickPos[2]];
|
||||
|
||||
|
||||
@@ -1,39 +1,32 @@
|
||||
const hyprland = await Service.import("hyprland");
|
||||
|
||||
const filterTitle = (titleString) => {
|
||||
const filterTitle = (windowtitle) => {
|
||||
const windowTitleMap = [
|
||||
["(.*) - NVIM", " NeoVim"],
|
||||
["(.*) - nvim", " NeoVim"],
|
||||
["(.*) - VIM", " NeoVim"],
|
||||
["(.*)vim (.*)", " NeoVim"],
|
||||
["(.*) — Mozilla Firefox", " Firefox"],
|
||||
["(.*) - Microsoft(.*)Edge", " Edge"],
|
||||
["(.*) - Discord", " Discord"],
|
||||
["(.*) — Dolphin", " Dolphin"],
|
||||
["Plex", " Plex"],
|
||||
["(.*) Steam", " Steam"],
|
||||
[" ", " Desktop"],
|
||||
["(.*) Spotify Free", " Spotify"],
|
||||
["(.*)Spotify Premium", " Spotify"],
|
||||
["Spotify", " Spotify"],
|
||||
[" ~", " Terminal"],
|
||||
["(.*) - Obsidian(.*)", " Obsidian"],
|
||||
["(.+)", ` ${titleString.charAt(0).toUpperCase() + titleString.slice(1)}`],
|
||||
["(.*)", ` Desktop`],
|
||||
["kitty", " Kitty Terminal"],
|
||||
["firefox", " Firefox"],
|
||||
["microsoft-edge", " Edge"],
|
||||
["discord", " Discord"],
|
||||
["org.kde.dolphin", " Dolphin"],
|
||||
["plex", " Plex"],
|
||||
["steam", " Steam"],
|
||||
["", " Desktop"],
|
||||
["spotify", " Spotify"],
|
||||
["obsidian", " Obsidian"],
|
||||
["(.+)", ` ${windowtitle.class.charAt(0).toUpperCase() + windowtitle.class.slice(1)}`],
|
||||
];
|
||||
|
||||
const foundMatch = windowTitleMap.find((wt) =>
|
||||
RegExp(wt[0]).test(titleString),
|
||||
RegExp(wt[0]).test(windowtitle.class.toLowerCase()),
|
||||
);
|
||||
|
||||
return foundMatch ? foundMatch[1] : titleString;
|
||||
return foundMatch ? foundMatch[1] : windowtitle.class;
|
||||
};
|
||||
|
||||
const ClientTitle = () => {
|
||||
return {
|
||||
component: Widget.Label({
|
||||
class_name: "window_title",
|
||||
label: hyprland.active.client.bind("title").as((v) => filterTitle(v)),
|
||||
label: hyprland.active.bind("client").as((v) => filterTitle(v)),
|
||||
}),
|
||||
isVisible: true,
|
||||
};
|
||||
|
||||
@@ -11,8 +11,6 @@ export const Padding = (name) =>
|
||||
|
||||
const moveBoxToCursor = (self, minWidth, minHeight, child) => {
|
||||
globalMousePos.connect("changed", ({ value }) => {
|
||||
// console.log(child.get_allocated_height());
|
||||
// console.log(child.get_allocated_width());
|
||||
let monWidth = hyprland.monitors[hyprland.active.monitor.id].width;
|
||||
let monHeight = hyprland.monitors[hyprland.active.monitor.id].height;
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@ const bluetooth = await Service.import("bluetooth");
|
||||
import DropdownMenu from "../DropdownMenu.js";
|
||||
|
||||
export default () => {
|
||||
bluetooth.connect("changed", (value) => {
|
||||
// console.log(JSON.stringify(value, null, 2));
|
||||
});
|
||||
|
||||
const connectedDevices = (btDevices) => {
|
||||
const noDevices = () => {
|
||||
return Widget.Box({
|
||||
@@ -69,9 +65,11 @@ export default () => {
|
||||
label: dev.paired ? "" : "",
|
||||
}),
|
||||
on_primary_click: () =>
|
||||
Utils.execAsync(
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl ${dev.paired ? "unpair" : "pair"} ${dev.address}`,
|
||||
).catch((err) =>
|
||||
]).catch((err) =>
|
||||
console.error(
|
||||
`bluetoothctl ${dev.paired ? "unpair" : "pair"} ${dev.address}`,
|
||||
err,
|
||||
@@ -87,9 +85,11 @@ export default () => {
|
||||
label: dev.connected ? "" : "",
|
||||
}),
|
||||
on_primary_click: () =>
|
||||
Utils.execAsync(
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl ${dev.connected ? "disconnect" : "connect"} ${dev.address}`,
|
||||
).catch((err) =>
|
||||
]).catch((err) =>
|
||||
console.error(
|
||||
`bluetoothctl ${dev.connected ? "disconnect" : "connect"} ${dev.address}`,
|
||||
err,
|
||||
@@ -104,9 +104,11 @@ export default () => {
|
||||
label: dev.trusted ? "" : "",
|
||||
}),
|
||||
on_primary_click: () =>
|
||||
Utils.execAsync(
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl ${dev.trusted ? "untrust" : "trust"} ${dev.address}`,
|
||||
).catch((err) =>
|
||||
]).catch((err) =>
|
||||
console.error(
|
||||
`bluetoothctl ${dev.trusted ? "untrust" : "trust"} ${dev.address}`,
|
||||
err,
|
||||
@@ -121,9 +123,11 @@ export default () => {
|
||||
label: "",
|
||||
}),
|
||||
on_primary_click: () =>
|
||||
Utils.execAsync(
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl remove ${dev.address}`,
|
||||
).catch((err) =>
|
||||
]).catch((err) =>
|
||||
console.error("Bluetooth Remove", err),
|
||||
),
|
||||
}),
|
||||
@@ -139,77 +143,110 @@ export default () => {
|
||||
return btDevices.length === 0 ? noDevices() : deviceList();
|
||||
};
|
||||
|
||||
const renderDevices = (btDevices) => {
|
||||
return btDevices
|
||||
.filter(
|
||||
(device) =>
|
||||
device.name !== null &&
|
||||
!bluetooth.connected_devices.find(
|
||||
(dev) => dev.address === device.address,
|
||||
),
|
||||
)
|
||||
.map((device) => {
|
||||
return Widget.Button({
|
||||
class_name: `menu-button bluetooth ${device}`,
|
||||
on_primary_click: () => {
|
||||
Utils.execAsync(`bluetoothctl connect ${device.address}`).catch(
|
||||
(err) =>
|
||||
console.error(`bluetoothctl connect ${device.address}`, err),
|
||||
);
|
||||
Utils.execAsync(`bluetoothctl pair ${device.address}`).catch(
|
||||
(err) =>
|
||||
console.error(`bluetoothctl pair ${device.address}`, err),
|
||||
);
|
||||
},
|
||||
child: Widget.Box({
|
||||
children: [
|
||||
const renderDevices = () => {
|
||||
return Widget.Box({
|
||||
class_name: "search-devices-container",
|
||||
vertical: true,
|
||||
setup: (self) =>
|
||||
self.hook(bluetooth, () => {
|
||||
const availableDevices = bluetooth.devices.filter(
|
||||
(device) =>
|
||||
device.name !== null &&
|
||||
!bluetooth.connected_devices.find(
|
||||
(dev) => dev.address === device.address,
|
||||
),
|
||||
);
|
||||
|
||||
if (availableDevices.length === 0) {
|
||||
return (self.children = [
|
||||
Widget.Box({
|
||||
hpack: "start",
|
||||
class_name: "empty-bt-devices-container dim",
|
||||
vertical: true,
|
||||
children: [
|
||||
Widget.Icon({
|
||||
class_name: bluetooth
|
||||
.bind("connected_devices")
|
||||
.as((btDevices) =>
|
||||
btDevices.find((cd) => cd.alias === device.alias)
|
||||
? "menu-button-icon active bluetooth"
|
||||
: "menu-button-icon bluetooth",
|
||||
),
|
||||
icon: `${device["icon-name"]}-symbolic`,
|
||||
Widget.Label({
|
||||
hexpand: true,
|
||||
label: "No devices currently found",
|
||||
}),
|
||||
Widget.Label({
|
||||
class_name: bluetooth
|
||||
.bind("connected_devices")
|
||||
.as((btDevices) =>
|
||||
btDevices.find((cd) => cd.alias === device.alias)
|
||||
? "menu-button-name active bluetooth"
|
||||
: "menu-button-name bluetooth",
|
||||
),
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
label: device.alias,
|
||||
hexpand: true,
|
||||
label: "Press '' to search",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
hpack: "end",
|
||||
expand: true,
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "menu-button-isactive bluetooth",
|
||||
label: bluetooth
|
||||
.bind("connected_devices")
|
||||
.as((btDevices) =>
|
||||
btDevices.find((cd) => cd.alias === device.alias)
|
||||
? " "
|
||||
: "",
|
||||
),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
]);
|
||||
}
|
||||
return (self.children = bluetooth.devices
|
||||
.filter(
|
||||
(device) =>
|
||||
device.name !== null &&
|
||||
!bluetooth.connected_devices.find(
|
||||
(dev) => dev.address === device.address,
|
||||
),
|
||||
)
|
||||
.map((device) => {
|
||||
return Widget.Button({
|
||||
hexpand: true,
|
||||
class_name: `menu-button bluetooth ${device}`,
|
||||
on_primary_click: () => {
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl pair ${device.address}`,
|
||||
]).catch((err) => {
|
||||
console.error(
|
||||
`bluetoothctl pair ${device.address}`,
|
||||
err,
|
||||
);
|
||||
|
||||
setTimeout(() => {
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl connect ${device.address}`,
|
||||
]).catch((err) =>
|
||||
console.error(
|
||||
`bluetoothctl connect ${device.address}`,
|
||||
err,
|
||||
),
|
||||
);
|
||||
}, 2000);
|
||||
});
|
||||
},
|
||||
child: Widget.Box({
|
||||
children: [
|
||||
Widget.Box({
|
||||
hpack: "start",
|
||||
children: [
|
||||
Widget.Icon({
|
||||
class_name: "menu-button-icon bluetooth",
|
||||
icon: `${device["icon-name"]}-symbolic`,
|
||||
}),
|
||||
Widget.Label({
|
||||
hexpand: true,
|
||||
class_name: "menu-button-name bluetooth",
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
label: device.alias,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
hpack: "end",
|
||||
children: device.connecting
|
||||
? [
|
||||
Widget.Label({
|
||||
class_name: "bluetooth-isconnecting",
|
||||
label: "",
|
||||
}),
|
||||
]
|
||||
: [],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
});
|
||||
}));
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const bluetoothOnModule = () => {
|
||||
@@ -250,25 +287,26 @@ export default () => {
|
||||
hpack: "end",
|
||||
child: Widget.Button({
|
||||
class_name: "menu-icon-button",
|
||||
on_primary_click: () =>
|
||||
Utils.execAsync(
|
||||
on_primary_click: () => {
|
||||
Utils.notify("Yoyo");
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
"bluetoothctl --timeout 120 scan on",
|
||||
).catch((err) =>
|
||||
]).catch((err) =>
|
||||
console.error(
|
||||
"bluetoothctl --timeout 120 scan on",
|
||||
err,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Widget.Icon("view-refresh-symbolic"),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
vertical: true,
|
||||
children: bluetooth
|
||||
.bind("devices")
|
||||
.as((v) => renderDevices(v)),
|
||||
child: renderDevices(),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -300,7 +338,7 @@ export default () => {
|
||||
return DropdownMenu({
|
||||
name: "bluetoothmenu",
|
||||
transition: "crossfade",
|
||||
minWidth: 325,
|
||||
minWidth: 350,
|
||||
child: Widget.Box({
|
||||
class_name: "menu-items",
|
||||
child: Widget.Box({
|
||||
@@ -323,16 +361,13 @@ export default () => {
|
||||
hpack: "end",
|
||||
child: Widget.Switch({
|
||||
class_name: "menu-switch bluetooth",
|
||||
active: bluetooth.enabled,
|
||||
setup: (self) => {
|
||||
bluetooth.connect("changed", ({ enabled }) => {
|
||||
self.set_property("active", enabled);
|
||||
});
|
||||
},
|
||||
active: bluetooth.bind("enabled"),
|
||||
on_activate: ({ active }) =>
|
||||
Utils.execAsync(
|
||||
Utils.execAsync([
|
||||
"bash",
|
||||
"-c",
|
||||
`bluetoothctl power ${active ? "on" : "off"}`,
|
||||
).catch((err) =>
|
||||
]).catch((err) =>
|
||||
console.error(
|
||||
`bluetoothctl power ${active ? "on" : "off"}`,
|
||||
err,
|
||||
|
||||
82
modules/notifications/index.js
Normal file
82
modules/notifications/index.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const notifs = await Service.import("notifications");
|
||||
|
||||
export default () => {
|
||||
notifs.popupTimeout = 7000;
|
||||
|
||||
return Widget.Window({
|
||||
name: "notifications-window",
|
||||
class_name: "notifications-window",
|
||||
layer: "top",
|
||||
anchor: ["top", "right"],
|
||||
child: Widget.Box({
|
||||
vertical: true,
|
||||
class_name: "notification-card-container",
|
||||
setup: (self) => {
|
||||
self.hook(notifs, () => {
|
||||
if (notifs.dnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (self.children = notifs.popups.map((notif) => {
|
||||
return Widget.Box({
|
||||
class_name: "notification-card",
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "notification-card-image-container",
|
||||
hpack: "start",
|
||||
child: Widget.Box({
|
||||
class_name: "notification-card-image",
|
||||
css: `background-image: url("${notif.image}")`,
|
||||
}),
|
||||
}),
|
||||
Widget.Box({
|
||||
vertical: true,
|
||||
hpack: "end",
|
||||
class_name: "notification-card-content",
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "notification-card-header",
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "notification-card-header-label",
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
label: notif["summary"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "notification-card-body",
|
||||
vexpand: true,
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "notification-card-body-label",
|
||||
useMarkup: true,
|
||||
lines: 3,
|
||||
wrap: true,
|
||||
truncate: "end",
|
||||
label: notif["body"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "notification-card-appname",
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "notification-card-appname-label",
|
||||
truncate: "end",
|
||||
wrap: true,
|
||||
label: notif["app-name"].toUpperCase(),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
}));
|
||||
});
|
||||
},
|
||||
}),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user