Upload files to ''
This commit is contained in:
parent
bc54f595cd
commit
27a9393534
100
main.ui
Normal file
100
main.ui
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.22.1 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkApplicationWindow" id="window">
|
||||||
|
<property name="width_request">600</property>
|
||||||
|
<property name="height_request">450</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">Yggtk</property>
|
||||||
|
<property name="resizable">False</property>
|
||||||
|
<property name="window_position">center</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFixed">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSwitch" id="status">
|
||||||
|
<property name="width_request">100</property>
|
||||||
|
<property name="height_request">35</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="x">250</property>
|
||||||
|
<property name="y">80</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="width_request">100</property>
|
||||||
|
<property name="height_request">80</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Yggdrasil</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="x">250</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="label_ip">
|
||||||
|
<property name="width_request">200</property>
|
||||||
|
<property name="height_request">35</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="x">200</property>
|
||||||
|
<property name="y">400</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="browse">
|
||||||
|
<property name="label" translatable="yes">Browse</property>
|
||||||
|
<property name="width_request">200</property>
|
||||||
|
<property name="height_request">35</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="x">200</property>
|
||||||
|
<property name="y">355</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="yggdrasil">
|
||||||
|
<property name="label" translatable="yes">Update Yggdrasil</property>
|
||||||
|
<property name="width_request">200</property>
|
||||||
|
<property name="height_request">35</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="x">200</property>
|
||||||
|
<property name="y">310</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="yggtk">
|
||||||
|
<property name="label" translatable="yes">Update Yggtk</property>
|
||||||
|
<property name="width_request">200</property>
|
||||||
|
<property name="height_request">35</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="x">200</property>
|
||||||
|
<property name="y">265</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
214
main.vala
Normal file
214
main.vala
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user