当用户尝试从 GNOME 关机时显示一个对话框

当用户尝试从 GNOME 关机时显示一个对话框

Ubuntu 18.04 和 20.04

你好,

我有一个作为 systemd 服务 (borgmatic) 运行的备份脚本,用于systemd-inhibit阻止用户重新启动/睡眠/关闭计算机。效果很好。

不幸的是,当用户尝试在 GNOME 中关闭或重新启动计算机时,什么也没有发生 - 即操作默默失败 - 然后用户会感到困惑并最终通过长按电源按钮关闭计算机 :-(

我想要实现的是能够打开一个对话窗口(使用 zenity 或 notify-send)并告诉用户稍等片刻 - 但仅在他尝试关机后。

我已经对服务单元进行了一些实验systemd --user,让 zenity 对话框显示在各种目标之前(gnome-session-shutdown.target),但是这不起作用,因为关机程序甚至没有启动......(即使它启动了,Xorg 似乎已经关闭,并且 zenity 因缺少 DISPLAY 而失败。)

systemd-inhibit处于活动状态时,当用户尝试关机时会记录以下内容:

dec 26 21:41:18 t410s gnome-shell[8333]: endSessionDialog: No XDG_SESSION_ID, fetched from logind: 17
dec 26 21:41:19 t410s gnome-shell[8333]: endSessionDialog: No XDG_SESSION_ID, fetched from logind: 17
dec 26 21:41:22 t410s gnome-session[8314]: gnome-session-binary[8314]: WARNING: Shutdown failed: GDBus.Error:System.Error.ESTALE: Stale file handle
dec 26 21:41:22 t410s gnome-session-binary[8314]: WARNING: Shutdown failed: GDBus.Error:System.Error.ESTALE: Stale file handle
dec 26 21:41:22 t410s gnome-session-binary[8314]: Entering running state
dec 26 21:41:22 t410s gnome-shell[8333]: Ignored exception from dbus method: Gio.IOErrorEnum: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dio_2derror_2dquark.Code19: 

知道如何显示备份正在运行的消息吗?

编辑:正如@matigo 所建议的,我已经实施了一种解决方法,以在备份过程中显示不同的壁纸,并希望获得最好的效果......

相关内容