add AppWindow class (dirty commit)
This commit is contained in:
parent
e31301b689
commit
a682844ba1
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="org/yggtk/yggtk">
|
||||
<gresource prefix="/org/yggtk/yggtk">
|
||||
<file preprocess="xml-stripblanks">ui/main.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkApplicationWindow" id="window">
|
||||
<template class="YggtkAppWindow" parent="GtkApplicationWindow">
|
||||
<property name="width_request">600</property>
|
||||
<property name="height_request">450</property>
|
||||
<property name="can_focus">False</property>
|
||||
@ -17,7 +17,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="status">
|
||||
<object class="GtkSwitch" id="status_switch">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
@ -27,7 +27,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<object class="GtkLabel" id="yggdrasil_label">
|
||||
<property name="width_request">100</property>
|
||||
<property name="height_request">80</property>
|
||||
<property name="visible">True</property>
|
||||
@ -39,7 +39,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="label_ip">
|
||||
<object class="GtkEntry" id="ip_entry">
|
||||
<property name="width_request">200</property>
|
||||
<property name="height_request">35</property>
|
||||
<property name="visible">True</property>
|
||||
@ -51,7 +51,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="browse">
|
||||
<object class="GtkButton" id="browse_button">
|
||||
<property name="label" translatable="yes">Browse</property>
|
||||
<property name="width_request">200</property>
|
||||
<property name="height_request">35</property>
|
||||
@ -65,7 +65,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="yggdrasil">
|
||||
<object class="GtkButton" id="update_yggdrasil_button">
|
||||
<property name="label" translatable="yes">Update Yggdrasil</property>
|
||||
<property name="width_request">200</property>
|
||||
<property name="height_request">35</property>
|
||||
@ -79,7 +79,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="yggtk">
|
||||
<object class="GtkButton" id="update_yggtk_button">
|
||||
<property name="label" translatable="yes">Update Yggtk</property>
|
||||
<property name="width_request">200</property>
|
||||
<property name="height_request">35</property>
|
||||
@ -93,7 +93,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="portable">
|
||||
<object class="GtkCheckButton" id="portable_checkbutton">
|
||||
<property name="label" translatable="yes">Portable</property>
|
||||
<property name="height_request">35</property>
|
||||
<property name="can_focus">True</property>
|
||||
@ -107,5 +107,5 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</template>
|
||||
</interface>
|
||||
|
274
src/app-window.vala
Normal file
274
src/app-window.vala
Normal file
@ -0,0 +1,274 @@
|
||||
/**
|
||||
* 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
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Gtk;
|
||||
|
||||
namespace Yggtk {
|
||||
|
||||
[GtkTemplate (ui = "/org/yggtk/yggtk/ui/main.ui")]
|
||||
public class AppWindow : ApplicationWindow {
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Switch status_switch;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Button update_yggtk_button;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Button update_yggdrasil_button;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.CheckButton portable_checkbutton;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Button browse_button;
|
||||
|
||||
[GtkChild]
|
||||
private Gtk.Entry ip_entry;
|
||||
|
||||
public AppWindow () {
|
||||
|
||||
check_status (status_switch);
|
||||
|
||||
status_switch.notify["active"].connect (() => {
|
||||
|
||||
if (status_switch.get_active ()) {
|
||||
|
||||
start ();
|
||||
|
||||
} else {
|
||||
|
||||
stop ();
|
||||
|
||||
}
|
||||
|
||||
check_status (status_switch);
|
||||
|
||||
});
|
||||
|
||||
ip_entry.notify["text"].connect (() => {
|
||||
|
||||
if (ip_entry.text != "") {
|
||||
|
||||
browse_button.label = "OK";
|
||||
|
||||
} else {
|
||||
|
||||
browse_button.label = "Browse";
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
browse_button.clicked.connect (() => {
|
||||
|
||||
if (browse_button.label == "OK") {
|
||||
|
||||
string yggconf;
|
||||
Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf);
|
||||
parse (yggconf, ip_entry);
|
||||
|
||||
} else {
|
||||
|
||||
Process.spawn_command_line_sync (
|
||||
"xdg-open https://github.com/yggdrasil-network/public-peers"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
update_yggdrasil_button.clicked.connect (() => {
|
||||
download ();
|
||||
});
|
||||
|
||||
update_yggtk_button.clicked.connect (() => {
|
||||
update ();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
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") {
|
||||
|
||||
Process.spawn_command_line_sync ("systemctl status yggdrasil | grep running -c", out yggstatus);
|
||||
|
||||
if (yggstatus == "0") {
|
||||
|
||||
status.state_set (false);
|
||||
|
||||
} else {
|
||||
|
||||
status.state_set (true);
|
||||
|
||||
}
|
||||
|
||||
} 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;
|
||||
|
||||
}
|
||||
|
||||
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 update () {
|
||||
|
||||
try {
|
||||
|
||||
unowned string repo_url = Environment.get_variable ("YGG_UPDATE_REPO");
|
||||
string temp_dir = Utils.mktempdir ();
|
||||
|
||||
if (repo_url == null) {
|
||||
repo_url = "https://git.macaw.me/plant_1312/Yggtk.git";
|
||||
}
|
||||
|
||||
Process.spawn_command_line_sync (@"git clone $repo_url $temp_dir");
|
||||
Process.spawn_command_line_sync (@"meson $temp_dir/build $temp_dir");
|
||||
Process.spawn_command_line_sync (@"ninja -C $temp_dir/build");
|
||||
Process.spawn_command_line_sync (@"cp $temp_dir/build/src/yggtk .");
|
||||
Process.spawn_command_line_sync (@"rm -rf $temp_dir");
|
||||
Process.spawn_command_line_sync ("./yggtk");
|
||||
|
||||
Gtk.main_quit ();
|
||||
|
||||
} catch (Error e) {
|
||||
|
||||
print ("Error update: %s\n", e.message);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int download () {
|
||||
|
||||
try {
|
||||
|
||||
string pm;
|
||||
Process.spawn_command_line_sync ("pkexec pacman -S yggdrasil --noconfirm", out pm);
|
||||
|
||||
if (pm == "Cannot run program pacman: No such file or directory\n") {
|
||||
|
||||
Process.spawn_command_line_sync (
|
||||
"wget https://2375-115685026-gh.circle-artifacts.com/0/yggdrasil-0.3.12-amd64.deb"
|
||||
);
|
||||
Process.spawn_command_line_sync ("pkexec dpkg -i yggdrasil-0.3.12-amd64.deb");
|
||||
|
||||
}
|
||||
|
||||
} catch (Error e) {
|
||||
|
||||
print ("Error download: %s\n", e.message);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int parse (string yggconf, Entry ip) {
|
||||
|
||||
try {
|
||||
|
||||
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 file = "yggdrasil.conf";
|
||||
FileUtils.set_contents (file, ptext);
|
||||
|
||||
Process.spawn_command_line_sync ("pkexec cp yggdrasil.conf /etc");
|
||||
|
||||
} catch (Error e) {
|
||||
|
||||
print ("Error parse JSON: %s\n", e.message);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
259
src/main.vala
259
src/main.vala
@ -19,266 +19,11 @@ int main (string[] args) {
|
||||
|
||||
Gtk.init (ref args);
|
||||
|
||||
try {
|
||||
Yggtk.AppWindow window = new Yggtk.AppWindow ();
|
||||
window.show_all ();
|
||||
|
||||
var builder = new Builder ();
|
||||
builder.add_from_resource ("/org/yggtk/yggtk/ui/main.ui");
|
||||
builder.connect_signals (null);
|
||||
var window = builder.get_object ("window") as Window;
|
||||
var browse = builder.get_object ("browse") as Button;
|
||||
|
||||
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 ();
|
||||
|
||||
});
|
||||
|
||||
var ip = builder.get_object ("label_ip") as Entry;
|
||||
|
||||
ip.notify["text"].connect (() => {
|
||||
|
||||
if (ip.text != "") {
|
||||
|
||||
browse.label = "OK";
|
||||
|
||||
} else {
|
||||
|
||||
browse.label = "Browse";
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
browse.clicked.connect (() => {
|
||||
|
||||
if (browse.label == "OK") {
|
||||
|
||||
string yggconf;
|
||||
Process.spawn_command_line_sync ("yggdrasil -genconf -json", out yggconf);
|
||||
parse (yggconf, ip);
|
||||
|
||||
} else {
|
||||
|
||||
Process.spawn_command_line_sync (
|
||||
"xdg-open https://github.com/yggdrasil-network/public-peers"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
window.show ();
|
||||
Gtk.main ();
|
||||
|
||||
} catch (Error e) {
|
||||
|
||||
print ("Error load UI: %s\n", e.message);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int download () {
|
||||
|
||||
try {
|
||||
|
||||
string pm;
|
||||
Process.spawn_command_line_sync ("pkexec pacman -S yggdrasil --noconfirm", out pm);
|
||||
|
||||
if (pm == "Cannot run program pacman: No such file or directory\n") {
|
||||
|
||||
Process.spawn_command_line_sync (
|
||||
"wget https://2375-115685026-gh.circle-artifacts.com/0/yggdrasil-0.3.12-amd64.deb"
|
||||
);
|
||||
Process.spawn_command_line_sync ("pkexec dpkg -i yggdrasil-0.3.12-amd64.deb");
|
||||
|
||||
}
|
||||
|
||||
} catch (Error e) {
|
||||
|
||||
print ("Error download: %s\n", e.message);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int update () {
|
||||
|
||||
try {
|
||||
|
||||
unowned string repo_url = Environment.get_variable ("YGG_UPDATE_REPO");
|
||||
string temp_dir = Utils.mktempdir ();
|
||||
|
||||
if (repo_url == null) {
|
||||
|
||||
repo_url = "https://git.macaw.me/plant_1312/Yggtk.git";
|
||||
|
||||
}
|
||||
|
||||
Process.spawn_command_line_sync (@"git clone $repo_url $temp_dir");
|
||||
Process.spawn_command_line_sync (@"meson $temp_dir/build $temp_dir");
|
||||
Process.spawn_command_line_sync (@"ninja -C $temp_dir/build");
|
||||
Process.spawn_command_line_sync (@"cp $temp_dir/build/src/yggtk .");
|
||||
Process.spawn_command_line_sync (@"rm -rf $temp_dir");
|
||||
Process.spawn_command_line_sync ("./yggtk");
|
||||
|
||||
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, Entry ip) {
|
||||
|
||||
try {
|
||||
|
||||
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 file = "yggdrasil.conf";
|
||||
FileUtils.set_contents (file, ptext);
|
||||
|
||||
Process.spawn_command_line_sync ("pkexec cp yggdrasil.conf /etc");
|
||||
|
||||
} catch (Error e) {
|
||||
|
||||
print ("Error parse JSON: %s\n", e.message);
|
||||
|
||||
}
|
||||
|
||||
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") {
|
||||
|
||||
Process.spawn_command_line_sync ("systemctl status yggdrasil | grep running -c", out yggstatus);
|
||||
|
||||
if (yggstatus == "0") {
|
||||
|
||||
status.state_set (false);
|
||||
|
||||
} else {
|
||||
|
||||
status.state_set (true);
|
||||
|
||||
}
|
||||
|
||||
} 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;
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
yggtk_sources = [
|
||||
'main.vala',
|
||||
'app-window.vala',
|
||||
'utils.vala',
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user