use actions instead of events for update buttons
This commit is contained in:
parent
78a8be9299
commit
1b720e4b5d
@ -72,6 +72,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="action_name">app.update-yggdrasil</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x">200</property>
|
||||
@ -86,6 +87,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="action_name">app.update-yggtk</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x">200</property>
|
||||
|
@ -23,12 +23,6 @@ namespace Yggtk {
|
||||
[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;
|
||||
|
||||
@ -38,7 +32,9 @@ namespace Yggtk {
|
||||
[GtkChild]
|
||||
private Gtk.Entry ip_entry;
|
||||
|
||||
public AppWindow () {
|
||||
public AppWindow (Gtk.Application application) {
|
||||
|
||||
Object(application: application);
|
||||
|
||||
check_status (status_switch);
|
||||
|
||||
@ -90,14 +86,6 @@ namespace Yggtk {
|
||||
|
||||
});
|
||||
|
||||
update_yggdrasil_button.clicked.connect (() => {
|
||||
download ();
|
||||
});
|
||||
|
||||
update_yggtk_button.clicked.connect (() => {
|
||||
update ();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
int check_status (Switch status) {
|
||||
@ -185,66 +173,6 @@ namespace Yggtk {
|
||||
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -24,11 +24,59 @@ namespace Yggtk {
|
||||
application_id: "org.yggtk.yggtk",
|
||||
flags: ApplicationFlags.FLAGS_NONE
|
||||
);
|
||||
add_actions ();
|
||||
}
|
||||
|
||||
private void add_actions () {
|
||||
SimpleAction update_yggtk_action = new SimpleAction ("update-yggtk", null);
|
||||
update_yggtk_action.activate.connect (update_yggtk);
|
||||
add_action (update_yggtk_action);
|
||||
|
||||
SimpleAction update_yggdrasil_action = new SimpleAction ("update-yggdrasil", null);
|
||||
update_yggdrasil_action.activate.connect (update_yggdrasil);
|
||||
add_action (update_yggdrasil_action);
|
||||
}
|
||||
|
||||
private void update_yggtk () {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void update_yggdrasil () {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void activate () {
|
||||
AppWindow window = new AppWindow ();
|
||||
add_window (window);
|
||||
AppWindow window = new AppWindow (this);
|
||||
window.show ();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user