diff --git a/data/ui/main.ui b/data/ui/main.ui index f3088a3..0a42215 100644 --- a/data/ui/main.ui +++ b/data/ui/main.ui @@ -72,6 +72,7 @@ True True True + app.update-yggdrasil 200 @@ -86,6 +87,7 @@ True True True + app.update-yggtk 200 diff --git a/src/app-window.vala b/src/app-window.vala index 3d2d7bb..61b886a 100644 --- a/src/app-window.vala +++ b/src/app-window.vala @@ -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 { diff --git a/src/application.vala b/src/application.vala index 46a23b8..59ba941 100644 --- a/src/application.vala +++ b/src/application.vala @@ -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 (); }