diff --git a/src/application.vala b/src/application.vala index 59ba941..bf3aece 100644 --- a/src/application.vala +++ b/src/application.vala @@ -19,14 +19,30 @@ namespace Yggtk { public class Application : Gtk.Application { + private YggdrasilService yggdrasil_service = null; + public Application () { Object ( application_id: "org.yggtk.yggtk", flags: ApplicationFlags.FLAGS_NONE ); + init_yggdrasil_service (); add_actions (); } + private void init_yggdrasil_service () { + if (Utils.is_command_available ("rc-service")) { + stdout.printf ("Found OpenRC init system\n"); + yggdrasil_service = new YggdrasilServiceOpenRC (); + } else if (Utils.is_command_available ("systemctl")) { + stdout.printf ("Found Systemd init system\n"); + yggdrasil_service = new YggdrasilServiceSystemd (); + } else { + stderr.printf ("Unable to determine init system"); + Gtk.main_quit (); + } + } + private void add_actions () { SimpleAction update_yggtk_action = new SimpleAction ("update-yggtk", null); update_yggtk_action.activate.connect (update_yggtk); diff --git a/src/meson.build b/src/meson.build index 161f7b0..79d1ba8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,6 +2,9 @@ yggtk_sources = [ 'application.vala', 'app-window.vala', 'utils.vala', + 'yggdrasil-service.vala', + 'yggdrasil-service-openrc.vala', + 'yggdrasil-service-systemd.vala', ] yggtk = executable( diff --git a/src/utils.vala b/src/utils.vala index b072b56..6725a1b 100644 --- a/src/utils.vala +++ b/src/utils.vala @@ -13,14 +13,26 @@ * along with this program. If not, see . */ -namespace Utils { +namespace Yggtk.Utils { - string mktempdir () throws Error { + public bool is_command_available (string command) { + try { + string cmd_stdout, cmd_stderr; + int cmd_status = -1; + Process.spawn_command_line_sync (@"which $command", out cmd_stdout, out cmd_stderr, out cmd_status); + if (cmd_status == 0 && cmd_stderr.length == 0 && cmd_stdout.length > 0) { + return true; + } + } catch (SpawnError e) { + return false; + } + return false; + } + public string mktempdir () throws SpawnError { string temp_dir = null; Process.spawn_command_line_sync ("mktemp -d", out temp_dir); return temp_dir.strip (); - } } \ No newline at end of file diff --git a/src/yggdrasil-service-openrc.vala b/src/yggdrasil-service-openrc.vala new file mode 100644 index 0000000..1623223 --- /dev/null +++ b/src/yggdrasil-service-openrc.vala @@ -0,0 +1,30 @@ +/** + * 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 + * 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 . + */ + +namespace Yggtk { + + public class YggdrasilServiceOpenRC : Object, YggdrasilService { + + public bool get_status () { + return false; + } + + public void start () {} + + public void stop () {} + + } + +} \ No newline at end of file diff --git a/src/yggdrasil-service-systemd.vala b/src/yggdrasil-service-systemd.vala new file mode 100644 index 0000000..2863bbb --- /dev/null +++ b/src/yggdrasil-service-systemd.vala @@ -0,0 +1,30 @@ +/** + * 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 + * 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 . + */ + +namespace Yggtk { + + public class YggdrasilServiceSystemd : Object, YggdrasilService { + + public bool get_status () { + return false; + } + + public void start () {} + + public void stop () {} + + } + +} \ No newline at end of file diff --git a/src/yggdrasil-service.vala b/src/yggdrasil-service.vala new file mode 100644 index 0000000..a7818cb --- /dev/null +++ b/src/yggdrasil-service.vala @@ -0,0 +1,26 @@ +/** + * 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 + * 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 . + */ + +namespace Yggtk { + + public interface YggdrasilService : Object { + + public abstract bool get_status (); + public abstract void start (); + public abstract void stop (); + + } + +} \ No newline at end of file