From e69eeada9d7690eebe257f511e0cf40f58dbad17 Mon Sep 17 00:00:00 2001 From: Timothy Feierabend Date: Wed, 27 Nov 2024 11:05:41 -0600 Subject: [PATCH 1/3] add reboot button to infobar reboot button will present yes/no dialog box asking for user confirmation --- usr/lib/linuxmint/mintUpdate/mintUpdate.py | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index 1f883f7c..50346559 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -813,7 +813,10 @@ def run(self): child.destroy() if self.application.reboot_required: self.application.show_infobar(_("Reboot required"), - _("You have installed updates that require a reboot to take effect. Please reboot your system as soon as possible."), icon="system-reboot-symbolic") + _("You have installed updates that require a reboot to take effect. Please reboot your system as soon as possible."), + icon="system-reboot-symbolic", + callback=self._on_infobar_reboot, + ok_label=_("Reboot")) Gdk.threads_leave() try: @@ -1192,6 +1195,19 @@ def run(self): finally: self.cleanup() + def _on_infobar_reboot(self, infobar, response_id): + dialog = Gtk.MessageDialog(self.application.window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, + Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, _("Are you sure you want to reboot?")) + dialog.format_secondary_markup(_("This will close all running applications.")) + dialog.set_title(_("Update Manager") + " - " + _("Confirm Reboot")) + dialog.connect("response", self._on_reboot_confirmation) + dialog.run() + dialog.destroy() + + def _on_reboot_confirmation(self, parent, response_id): + if response_id == Gtk.ResponseType.YES: + subprocess.run(['reboot']) + def check_policy(self): """ Check the presence of the Mint layer """ p = subprocess.run(['apt-cache', 'policy'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={"LC_ALL": "C"}) @@ -1843,7 +1859,10 @@ def show_dpkg_lock_msg(parent): dialog.run() dialog.destroy() - def show_infobar(self, title, msg, msg_type=Gtk.MessageType.WARNING, icon=None, callback=None): + def show_infobar(self, title, msg, msg_type=Gtk.MessageType.WARNING, icon=None, callback=None, ok_label=None): + if not ok_label: + ok_label = _("OK") + infobar = Gtk.InfoBar() infobar.set_margin_bottom(2) infobar.set_message_type(msg_type) @@ -1869,7 +1888,7 @@ def show_infobar(self, title, msg, msg_type=Gtk.MessageType.WARNING, icon=None, infobar.add_button(_("Yes"), Gtk.ResponseType.YES) infobar.add_button(_("No"), Gtk.ResponseType.NO) else: - infobar.add_button(_("OK"), Gtk.ResponseType.OK) + infobar.add_button(ok_label, Gtk.ResponseType.OK) infobar.connect("response", callback) infobar.show_all() self.infobar.pack_start(infobar, True, True, 0) From ac2da987f0cffcc46d00556cda9419546be3e1b8 Mon Sep 17 00:00:00 2001 From: Timothy Feierabend Date: Fri, 29 Nov 2024 14:18:25 -0600 Subject: [PATCH 2/3] pulled latest master code and re-implemented --- usr/lib/linuxmint/mintUpdate/mintUpdate.py | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index 479c364e..2ca829eb 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -594,7 +594,10 @@ def show_dpkg_lock_msg(parent): dialog.destroy() @_idle - def show_infobar(self, title, msg, msg_type, icon, callback): + def show_infobar(self, title, msg, msg_type, icon, callback, ok_label=None): + if not ok_label: + ok_label = _("OK") + infobar = Gtk.InfoBar() infobar.set_margin_bottom(2) infobar.set_message_type(msg_type) @@ -620,7 +623,7 @@ def show_infobar(self, title, msg, msg_type, icon, callback): infobar.add_button(_("Yes"), Gtk.ResponseType.YES) infobar.add_button(_("No"), Gtk.ResponseType.NO) else: - infobar.add_button(_("OK"), Gtk.ResponseType.OK) + infobar.add_button(ok_label, Gtk.ResponseType.OK) infobar.connect("response", callback) infobar.show_all() for child in self.ui_infobar.get_children(): @@ -2082,7 +2085,11 @@ def refresh(self, refresh_cache): if self.reboot_required: self.show_infobar(_("Reboot required"), - _("You have installed updates that require a reboot to take effect. Please reboot your system as soon as possible."), Gtk.MessageType.WARNING, "system-reboot-symbolic", None) + _("You have installed updates that require a reboot to take effect. Please reboot your system as soon as possible."), + Gtk.MessageType.WARNING, + "system-reboot-symbolic", + self._on_infobar_reboot, + _("Reboot")) if refresh_cache: # Note: All cache refresh happen asynchronously @@ -2111,6 +2118,19 @@ def refresh(self, refresh_cache): self.refresh_updates() + def _on_infobar_reboot(self, parent, response_id): + dialog = Gtk.MessageDialog(self.ui_window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, + Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, _("Are you sure you want to reboot?")) + dialog.format_secondary_markup(_("This will close all running applications.")) + dialog.set_title(_("Update Manager") + " - " + _("Confirm Reboot")) + dialog.connect("response", self._on_reboot_confirmation) + dialog.run() + dialog.destroy() + + def _on_reboot_confirmation(self, parent, response_id): + if response_id == Gtk.ResponseType.YES: + subprocess.run(['reboot']) + @_async def refresh_apt_cache_externally(self): try: From 2adb20740346ff3ff99f9baec84c53de78ae37be Mon Sep 17 00:00:00 2001 From: Timothy Feierabend Date: Fri, 6 Dec 2024 05:47:46 -0600 Subject: [PATCH 3/3] reworked reboot to integrate with DE --- usr/lib/linuxmint/mintUpdate/mintUpdate.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index 2ca829eb..b9a8dcdd 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -2119,17 +2119,17 @@ def refresh(self, refresh_cache): self.refresh_updates() def _on_infobar_reboot(self, parent, response_id): - dialog = Gtk.MessageDialog(self.ui_window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, - Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, _("Are you sure you want to reboot?")) - dialog.format_secondary_markup(_("This will close all running applications.")) - dialog.set_title(_("Update Manager") + " - " + _("Confirm Reboot")) - dialog.connect("response", self._on_reboot_confirmation) - dialog.run() - dialog.destroy() - - def _on_reboot_confirmation(self, parent, response_id): - if response_id == Gtk.ResponseType.YES: - subprocess.run(['reboot']) + session = os.environ.get("XDG_CURRENT_DESKTOP") + # Trigger reboot based on DE + if session in ["Cinnamon", "X-Cinnamon"]: + subprocess.run(['/usr/bin/cinnamon-session-quit', '--reboot']) + elif session == 'MATE': + subprocess.run(['/usr/bin/dbus-send', '--dest=org.gnome.SessionManager', '--type=method_call', + '/org/gnome/SessionManager', 'org.gnome.SessionManager.RequestReboot']) + elif session == 'XFCE': + subprocess.run(['/usr/bin/xfce4-session-logout', '--reboot']) + else: + subprocess.run(['/usr/bin/systemctl', 'reboot']) @_async def refresh_apt_cache_externally(self):