add YggdrasilService interface and implementors
This commit is contained in:
parent
1b720e4b5d
commit
c3ca4e0055
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -13,14 +13,26 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 ();
|
||||
|
||||
}
|
||||
|
||||
}
|
30
src/yggdrasil-service-openrc.vala
Normal file
30
src/yggdrasil-service-openrc.vala
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Yggtk {
|
||||
|
||||
public class YggdrasilServiceOpenRC : Object, YggdrasilService {
|
||||
|
||||
public bool get_status () {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void start () {}
|
||||
|
||||
public void stop () {}
|
||||
|
||||
}
|
||||
|
||||
}
|
30
src/yggdrasil-service-systemd.vala
Normal file
30
src/yggdrasil-service-systemd.vala
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Yggtk {
|
||||
|
||||
public class YggdrasilServiceSystemd : Object, YggdrasilService {
|
||||
|
||||
public bool get_status () {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void start () {}
|
||||
|
||||
public void stop () {}
|
||||
|
||||
}
|
||||
|
||||
}
|
26
src/yggdrasil-service.vala
Normal file
26
src/yggdrasil-service.vala
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Yggtk {
|
||||
|
||||
public interface YggdrasilService : Object {
|
||||
|
||||
public abstract bool get_status ();
|
||||
public abstract void start ();
|
||||
public abstract void stop ();
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user