remove tabs, empty whitespaced lines, unnecessary this keyword

This commit is contained in:
Nikolay Brovko 2020-01-28 04:39:53 +03:00
parent 77fd314253
commit c2df644c9f
No known key found for this signature in database
GPG Key ID: 32258A3DEC9B6F07
5 changed files with 82 additions and 82 deletions

View File

@ -29,20 +29,20 @@ namespace Yggtk {
[GtkChild] [GtkChild]
private Gtk.Button save_config_button; private Gtk.Button save_config_button;
[GtkCallback] [GtkCallback]
private bool on_service_state_switch_state_set (bool state) { private bool on_service_state_switch_state_set (bool state) {
this.application.activate_action ("set-service-state", new Variant.boolean (state)); application.activate_action ("set-service-state", new Variant.boolean (state));
return true; return true;
} }
[GtkCallback] [GtkCallback]
private void on_peer_ip_entry_changed () { private void on_peer_ip_entry_changed () {
save_config_button.visible = peer_ip_entry.text.length > 0; save_config_button.visible = peer_ip_entry.text.length > 0;
} }
public void set_service_state (bool state) { public void set_service_state (bool state) {
service_state_switch.set_state (state); service_state_switch.set_state (state);
} }
public AppWindow (Gtk.Application application) { public AppWindow (Gtk.Application application) {

View File

@ -19,9 +19,9 @@ namespace Yggtk {
public class Application : Gtk.Application { public class Application : Gtk.Application {
private YggdrasilService yggdrasil_service = null; private YggdrasilService yggdrasil_service = null;
private AppWindow window = null; private AppWindow window = null;
public Application () { public Application () {
Object ( Object (
@ -54,44 +54,44 @@ namespace Yggtk {
update_yggdrasil_action.activate.connect (update_yggdrasil); update_yggdrasil_action.activate.connect (update_yggdrasil);
add_action (update_yggdrasil_action); add_action (update_yggdrasil_action);
SimpleAction set_service_state_action = new SimpleAction ("set-service-state", VariantType.BOOLEAN); SimpleAction set_service_state_action = new SimpleAction ("set-service-state", VariantType.BOOLEAN);
set_service_state_action.activate.connect (set_service_state); set_service_state_action.activate.connect (set_service_state);
add_action (set_service_state_action); add_action (set_service_state_action);
SimpleAction browse_peers_action = new SimpleAction ("browse-peers", null); SimpleAction browse_peers_action = new SimpleAction ("browse-peers", null);
browse_peers_action.activate.connect (browse_peers); browse_peers_action.activate.connect (browse_peers);
add_action (browse_peers_action); add_action (browse_peers_action);
} }
private void set_service_state (SimpleAction action, Variant? state) { private void set_service_state (SimpleAction action, Variant? state) {
try { try {
if (yggdrasil_service.get_status () == state.get_boolean ()) { if (yggdrasil_service.get_status () == state.get_boolean ()) {
return; return;
} }
if (state.get_boolean ()) { if (state.get_boolean ()) {
yggdrasil_service.start (); yggdrasil_service.start ();
} else { } else {
yggdrasil_service.stop (); yggdrasil_service.stop ();
} }
display_current_service_state (); display_current_service_state ();
} catch (SpawnError e) { } catch (SpawnError e) {
stderr.printf ("Unable to change service state: %s\n", e.message); stderr.printf ("Unable to change service state: %s\n", e.message);
} }
} }
private bool display_current_service_state () { private bool display_current_service_state () {
try { try {
if (window != null) { if (window != null) {
window.set_service_state (yggdrasil_service.get_status ()); window.set_service_state (yggdrasil_service.get_status ());
} }
} catch (SpawnError e) { } catch (SpawnError e) {
stderr.printf ("Unable to get service state: %s\n", e.message); stderr.printf ("Unable to get service state: %s\n", e.message);
} }
return true; return true;
} }
private void update_yggtk () { private void update_yggtk () {
try { try {
@ -142,11 +142,11 @@ namespace Yggtk {
} }
protected override void activate () { protected override void activate () {
if (window == null) { if (window == null) {
window = new AppWindow (this); window = new AppWindow (this);
} }
display_current_service_state (); display_current_service_state ();
Timeout.add_seconds (1, display_current_service_state); Timeout.add_seconds (1, display_current_service_state);
window.show (); window.show ();
} }

View File

@ -15,29 +15,29 @@
namespace Yggtk { namespace Yggtk {
public class YggdrasilServiceOpenRC : Object, YggdrasilService { public class YggdrasilServiceOpenRC : Object, YggdrasilService {
public bool get_status () throws SpawnError { public bool get_status () throws SpawnError {
string cmd_stdout, cmd_stderr; string cmd_stdout, cmd_stderr;
int cmd_status = -1; int cmd_status = -1;
Process.spawn_command_line_sync ("rc-service yggdrasil status", out cmd_stdout, out cmd_stderr, out cmd_status); Process.spawn_command_line_sync ("rc-service yggdrasil status", out cmd_stdout, out cmd_stderr, out cmd_status);
if (cmd_status != 0 || cmd_stderr.length > 0 || cmd_stdout.contains ("stopped")) { if (cmd_status != 0 || cmd_stderr.length > 0 || cmd_stdout.contains ("stopped")) {
return false; return false;
} }
return true; return true;
} }
public void start () throws SpawnError { public void start () throws SpawnError {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil start"); Process.spawn_command_line_sync ("pkexec rc-service yggdrasil start");
} }
public void stop () throws SpawnError {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil stop");
}
}
public void stop () throws SpawnError {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil stop");
}
}
} }

View File

@ -15,29 +15,29 @@
namespace Yggtk { namespace Yggtk {
public class YggdrasilServiceSystemd : Object, YggdrasilService { public class YggdrasilServiceSystemd : Object, YggdrasilService {
public bool get_status () throws SpawnError { public bool get_status () throws SpawnError {
string cmd_stdout; string cmd_stdout;
int cmd_status = -1; int cmd_status = -1;
Process.spawn_command_line_sync ("systemctl status yggdrasil", out cmd_stdout, null, out cmd_status); Process.spawn_command_line_sync ("systemctl status yggdrasil", out cmd_stdout, null, out cmd_status);
if (cmd_status == 0 && cmd_stdout.contains ("active (running)")) { if (cmd_status == 0 && cmd_stdout.contains ("active (running)")) {
return true; return true;
} }
return false; return false;
} }
public void start () throws SpawnError { public void start () throws SpawnError {
Process.spawn_command_line_sync ("pkexec systemctl start yggdrasil"); Process.spawn_command_line_sync ("pkexec systemctl start yggdrasil");
} }
public void stop () throws SpawnError {
Process.spawn_command_line_sync ("pkexec systemctl stop yggdrasil");
}
}
public void stop () throws SpawnError {
Process.spawn_command_line_sync ("pkexec systemctl stop yggdrasil");
}
}
} }

View File

@ -20,7 +20,7 @@ namespace Yggtk {
public abstract bool get_status () throws SpawnError; public abstract bool get_status () throws SpawnError;
public abstract void start () throws SpawnError; public abstract void start () throws SpawnError;
public abstract void stop () throws SpawnError; public abstract void stop () throws SpawnError;
} }
} }