Little fix

This commit is contained in:
plant_1312 2020-01-28 18:42:33 +03:00
parent c2df644c9f
commit b5a8590e99
2 changed files with 25 additions and 22 deletions

View File

@ -131,7 +131,7 @@
</child> </child>
<child> <child>
<object class="GtkButton" id="save_config_button"> <object class="GtkButton" id="save_config_button">
<property name="label" translatable="yes">Save Config</property> <property name="label" translatable="yes">Save</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
</object> </object>

View File

@ -45,41 +45,44 @@ namespace Yggtk {
} }
public AppWindow (Gtk.Application application) { public AppWindow (Gtk.Application application) {
Object(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 (() => { save_config_button.clicked.connect (() => {
string yggconf;
Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf); if (peer_ip_entry.text != yggconfout) {
parse (yggconf, peer_ip_entry); Parser.to_json (peer_ip_entry);
}
}); });
} }
int parse (string yggconf, Entry ip) { public class Parser : Object {
public void to_json (Entry ip) {
try { string yggconf;
Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf);
var node = Json.from_string (yggconf); var node = Json.from_string (yggconf);
var obj = node.get_object (); var obj = node.get_object ();
obj.set_string_member ("Peers", ip.text); 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 ("yggdrasil.conf", ptext);
FileUtils.set_contents (file, ptext);
Process.spawn_command_line_sync ("pkexec cp yggdrasil.conf /etc"); 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;
}
}
} }
} }
}
}