Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Show a message when reboot required #45

Closed
wants to merge 8 commits into from
Closed
65 changes: 62 additions & 3 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +39,8 @@ 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 Gtk.Revealer restart_required_revealer;
private Wingpanel.Widgets.Container shutdown;

private Session.Services.UserManager manager;

Expand Down Expand Up @@ -79,8 +87,28 @@ 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 ("<small>%s</small>".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 ("attention");

restart_required_revealer = new Gtk.Revealer ();
restart_required_revealer.valign = Gtk.Align.CENTER;
restart_required_revealer.add (restart_required_label);

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);

shutdown = new Wingpanel.Widgets.Container ();
shutdown.content_widget.add (shutdown_grid);

suspend = new Gtk.ModelButton ();
suspend.text = _("Suspend");
Expand All @@ -106,19 +134,49 @@ 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;

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");
Expand Down Expand Up @@ -170,6 +228,7 @@ public class Session.Indicator : Wingpanel.Indicator {
});

shutdown.clicked.connect (() => {
close ();
show_shutdown_dialog ();
});

Expand Down