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>
<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="receives_default">True</property>
</object>

View File

@ -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;
}
}
}
}
}
}