use YggdrasilService to control service state

This commit is contained in:
Nikolay Brovko 2020-01-26 21:33:54 +03:00
parent 6f7cfb10d0
commit bb67130d5e
No known key found for this signature in database
GPG key ID: 32258A3DEC9B6F07
3 changed files with 52 additions and 58 deletions

View file

@ -21,7 +21,7 @@ namespace Yggtk {
public class AppWindow : ApplicationWindow {
[GtkChild]
private Gtk.Switch status_switch;
private Gtk.Switch service_state_switch;
[GtkChild]
private Gtk.CheckButton portable_checkbutton;
@ -32,27 +32,21 @@ namespace Yggtk {
[GtkChild]
private Gtk.Entry ip_entry;
[GtkCallback]
private bool on_service_state_switch_state_set (bool state) {
this.application.activate_action ("set-service-state", new Variant.boolean (state));
return true;
}
public void set_service_state (bool state) {
service_state_switch.set_state (state);
}
public AppWindow (Gtk.Application application) {
Object(application: application);
check_status (status_switch);
status_switch.notify["active"].connect (() => {
if (status_switch.get_active ()) {
start ();
} else {
stop ();
}
check_status (status_switch);
});
check_status (service_state_switch);
ip_entry.notify["text"].connect (() => {
@ -135,44 +129,6 @@ namespace Yggtk {
}
int stop () {
try {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil stop");
Process.spawn_command_line_sync ("pkexec systemctl stop yggdrasil");
} catch (Error e) {
print ("Error stop Yggdrasil: %s\n", e.message);
return 1;
}
return 0;
}
int start () {
try {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil start");
Process.spawn_command_line_sync ("pkexec systemctl start yggdrasil");
} catch (Error e) {
print ("Error start Yggdrasil: %s\n", e.message);
return 1;
}
return 0;
}
int parse (string yggconf, Entry ip) {
try {