From 27a9393534ddd54940fb40f99ea9c521e035183a Mon Sep 17 00:00:00 2001 From: plant_1312 Date: Fri, 17 Jan 2020 22:13:39 +0000 Subject: [PATCH] Upload files to '' --- main.ui | 100 +++++++++++++++++++++++++ main.vala | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 314 insertions(+) create mode 100644 main.ui create mode 100644 main.vala diff --git a/main.ui b/main.ui new file mode 100644 index 0000000..14eda25 --- /dev/null +++ b/main.ui @@ -0,0 +1,100 @@ + + + + + + 600 + 450 + False + Yggtk + False + center + + + + + + True + False + + + 100 + 35 + True + True + + + 250 + 80 + + + + + 100 + 80 + True + False + Yggdrasil + + + 250 + + + + + 200 + 35 + True + True + + + 200 + 400 + + + + + Browse + 200 + 35 + True + True + True + + + 200 + 355 + + + + + Update Yggdrasil + 200 + 35 + True + True + True + + + 200 + 310 + + + + + Update Yggtk + 200 + 35 + True + True + True + + + 200 + 265 + + + + + + diff --git a/main.vala b/main.vala new file mode 100644 index 0000000..ddb6422 --- /dev/null +++ b/main.vala @@ -0,0 +1,214 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using Gtk; + +int main (string[] args) { + + Gtk.init (ref args); + + try { + + var builder = new Builder (); + builder.add_from_file ("main.ui"); + builder.connect_signals (null); + var window = builder.get_object ("window") as Window; + var browse = builder.get_object ("browse") as Button; + + browse.clicked.connect (() => { + + browse.label = "clicked"; + + }); + + var yggdrasil = builder.get_object ("yggdrasil") as Button; + + yggdrasil.clicked.connect (() => { + + download (); + + }); + + var status = builder.get_object ("status") as Switch; + + check_status(status); + + status.notify["active"].connect (() => { + + if (status.get_active()) { + + start(); + + } else { + + stop(); + + } + + check_status(status); + + }); + + var yggtk = builder.get_object ("yggtk") as Button; + + yggtk.clicked.connect (() => { + + update(); + + }); + + window.show_all (); + Gtk.main (); + + } catch (Error e) { + + print ("Error load UI: %s\n", e.message); + + return 1; + + } + + return 0; + +} + +int download () { + + try { + + string yggconf; + Process.spawn_command_line_sync ("pkexec pacman -S yggdrasil --noconfirm"); + Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf); + parse (yggconf); + + } catch (Error e) { + + print ("Error download: %s\n", e.message); + + return 1; + + } + + return 0; + +} + +int update () { + + try { + + Process.spawn_command_line_sync ("git clone https://git.macaw.me:3000/plant_1312/Yggtk.git"); + Process.spawn_command_line_sync ("valac Yggtk/main.vala --pkg gtk+-3.0 --pkg json-glib-1.0"); + Process.spawn_command_line_sync ("cp Yggtk/main.ui ."); + Process.spawn_command_line_sync ("rm -R Yggtk"); + + Process.spawn_command_line_async ("./main"); + Gtk.main_quit (); + + } catch (Error e) { + + print ("Error update: %s\n", e.message); + + return 1; + + } + + return 0; + +} + +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) { + + /*var parser = new Json.Parser (); + parser.load_from_data (yggconf, -1);*/ + + return 0; + +} + +int check_status (Switch status) { + + try { + + string yggstatus; + Process.spawn_command_line_sync ("rc-service yggdrasil status", out yggstatus); + + if (yggstatus == "bash: rc-service: command not found\n") { + + print ("systemd\n"); + + } else { + + if (yggstatus == " * status: stopped\n") { + + status.state_set(false); + + } else { + + status.state_set(true); + + } + + } + + } catch (Error e) { + + print ("Error check status: %s\n", e.message); + + return 1; + + } + + return 0; + +}