place source code files to src directory

This commit is contained in:
Nikolay Brovko 2020-01-24 16:02:38 +03:00
parent 397f225fa8
commit 6803ef84a5
No known key found for this signature in database
GPG key ID: 32258A3DEC9B6F07
4 changed files with 19 additions and 17 deletions

247
src/main.vala Normal file
View file

@ -0,0 +1,247 @@
/*
* 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_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;
browse.clicked.connect (() => {
browse.label = "Soon";
});
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 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;
}
string mktempdir () throws Error {
string temp_dir = null;
Process.spawn_command_line_sync ("mktemp -d", out temp_dir);
return temp_dir.strip ();
}
int update () {
try {
unowned string repo_url = Environment.get_variable ("YGG_UPDATE_REPO");
string temp_dir = 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) {
/*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") {
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;
}

16
src/meson.build Normal file
View file

@ -0,0 +1,16 @@
yggtk_sources = [
'main.vala',
]
yggtk = executable(
meson.project_name(),
yggtk_sources + yggtk_resources,
dependencies: [
dependency('gtk+-3.0'),
dependency('json-glib-1.0'),
],
vala_args: [
'--gresources',
join_paths(meson.source_root(), 'data', 'org.yggtk.yggtk.gresource.xml'),
]
)