Skip to content
Prev Previous commit
Next Next commit
Add restart method
  • Loading branch information
meisenzahl committed Jan 29, 2022
commit 394f2e1b8a99b7ba801076ba4b698d5b63cd0ebb
52 changes: 52 additions & 0 deletions src/Utils/SystemUpgrade.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 elementary, Inc. (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 3 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Marius Meisenzahl <mariusmeisenzahl@gmail.com>
*/

public class About.SystemUpgrade {
public static void restart () {
get_system_instance ();

try {
system_instance.reboot (false);
} catch (GLib.Error e) {
critical (e.message);
}
}

[DBus (name = "org.freedesktop.login1.Manager")]
interface SystemInterface : Object {
public abstract void reboot (bool interactive) throws GLib.Error;
}

private static SystemInterface? system_instance;
private static void get_system_instance () {
if (system_instance == null) {
try {
system_instance = Bus.get_proxy_sync (
BusType.SYSTEM,
"org.freedesktop.login1",
"/org/freedesktop/login1"
);
} catch (GLib.Error e) {
warning ("%s", e.message);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Views/OperatingSystemView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public class About.OperatingSystemView : Gtk.Grid {
break;
case State.RESTART:
message_dialog.destroy ();
// Utils.restart ();
SystemUpgrade.restart ();
break;
}
});
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plug_files = files(
'Interfaces/FirmwareClient.vala',
'Interfaces/LoginManager.vala',
'Utils/ARMPartDecoder.vala',
'Utils/SystemUpgrade.vala',
'Views/FirmwareReleaseView.vala',
'Views/FirmwareView.vala',
'Views/HardwareView.vala',
Expand Down