From 240ba192b6e61078f59fdd0a78eb17db5342ca3b Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Sun, 15 Jun 2025 19:36:14 -0300 Subject: [PATCH] :sparkles: chore(logout-menu): use hyprctl to exit Hyprland, add background color for better visibility also improved error handling if command fails --- ags/style/_logout-menu.scss | 2 ++ ags/window/LogoutMenu.ts | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ags/style/_logout-menu.scss b/ags/style/_logout-menu.scss index e8c6b2f..41e4637 100644 --- a/ags/style/_logout-menu.scss +++ b/ags/style/_logout-menu.scss @@ -1,6 +1,8 @@ @use "./colors"; .logout-menu { + background: rgba($color: colors.$bg-translucent-primary, $alpha: .4); + .top { .time { font-size: 128px; diff --git a/ags/window/LogoutMenu.ts b/ags/window/LogoutMenu.ts index ce043ad..f05c7ab 100644 --- a/ags/window/LogoutMenu.ts +++ b/ags/window/LogoutMenu.ts @@ -1,8 +1,10 @@ import { Astal, Gdk, Gtk, Widget } from "astal/gtk3"; import { getDateTime } from "../scripts/time"; -import { exec, execAsync, GLib } from "astal"; +import { exec, execAsync, Gio, GLib } from "astal"; import { AskPopup } from "../widget/AskPopup"; import { Windows } from "../windows"; +import { Notifications } from "../scripts/notifications"; +import AstalNotifd from "gi://AstalNotifd?version=0.1"; const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor; @@ -99,8 +101,32 @@ export const LogoutMenu = (mon: number) => new Widget.Window({ title: "Log out", text: "Are you sure you want to log out? Your session will be ended.", onAccept: () => { - exec(`sh "${GLib.getenv("XDG_CONFIG_HOME")}/hypr/scripts/save-hyprsunset.sh"`); - execAsync(`sh -c "loginctl terminate-user ${GLib.getenv("USER") || "$USER"}"`); + execAsync( + `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),