From 37c4c0898593eb2fc34b04b9b9cc64eef84bdf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Wed, 4 Apr 2018 16:24:10 -0700 Subject: [PATCH 1/3] Show a message when reboot required --- meson.build | 1 + src/Indicator.vala | 33 ++++++++++++++++++++++--- src/Services/UpdateManager.vala | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/Services/UpdateManager.vala diff --git a/meson.build b/meson.build index 08c8f96e..65aa7aad 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ shared_module( 'src/Widgets/UserBox.vala', 'src/Widgets/UserListBox.vala', 'src/Services/DbusInterfaces.vala', + 'src/Services/UpdateManager.vala', 'src/Services/UserManager.vala', dependencies: [ dependency('accountsservice'), diff --git a/src/Indicator.vala b/src/Indicator.vala index ad8e89e2..22d486c2 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -32,9 +32,10 @@ public class Session.Indicator : Wingpanel.Indicator { private Gtk.ModelButton lock_screen; private Gtk.ModelButton log_out; private Gtk.ModelButton suspend; - private Gtk.ModelButton shutdown; + private Wingpanel.Widgets.Container shutdown; private Session.Services.UserManager manager; + private Session.Services.UpdateManager update_manager; private Gtk.Grid main_grid; private Session.Widgets.EndSessionDialog? shutdown_dialog = null; @@ -46,6 +47,12 @@ public class Session.Indicator : Wingpanel.Indicator { this.server_type = server_type; } + construct { + if (server_type == Wingpanel.IndicatorManager.ServerType.SESSION) { + update_manager = new Session.Services.UpdateManager (); + } + } + public override Gtk.Widget get_display_widget () { if (indicator_icon == null) { indicator_icon = new Wingpanel.Widgets.OverlayIcon (ICON_NAME); @@ -79,8 +86,27 @@ public class Session.Indicator : Wingpanel.Indicator { lock_screen = new Gtk.ModelButton (); lock_screen.text = _("Lock"); - shutdown = new Gtk.ModelButton (); - shutdown.text = _("Shut Down…"); + var shutdown_label = new Gtk.Label (_("Shut Down…")); + shutdown_label.xalign = 0; + shutdown_label.margin_start = shutdown_label.margin_end = 6; + + var restart_required_label = new Gtk.Label ("%s".printf (_("Restart required to complete updates"))); + restart_required_label.margin_start = restart_required_label.margin_end = 6; + restart_required_label.use_markup = true; + restart_required_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + + var restart_required_revealer = new Gtk.Revealer (); + restart_required_revealer.valign = Gtk.Align.CENTER; + restart_required_revealer.add (restart_required_label); + restart_required_revealer.bind_property ("reveal-child", update_manager, "restart_required", GLib.BindingFlags.SYNC_CREATE); + + var shutdown_grid = new Gtk.Grid (); + shutdown_grid.orientation = Gtk.Orientation.VERTICAL; + shutdown_grid.add (shutdown_label); + shutdown_grid.add (restart_required_revealer); + + shutdown = new Wingpanel.Widgets.Container (); + shutdown.content_widget.add (shutdown_grid); suspend = new Gtk.ModelButton (); suspend.text = _("Suspend"); @@ -170,6 +196,7 @@ public class Session.Indicator : Wingpanel.Indicator { }); shutdown.clicked.connect (() => { + close (); show_shutdown_dialog (); }); diff --git a/src/Services/UpdateManager.vala b/src/Services/UpdateManager.vala new file mode 100644 index 00000000..b45d3907 --- /dev/null +++ b/src/Services/UpdateManager.vala @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2018 elementary LLC. (https://elementary.io) +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +public class Session.Services.UpdateManager : Object { + public bool restart_required { public get; private set; default = false; } + + construct { + check_file_existance (); + + var restart_folder = File.new_for_path ("/var/run/"); + + try { + var monitor = restart_folder.monitor_directory (FileMonitorFlags.NONE, null); + monitor.changed.connect ((src, dest, event) => { + check_file_existance (); + }); + } catch (IOError e) { + critical (e.message); + } + } + + private void check_file_existance () { + var restart_file = File.new_for_path ("/var/run/reboot-required"); + if (restart_file.query_exists ()) { + restart_required = true; + } else if (restart_required) { + restart_required = false; + } + } +} From c0b4a0bfc15d6bbab64b67aeb8813e990bb22ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Wed, 4 Apr 2018 19:44:24 -0700 Subject: [PATCH 2/3] Remove separate class --- meson.build | 1 - src/Indicator.vala | 52 ++++++++++++++++++++++++++------- src/Services/UpdateManager.vala | 44 ---------------------------- 3 files changed, 42 insertions(+), 55 deletions(-) delete mode 100644 src/Services/UpdateManager.vala diff --git a/meson.build b/meson.build index 65aa7aad..08c8f96e 100644 --- a/meson.build +++ b/meson.build @@ -15,7 +15,6 @@ shared_module( 'src/Widgets/UserBox.vala', 'src/Widgets/UserListBox.vala', 'src/Services/DbusInterfaces.vala', - 'src/Services/UpdateManager.vala', 'src/Services/UserManager.vala', dependencies: [ dependency('accountsservice'), diff --git a/src/Indicator.vala b/src/Indicator.vala index 22d486c2..432cb55f 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -20,6 +20,13 @@ public class Session.Indicator : Wingpanel.Indicator { private const string ICON_NAME = "system-shutdown-symbolic"; + private const string RESTART_CSS = """ + .compact-labels label { + padding-bottom: 0; + padding-top: 0; + } + """; + private SystemInterface suspend_interface; private LockInterface lock_interface; private SeatInterface seat_interface; @@ -32,10 +39,10 @@ public class Session.Indicator : Wingpanel.Indicator { private Gtk.ModelButton lock_screen; private Gtk.ModelButton log_out; private Gtk.ModelButton suspend; + private Gtk.Revealer restart_required_revealer; private Wingpanel.Widgets.Container shutdown; private Session.Services.UserManager manager; - private Session.Services.UpdateManager update_manager; private Gtk.Grid main_grid; private Session.Widgets.EndSessionDialog? shutdown_dialog = null; @@ -47,12 +54,6 @@ public class Session.Indicator : Wingpanel.Indicator { this.server_type = server_type; } - construct { - if (server_type == Wingpanel.IndicatorManager.ServerType.SESSION) { - update_manager = new Session.Services.UpdateManager (); - } - } - public override Gtk.Widget get_display_widget () { if (indicator_icon == null) { indicator_icon = new Wingpanel.Widgets.OverlayIcon (ICON_NAME); @@ -93,15 +94,16 @@ public class Session.Indicator : Wingpanel.Indicator { var restart_required_label = new Gtk.Label ("%s".printf (_("Restart required to complete updates"))); restart_required_label.margin_start = restart_required_label.margin_end = 6; restart_required_label.use_markup = true; - restart_required_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + restart_required_label.get_style_context ().add_class ("attention"); - var restart_required_revealer = new Gtk.Revealer (); + restart_required_revealer = new Gtk.Revealer (); restart_required_revealer.valign = Gtk.Align.CENTER; restart_required_revealer.add (restart_required_label); - restart_required_revealer.bind_property ("reveal-child", update_manager, "restart_required", GLib.BindingFlags.SYNC_CREATE); var shutdown_grid = new Gtk.Grid (); + shutdown_grid.margin_top = shutdown_grid.margin_bottom = 3; shutdown_grid.orientation = Gtk.Orientation.VERTICAL; + shutdown_grid.get_style_context ().add_class ("compact-labels"); shutdown_grid.add (shutdown_label); shutdown_grid.add (restart_required_revealer); @@ -132,12 +134,33 @@ public class Session.Indicator : Wingpanel.Indicator { main_grid.add (lock_screen); main_grid.add (log_out); main_grid.add (new Wingpanel.Widgets.Separator ()); + + check_file_existance (); + + var restart_folder = File.new_for_path ("/var/run"); + + try { + var monitor = restart_folder.monitor_directory (FileMonitorFlags.NONE, null); + monitor.changed.connect ((src, dest, event) => { + check_file_existance (); + }); + } catch (IOError e) { + critical (e.message); + } } main_grid.add (suspend); main_grid.add (shutdown); connections (); + + var provider = new Gtk.CssProvider (); + try { + provider.load_from_data (RESTART_CSS, RESTART_CSS.length); + Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } catch (Error e) { + critical (e.message); + } } this.visible = true; @@ -145,6 +168,15 @@ public class Session.Indicator : Wingpanel.Indicator { return main_grid; } + private void check_file_existance () { + var restart_file = File.new_for_path ("/var/run/reboot-required"); + if (restart_file.query_exists ()) { + restart_required_revealer.reveal_child = true; + } else { + restart_required_revealer.reveal_child = false; + } + } + private void init_interfaces () { try { suspend_interface = Bus.get_proxy_sync (BusType.SYSTEM, "org.freedesktop.login1", "/org/freedesktop/login1"); diff --git a/src/Services/UpdateManager.vala b/src/Services/UpdateManager.vala deleted file mode 100644 index b45d3907..00000000 --- a/src/Services/UpdateManager.vala +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Copyright (c) 2018 elementary LLC. (https://elementary.io) -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -public class Session.Services.UpdateManager : Object { - public bool restart_required { public get; private set; default = false; } - - construct { - check_file_existance (); - - var restart_folder = File.new_for_path ("/var/run/"); - - try { - var monitor = restart_folder.monitor_directory (FileMonitorFlags.NONE, null); - monitor.changed.connect ((src, dest, event) => { - check_file_existance (); - }); - } catch (IOError e) { - critical (e.message); - } - } - - private void check_file_existance () { - var restart_file = File.new_for_path ("/var/run/reboot-required"); - if (restart_file.query_exists ()) { - restart_required = true; - } else if (restart_required) { - restart_required = false; - } - } -} From af878c892f062f8bd78a137fe062bf3e6ba74741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 5 Apr 2018 08:12:28 -0700 Subject: [PATCH 3/3] Cache restart file --- src/Indicator.vala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Indicator.vala b/src/Indicator.vala index 432cb55f..39d86f76 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -35,6 +35,7 @@ public class Session.Indicator : Wingpanel.Indicator { private Wingpanel.Widgets.OverlayIcon indicator_icon; private Wingpanel.Widgets.Separator users_separator; + private GLib.File restart_file; private Gtk.ModelButton user_settings; private Gtk.ModelButton lock_screen; private Gtk.ModelButton log_out; @@ -169,7 +170,10 @@ public class Session.Indicator : Wingpanel.Indicator { } private void check_file_existance () { - var restart_file = File.new_for_path ("/var/run/reboot-required"); + if (restart_file == null) { + restart_file = File.new_for_path ("/var/run/reboot-required"); + } + if (restart_file.query_exists ()) { restart_required_revealer.reveal_child = true; } else {