diff --git a/data/ui/app-window.ui b/data/ui/app-window.ui index 6b25144..2c6a2e9 100644 --- a/data/ui/app-window.ui +++ b/data/ui/app-window.ui @@ -131,7 +131,7 @@ - Save Config + Save True True diff --git a/src/app-window.vala b/src/app-window.vala index fc1a48a..07933ca 100644 --- a/src/app-window.vala +++ b/src/app-window.vala @@ -45,41 +45,44 @@ namespace Yggtk { } public AppWindow (Gtk.Application application) { - Object(application: application); + var Parser = new Parser (); + Parser.from_json (peer_ip_entry); + string yggconfout = peer_ip_entry.text; save_config_button.clicked.connect (() => { - string yggconf; - Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf); - parse (yggconf, peer_ip_entry); + + if (peer_ip_entry.text != yggconfout) { + Parser.to_json (peer_ip_entry); + } }); - } - int parse (string yggconf, Entry ip) { - - try { - + public class Parser : Object { + public void to_json (Entry ip) { + string yggconf; + Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf); var node = Json.from_string (yggconf); var obj = node.get_object (); obj.set_string_member ("Peers", ip.text); - string ptext = Json.to_string (node,true); + string ptext = Json.to_string (node, true); - string file = "yggdrasil.conf"; - FileUtils.set_contents (file, ptext); + FileUtils.set_contents ("yggdrasil.conf", ptext); Process.spawn_command_line_sync ("pkexec cp yggdrasil.conf /etc"); - - } catch (Error e) { - - print ("Error parse JSON: %s\n", e.message); - } - return 0; + public void from_json (Entry ip) { + string yggconfout; + FileUtils.get_contents ("/etc/yggdrasil.conf", out yggconfout); + var node = Json.from_string (yggconfout); + var obj = node.get_object (); + string ptext = obj.get_string_member ("Peers"); + if (yggconfout != null) { + ip.text = ptext; + } + } } - } - -} \ No newline at end of file +}