fix codestyle, add editorconfig, align with vala-lint

This commit is contained in:
Nikolay Brovko 2020-01-24 15:37:04 +03:00
parent 5407e06683
commit 7e7c0a3ce5
No known key found for this signature in database
GPG Key ID: 32258A3DEC9B6F07
3 changed files with 113 additions and 99 deletions

10
.editorconfig Normal file
View File

@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.vala]
indent_style = space
indent_size = 4
charset = utf-8

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/build /build
/yggtk /yggtk
*\#*

199
main.vala
View File

@ -17,112 +17,115 @@ using Gtk;
int main (string[] args) { int main (string[] args) {
Gtk.init (ref args); Gtk.init (ref args);
try { try {
var builder = new Builder (); var builder = new Builder ();
builder.add_from_file ("main.ui"); builder.add_from_file ("main.ui");
builder.connect_signals (null); builder.connect_signals (null);
var window = builder.get_object ("window") as Window; var window = builder.get_object ("window") as Window;
var browse = builder.get_object ("browse") as Button; var browse = builder.get_object ("browse") as Button;
browse.clicked.connect (() => { browse.clicked.connect (() => {
browse.label = "Soon"; browse.label = "Soon";
}); });
var yggdrasil = builder.get_object ("yggdrasil") as Button; var yggdrasil = builder.get_object ("yggdrasil") as Button;
yggdrasil.clicked.connect (() => { yggdrasil.clicked.connect (() => {
download (); download ();
}); });
var status = builder.get_object ("status") as Switch; var status = builder.get_object ("status") as Switch;
check_status (status); check_status (status);
status.notify["active"].connect (() => { status.notify["active"].connect (() => {
if (status.get_active()) { if (status.get_active ()) {
start(); start ();
} else { } else {
stop(); stop ();
} }
check_status(status); check_status (status);
}); });
var yggtk = builder.get_object ("yggtk") as Button; var yggtk = builder.get_object ("yggtk") as Button;
yggtk.clicked.connect (() => { yggtk.clicked.connect (() => {
update(); update ();
}); });
window.show_all (); window.show_all ();
Gtk.main (); Gtk.main ();
} catch (Error e) { } catch (Error e) {
print ("Error load UI: %s\n", e.message); print ("Error load UI: %s\n", e.message);
return 1; return 1;
} }
return 0; return 0;
} }
int download () { int download () {
try { try {
string pm; string pm;
Process.spawn_command_line_sync ("pkexec pacman -S yggdrasil --noconfirm", out 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") { 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");
} 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); } catch (Error e) {
return 1; print ("Error download: %s\n", e.message);
} return 1;
return 0; }
return 0;
} }
string mktempdir () throws Error { string mktempdir () throws Error {
string temp_dir = null; string temp_dir = null;
Process.spawn_command_line_sync("mktemp -d", out temp_dir); Process.spawn_command_line_sync ("mktemp -d", out temp_dir);
return temp_dir.strip (); return temp_dir.strip ();
} }
int update () { int update () {
try { try {
unowned string repo_url = Environment.get_variable ("YGG_UPDATE_REPO"); unowned string repo_url = Environment.get_variable ("YGG_UPDATE_REPO");
string temp_dir = mktempdir (); string temp_dir = mktempdir ();
string command = null;
if (repo_url == null) { if (repo_url == null) {
repo_url = "https://git.macaw.me/plant_1312/Yggtk.git"; repo_url = "https://git.macaw.me/plant_1312/Yggtk.git";
@ -135,110 +138,110 @@ int update () {
Process.spawn_command_line_sync (@"rm -rf $temp_dir"); Process.spawn_command_line_sync (@"rm -rf $temp_dir");
Process.spawn_command_line_sync ("./yggtk"); Process.spawn_command_line_sync ("./yggtk");
Gtk.main_quit (); Gtk.main_quit ();
} catch (Error e) { } catch (Error e) {
print ("Error update: %s\n", e.message); print ("Error update: %s\n", e.message);
return 1; return 1;
} }
return 0; return 0;
} }
int stop () { int stop () {
try { try {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil stop"); Process.spawn_command_line_sync ("pkexec rc-service yggdrasil stop");
Process.spawn_command_line_sync ("pkexec systemctl stop yggdrasil"); Process.spawn_command_line_sync ("pkexec systemctl stop yggdrasil");
} catch (Error e) { } catch (Error e) {
print ("Error stop Yggdrasil: %s\n", e.message); print ("Error stop Yggdrasil: %s\n", e.message);
return 1; return 1;
} }
return 0; return 0;
} }
int start () { int start () {
try { try {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil start"); Process.spawn_command_line_sync ("pkexec rc-service yggdrasil start");
Process.spawn_command_line_sync ("pkexec systemctl start yggdrasil"); Process.spawn_command_line_sync ("pkexec systemctl start yggdrasil");
} catch (Error e) { } catch (Error e) {
print ("Error start Yggdrasil: %s\n", e.message); print ("Error start Yggdrasil: %s\n", e.message);
return 1; return 1;
} }
return 0; return 0;
} }
int parse (string yggconf) { int parse (string yggconf) {
/*var parser = new Json.Parser (); /*var parser = new Json.Parser ();
parser.load_from_data (yggconf, -1);*/ parser.load_from_data (yggconf, -1);*/
return 0; return 0;
} }
int check_status (Switch status) { int check_status (Switch status) {
try { try {
string yggstatus; string yggstatus;
Process.spawn_command_line_sync ("rc-service yggdrasil status", out yggstatus); Process.spawn_command_line_sync ("rc-service yggdrasil status", out yggstatus);
if (yggstatus == "bash: rc-service: command not found\n") { if (yggstatus == "bash: rc-service: command not found\n") {
Process.spawn_command_line_sync ("systemctl status yggdrasil | grep running -c", out yggstatus); Process.spawn_command_line_sync ("systemctl status yggdrasil | grep running -c", out yggstatus);
if (yggstatus == "0") { if (yggstatus == "0") {
status.state_set (false); status.state_set (false);
} else { } else {
status.state_set (true); status.state_set (true);
} }
} else { } else {
if (yggstatus == " * status: stopped\n") { if (yggstatus == " * status: stopped\n") {
status.state_set (false); status.state_set (false);
} else { } else {
status.state_set (true); status.state_set (true);
} }
} }
} catch (Error e) { } catch (Error e) {
print ("Error check status: %s\n", e.message); print ("Error check status: %s\n", e.message);
return 1; return 1;
} }
return 0; return 0;
} }