chore(logout-menu): use hyprctl to exit Hyprland, add background color for better visibility

also improved error handling if command fails
This commit is contained in:
retrozinndev
2025-06-15 19:36:14 -03:00
parent be0a9c4845
commit 240ba192b6
2 changed files with 31 additions and 3 deletions
+2
View File
@@ -1,6 +1,8 @@
@use "./colors"; @use "./colors";
.logout-menu { .logout-menu {
background: rgba($color: colors.$bg-translucent-primary, $alpha: .4);
.top { .top {
.time { .time {
font-size: 128px; font-size: 128px;
+29 -3
View File
@@ -1,8 +1,10 @@
import { Astal, Gdk, Gtk, Widget } from "astal/gtk3"; import { Astal, Gdk, Gtk, Widget } from "astal/gtk3";
import { getDateTime } from "../scripts/time"; import { getDateTime } from "../scripts/time";
import { exec, execAsync, GLib } from "astal"; import { exec, execAsync, Gio, GLib } from "astal";
import { AskPopup } from "../widget/AskPopup"; import { AskPopup } from "../widget/AskPopup";
import { Windows } from "../windows"; import { Windows } from "../windows";
import { Notifications } from "../scripts/notifications";
import AstalNotifd from "gi://AstalNotifd?version=0.1";
const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor; const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor;
@@ -99,8 +101,32 @@ export const LogoutMenu = (mon: number) => new Widget.Window({
title: "Log out", title: "Log out",
text: "Are you sure you want to log out? Your session will be ended.", text: "Are you sure you want to log out? Your session will be ended.",
onAccept: () => { onAccept: () => {
exec(`sh "${GLib.getenv("XDG_CONFIG_HOME")}/hypr/scripts/save-hyprsunset.sh"`); execAsync(
execAsync(`sh -c "loginctl terminate-user ${GLib.getenv("USER") || "$USER"}"`); `sh "${GLib.getenv("XDG_CONFIG_HOME")}/hypr/scripts/save-hyprsunset.sh"`
).finally(() =>
execAsync(`hyprctl dispatch exit`).catch((err: Gio.IOErrorEnum) =>
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't exit Hyprland",
body: `An error occurred and colorshell couldn't exit Hyprland. Stderr: \n${
err.message ? `${err.message}\n` : ""}${err.stack}`,
urgency: AstalNotifd.Urgency.NORMAL,
actions: [{
text: "Report Issue on colorshell",
onAction: () => execAsync(
`xdg-open https://github.com/retrozinndev/colorshell/issues/new`
).catch((err: Gio.IOErrorEnum) =>
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't open link",
body: `Do you have \`xdg-utils\` installed? Stderr: \n${
err.message ? `${err.message}\n` : ""}${err.stack}`
})
)
}]
})
)
);
} }
}) })
} as Widget.ButtonProps), } as Widget.ButtonProps),