code cleanup and openrc script

This commit is contained in:
Chris Cromer 2020-08-05 21:15:32 -04:00
parent fb70d11f2b
commit 6b771cfa98
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
28 changed files with 2043 additions and 1572 deletions

1
contrib/meson.build Normal file
View File

@ -0,0 +1 @@
subdir('openrc')

View File

@ -0,0 +1,19 @@
openrc_config_data = configuration_data()
openrc_config_data.set('SBINDIR', join_paths(get_option('prefix'), get_option('sbindir')))
openrc_config_data.set('LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir'), meson.project_name()))
openrc_config_data_file = configure_file(
input: 'tufmanager.in',
output: 'tufmanager',
configuration: openrc_config_data
)
if openrc
install_data(
openrc_config_data_file,
install_dir: join_paths(get_option('sysconfdir'), 'init.d')
)
permissions = find_program('chmod')
meson.add_install_script('permission.sh', join_paths(get_option('sysconfdir'), 'init.d'))
endif

4
contrib/openrc/permission.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh -eu
echo "Make OpenRC script executable..."
chmod 755 "${DESTDIR}${1}/tufmanager"

View File

@ -11,7 +11,7 @@
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
command=@PKG_PREFIX@/libexec/tuf-manager/tuf-server
command=@LIBEXECDIR@/tuf-server
pidfile=/var/run/tufmanager/tufmanager.pid
name="TUF Manager daemon"

View File

@ -1,5 +1,5 @@
dbus_config_data = configuration_data()
dbus_config_data.set('LIBEXEC_DIR', join_paths(get_option('prefix'), get_option('libexecdir'), meson.project_name()))
dbus_config_data.set('LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir'), meson.project_name()))
dbus_config_data_file = configure_file(
input: 'org.tuf.manager.server.service.in',

View File

@ -1,4 +1,4 @@
[D-BUS Service]
Name=org.tuf.manager.server
Exec=@LIBEXEC_DIR@/tuf-server
Exec=@LIBEXECDIR@/tuf-server
User=root

View File

@ -5,7 +5,7 @@
<policyconfig>
<vendor>TUF Manager</vendor>
<vendor_url>https://git.cromer.cl/cromer/tuf-manager/</vendor_url>
<icon_name>package-x-generic</icon_name>
<icon_name>tuf-manager</icon_name>
<action id="org.tuf.manager.save">
<message>Authentication is required</message>
<defaults>

View File

@ -21,9 +21,11 @@ add_global_arguments(
always_authenticated = get_option('always-authenticated')
build_cli = get_option('build-cli')
build_gui = get_option('build-gui')
openrc = get_option('openrc')
subdir('po')
subdir('data')
subdir('src')
subdir('docs')
subdir('script')
subdir('contrib')

View File

@ -28,3 +28,9 @@ option(
value: true,
description: 'User is always authenticated, so no password is necessary'
)
option(
'openrc',
type : 'boolean',
value: false,
description: 'Install OpenRC script'
)

View File

@ -1,5 +1,5 @@
# only gui or cli need gschema
if build_gui or build_cli
valadoc = find_program('glib-compile-schemas')
glib_compile_schemas = find_program('glib-compile-schemas')
meson.add_install_script('compile_schemas.sh')
endif

View File

@ -20,6 +20,9 @@ namespace TUFManager {
* The CLI namespace handles all command line related usage
*/
namespace CLI {
/**
* This class contains the app that runs on the command line
*/
public class TUFManagerApp : Application {
#if ALWAYS_AUTHENTICATED
#else
@ -29,56 +32,149 @@ namespace TUFManager {
Subprocess? pkttyagent = null;
#endif
/**
* The possible modes the fan can be in
*/
private enum FanMode {
/**
* This is the default fan mode
*/
BALANCED,
/**
* This mode makes the fans run at full power
*/
TURBO,
/**
* This mode trys to keep the fans as quiet as possible
*/
SILENT
}
/**
* The possible modes the keyboard lighting can be set to
*/
private enum KeyboardMode {
/**
* This mode makes the keyboard lights stay a constant color
*/
STATIC,
/**
* This mode makes the keyboard lights turn on and off at a variable speed
*/
BREATHING,
/**
* This mode makes the keyboard lights cycle through various colors at a variable speed
*/
COLOR_CYCLE,
/**
* This modes makes the keyboad lights strobe fast
*/
STROBING
}
/**
* The possible speeds that can bet set for the keyboard
*/
private enum KeyboardSpeed {
/**
* Slow speed
*/
SLOW,
/**
* Medium speed
*/
MEDIUM,
/**
* Fast speed
*/
FAST
}
/**
* This flag is set if the command line arguments are invalid
*/
private bool invalid = false;
/**
* This flag is set if the user wants to see help
*/
private bool help = false;
/**
* This flag is set if the user wants to see info
*/
private bool info = false;
/**
* This flag is set if the user wants to see the version
*/
private bool version = false;
/**
* This flag is set if the user wants to set the fan mode
*/
private bool fan = false;
/**
* This contains the mode the user want to set for the fan
*/
private FanMode? fan_mode = null;
/**
* This flag is set if the user wants to set the keyboard lighting mode
*/
private bool lighting = false;
/**
* This contains the mode the user want to set for the keyboard
*/
private KeyboardMode? keyboard_mode = null;
/**
* This flag is set if the user wants to change the speed of the lights on the keyboard
*/
private bool speed = false;
/**
* This contains the speed of the lights on the keyboard that the user wants to set
*/
private KeyboardSpeed? keyboard_speed = null;
/**
* This flag is set if the user wants to change the keyboard color
*/
private bool color = false;
/**
* This contains the color in rgba format to set
*/
private Gdk.RGBA? rgba = null;
/**
* Initializes the command line app and sets a timeout so that the process can finish before return is called
*/
public TUFManagerApp () {
Object (application_id: "cl.cromer.tuf.manager", flags: ApplicationFlags.HANDLES_COMMAND_LINE);
set_inactivity_timeout (1000);
}
/**
* This is called when the application gets activated
*/
public override void activate () {
this.hold ();
this.release ();
}
/**
* This is the logic that controls the command lines options used
*
* @param command_line The command line that is in use
* @return Returns 0 on success or an error code if failure
*/
private int _command_line (ApplicationCommandLine command_line) {
try {
connect_dbus ();
connect_tuf_server ();
}
catch (TUFError e) {
command_line.printerr (_ ("Error: ") + e.message + "\n");
@ -87,9 +183,11 @@ namespace TUFManager {
string[] args = command_line.get_arguments ();
if (args.length == 1) {
// If no arguments are passed show help
help = true;
}
else if (args.length > 1) {
// Find out what the first argument is
switch (args[1]) {
case "version":
version = true;
@ -121,6 +219,7 @@ namespace TUFManager {
}
if (args.length > 2) {
// If the first argument requires a second argument, look for it here
if (fan) {
switch (args[2]) {
case "balanced":
@ -377,12 +476,23 @@ namespace TUFManager {
return 0;
}
/**
* If there are more arguments than there should be we need to invalidate
* TODO: Change this to something better later
*
* @param args The arguments to check the length on
*/
private void check_second_argument (string[] args) {
if (args.length > 2) {
invalid = true;
}
}
/**
* Print the usage for the user if help is called or they do something invalid
*
* @param command_line The command line currently in use to print to
*/
private void print_usage (ApplicationCommandLine command_line) {
command_line.print ("Usage: tuf-cli COMMAND [SUBCOMMAND] ...\n\n");
command_line.print (" version Print the version of tuf-cli\n");
@ -398,7 +508,8 @@ namespace TUFManager {
}
/**
* This method releases the command line program from it's loop
* This method releases the command line program from it's hold
* This will should be called when by a signal from the server to release the program
*/
public void release_cli () {
#if ALWAYS_AUTHENTICATED
@ -410,6 +521,13 @@ namespace TUFManager {
this.release ();
}
/**
* The command line application starts here, we hold it in a loop until
* the serve responds and releases
*
* @param command_line The command line that is going to be used
* @return Returns the status code from our command line program
*/
public override int command_line (ApplicationCommandLine command_line) {
// keep the application running until we are done with this commandline
this.hold ();

View File

@ -16,42 +16,67 @@
* The TUF Manager namespace
*/
namespace TUFManager {
/**
* The TUF Server interface that is running in the background
*/
private TUFServerInterface tuf_server;
/**
* The bus name to send to the server to identify itself
*/
private BusName bus_name;
private void connect_dbus () throws TUFError {
/**
* Connect to the TUF Server daemon via dbus
*
* @throws TUFError Thrown when the server and the client versions don't match
*/
private void connect_tuf_server () throws TUFError {
bus_name = new BusName ("org.tuf.manager");
connect_tuf_server ();
if (get_server_version () != VERSION) {
throw new TUFError.UNMATCHED_VERSIONS ("The server and client versions do not match!");
}
}
private void connect_tuf_server () {
try {
tuf_server = Bus.get_proxy_sync (BusType.SYSTEM, "org.tuf.manager.server", "/org/tuf/manager/server");
}
catch (IOError e) {
stderr.printf ("Error: %s\n", e.message);
stderr.printf (_ ("Error: %s\n"), e.message);
}
string? server_version = get_server_version ();
if (server_version == null) {
return;
}
if (server_version != VERSION) {
throw new TUFError.UNMATCHED_VERSIONS (_ ("The server and client versions do not match!"));
}
}
/**
* Get the server version from the running daemon
*
* @return Returns a string containing the server version or null on failure
*/
private string? get_server_version () {
try {
return tuf_server.get_server_version ();
}
catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
stderr.printf (_ ("Error: %s\n"), e.message);
}
return null;
}
/**
* Get the mode the fan is in
*
* @return Returns the fan mode or -3 on error
*/
private int get_fan_mode () {
try {
return tuf_server.get_fan_mode ();
}
catch (TUFError e) {
stderr.printf ("Error: %s\n", e.message);
stderr.printf (_ ("Error: %s\n"), e.message);
}
catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
@ -59,6 +84,11 @@ namespace TUFManager {
return -3;
}
/**
* Set the fan mode
*
* @param mode The new mode to set
*/
private void set_fan_mode (int mode) {
try {
tuf_server.set_fan_mode (mode, bus_name);
@ -71,6 +101,11 @@ namespace TUFManager {
}
}
/**
* Get the current keyboard color
*
* @return Returns an RGBA struct containing the keyboard color or an initialized RGBA struct on error
*/
private Gdk.RGBA get_keyboard_color () {
try {
return tuf_server.get_keyboard_color ();
@ -84,6 +119,11 @@ namespace TUFManager {
return Gdk.RGBA ();
}
/**
* Set a new keyboard color
*
* @param color An RGBA struct containing the new color to set
*/
private void set_keyboard_color (Gdk.RGBA color) {
try {
tuf_server.set_keyboard_color (color, bus_name);
@ -96,6 +136,11 @@ namespace TUFManager {
}
}
/**
* Get the current lighting mode of the keyboard
*
* @return Returns the current keyboard lighting mode or -3 on error
*/
private int get_keyboard_mode () {
try {
return tuf_server.get_keyboard_mode ();
@ -109,6 +154,11 @@ namespace TUFManager {
return -3;
}
/**
* Set the keyboard lighting mode
*
* @param mode The new mode to set for the keyboard lighting
*/
private void set_keyboard_mode (int mode) {
try {
tuf_server.set_keyboard_mode (mode, bus_name);
@ -121,6 +171,11 @@ namespace TUFManager {
}
}
/**
* Get the current keyboard lighting speed
*
* @return Returns the current speed or -3 on error
*/
private int get_keyboard_speed () {
try {
return tuf_server.get_keyboard_speed ();
@ -134,6 +189,11 @@ namespace TUFManager {
return -3;
}
/**
* Set a new keyboard lighting speed
*
* @param speed The new speed to set
*/
private void set_keyboard_speed (int speed) {
try {
tuf_server.set_keyboard_speed (speed, bus_name);

View File

@ -20,19 +20,49 @@ namespace TUFManager {
* The package name used for translations
*/
public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@";
/**
* The version of the application
*/
public const string VERSION = "@VERSION@";
/**
* The location of the thermal control
*/
public const string THERMAL_PATH = "/sys/devices/platform/faustus/throttle_thermal_policy";
/**
* The location of the red hue control
*/
public const string RED_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_red";
/**
* The location of the green hue control
*/
public const string GREEN_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_green";
/**
* The location of the blue hue control
*/
public const string BLUE_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_blue";
/**
* The location of the keyboard mode control
*/
public const string KEYBOARD_MODE_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_mode";
/**
* The location of the flags for the keyboard control
*/
public const string KEYBOARD_FLAGS_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_flags";
/**
* The location of the keyboard lighting speed control
*/
public const string KEYBOARD_SPEED_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_speed";
/**
* The location of the keyboard set control
*/
public const string KEYBOARD_SET_PATH = "/sys/devices/platform/faustus/kbbl/kbbl_set";
}

View File

@ -29,6 +29,10 @@ namespace TUFManager {
* This is used to make sure that the sysfs files are not written to until everything is initialized
*/
private bool initialized = false;
/**
* The settings object from gschema/dconf
*/
private Settings settings;
/**
@ -37,9 +41,15 @@ namespace TUFManager {
[GtkChild]
private Gtk.ComboBoxText fan_mode;
/**
* They keyboard mode combo box
*/
[GtkChild]
private Gtk.ComboBoxText keyboard_mode;
/**
* The keyboard speed combox box
*/
[GtkChild]
private Gtk.ComboBoxText keyboard_speed;
@ -57,10 +67,13 @@ namespace TUFManager {
Object (application: application);
}
/**
* This is called after the window is created to initialize it's interface
*/
public void initialize () {
settings = new Settings ("org.tuf.manager");
try {
connect_dbus ();
connect_tuf_server ();
}
catch (TUFError e) {
stderr.printf ("Error: %s:\n", e.message);
@ -87,9 +100,6 @@ namespace TUFManager {
}
else {
// Get the fan speed
// 0 - normal
// 1 - boost
// 2 - silent
var mode = get_fan_mode ();
if (mode >= 0) {
fan_mode.set_active (mode);
@ -135,6 +145,10 @@ namespace TUFManager {
}
}
/**
* Used to restore the previous config from donf
* TODO: Move this to a status bar app and/or user daemon
*/
public void restore () {
var mode = settings.get_int ("fan-mode");
if (mode >= 0 && mode <= 2) {
@ -182,9 +196,6 @@ namespace TUFManager {
/**
* Called when the user changes the fan mode
*
* * 1 - normal mode
* * 2 - boost mode
* * 3 - silent mode
* @param combo_box The combo box that changed
*/
[GtkCallback]
@ -199,6 +210,7 @@ namespace TUFManager {
/**
* Called when the user changes the keyboard lighting mode
*
* @param combo_box The combo box that changed
*/
[GtkCallback]
@ -223,6 +235,11 @@ namespace TUFManager {
}
}
/**
* Called when the user changes the keyboard lighting speed
*
* @param combo_box The combo box that changed
*/
[GtkCallback]
public void on_speed_changed (Gtk.ComboBox combo_box) {
if (initialized) {
@ -233,6 +250,11 @@ namespace TUFManager {
}
}
/**
* Called when the user clicks the set color button
*
* @param button The button that was clicked
*/
[GtkCallback]
public void on_set_color_clicked (Gtk.Button button) {
if (initialized) {

View File

@ -22,7 +22,7 @@ namespace TUFManager {
namespace GUI {
/**
* The application class
* The GUI application class
*/
public class TUFManagerApp : Gtk.Application {
/**
@ -38,7 +38,7 @@ namespace TUFManager {
}
/**
* Run when the application is activated
* Run when the application is activated, we call and show the window here
*/
public override void activate () {
window = new MainWindow (this);
@ -48,7 +48,7 @@ namespace TUFManager {
}
/**
* Run when the application starts
* Run when the application starts, we set the language here
*/
public override void startup () {
Intl.textdomain (GETTEXT_PACKAGE);

View File

@ -17,7 +17,7 @@
*/
namespace TUFManager {
/**
* The entry point to the TUF Manager application
* The entry point to the TUF Manager UI applications
*
* @param args Arguments passed from the command line
* @return Returns the status from the application
@ -28,10 +28,10 @@ namespace TUFManager {
application.register ();
}
catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
stderr.printf (_ ("Error: %s\n"), e.message);
}
if (application.get_is_remote ()) {
stderr.printf ("Error: %s\n", _ ("Another instance of TUF Manager is already running!"));
stderr.printf (_ ("Error: %s\n"), _ ("Another instance of TUF Manager is already running!"));
return -1;
}
return application.run (args);

View File

@ -21,15 +21,106 @@ namespace TUFManager {
*/
[DBus (name = "org.tuf.manager.server")]
public interface TUFServerInterface : Object {
public abstract string get_server_version () throws Error;
public abstract int get_fan_mode () throws Error, TUFError;
public abstract void set_fan_mode (int mode, BusName sender) throws Error, TUFError;
public abstract Gdk.RGBA get_keyboard_color () throws Error, TUFError;
public abstract void set_keyboard_color (Gdk.RGBA color, BusName sender) throws Error, TUFError;
public abstract int get_keyboard_mode () throws Error, TUFError;
public abstract void set_keyboard_mode (int mode, BusName sender) throws Error, TUFError;
public abstract int get_keyboard_speed () throws Error, TUFError;
public abstract void set_keyboard_speed (int speed, BusName sender) throws Error, TUFError;
/**
* This signal is emited when a procedure finishes
*/
public signal void procedure_finished ();
/**
* Get the version of the currently running server
*
* @return Returns a string containing the version
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
*/
public abstract string get_server_version () throws Error;
/**
* Get the current fan mode
*
* @return Returns the current fan mode
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem reading a value from the stream
*/
public abstract int get_fan_mode () throws Error, TUFError;
/**
* Set a new fan mode
*
* * 0 - balanced mode
* * 1 - turbo mode
* * 2 - silent mode
*
* @param mode The new mode to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract void set_fan_mode (int mode, BusName sender) throws Error, TUFError;
/**
* Get the current keyboard color
*
* @return Returns an RGBA struct containing the color
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract Gdk.RGBA get_keyboard_color () throws Error, TUFError;
/**
* Set the keyboard color
*
* @param color The new RGBA color to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract void set_keyboard_color (Gdk.RGBA color, BusName sender) throws Error, TUFError;
/**
* Get the current keyboard mode
*
* @return Returns the mode
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract int get_keyboard_mode () throws Error, TUFError;
/**
* Set a new keyboard mode
*
* * 0 - static
* * 1 - breathing
* * 2 - color cycle
* * 3 - strobing
*
* @param mode The new mode to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract void set_keyboard_mode (int mode, BusName sender) throws Error, TUFError;
/**
* Get the current keyboard lighting speed
*
* @return The current speed
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract int get_keyboard_speed () throws Error, TUFError;
/**
* Set a new keyboard speed
*
* * 0 - slow
* * 1 - medium
* * 2 - fast
*
* @param speed The new speed to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public abstract void set_keyboard_speed (int speed, BusName sender) throws Error, TUFError;
}
}

View File

@ -21,13 +21,24 @@ namespace TUFManager {
* and handling root related tasks
*/
namespace Server {
/**
* Run the process in the foreground
*/
private static bool foreground = false;
/**
* The command line arguments available
*/
private const OptionEntry[] options = {
{ "foreground", 'f', 0, OptionArg.NONE, ref foreground, N_ ("Run the daemon in the foreground"), null },
{ null }
};
/**
* Called when the server should exit
*
* @param signum The signal that caused the server to exit
*/
private static void on_exit (int signum) {
if (loop != null) {
loop.quit ();

View File

@ -25,6 +25,7 @@ namespace TUFManager {
* The global instance of the server running as a dbus daemon
*/
TUFServer tuf_server;
/**
* The loop of the dbus daemon running in the background
*/
@ -40,13 +41,13 @@ namespace TUFManager {
tuf_server = new TUFManager.Server.TUFServer ();
}
catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
stderr.printf (_ ("Error: %s\n"), e.message);
}
try {
conn.register_object ("/org/tuf/manager/server", tuf_server);
}
catch (IOError e) {
stderr.printf ("Could not register service\n");
stderr.printf (_ ("Error: Could not register service\n"));
if (loop != null) {
loop.quit ();
}
@ -59,10 +60,32 @@ namespace TUFManager {
*/
[DBus (name = "org.tuf.manager.server")]
public class TUFServer : Object {
/**
* We use this mutex to lock procedures
*/
private Mutex locked;
#if ALWAYS_AUTHENTICATED
#else
/**
* This mutex is used to lock the authorization process via polkit
*/
private Mutex authorization;
/**
* A list of authorized senders so that they don't need to reauthenicate constantly
*/
private GenericSet<string> authorized_senders;
/**
* The main thread context used in fast authentication when reauthenticating
*/
private MainContext context;
#endif
/**
* This signal is emited when a procedure finishes
*/
public signal void procedure_finished ();
/**
@ -71,10 +94,13 @@ namespace TUFManager {
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
*/
public TUFServer () throws Error {
locked = Mutex ();
#if ALWAYS_AUTHENTICATED
#else
authorization = Mutex ();
authorized_senders = new GenericSet<string> (str_hash, str_equal);
context = MainContext.ref_thread_default ();
#endif
locked = Mutex ();
}
/**
@ -111,14 +137,8 @@ namespace TUFManager {
authorized = result.get_is_authorized ();
}
catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
stderr.printf (_ ("Error: %s\n"), e.message);
}
/*if (!authorized) {
stderr.printf ("%s\n", _ ("Authentication failed!"));
}
else {
stderr.printf ("%s\n", _ ("Authentication passed!"));
}*/
return authorized;
#endif
}
@ -162,11 +182,12 @@ namespace TUFManager {
/**
* Set a new fan mode
*
* * 1 - normal mode
* * 2 - boost mode
* * 3 - silent mode
* * 0 - balanced mode
* * 1 - turbo mode
* * 2 - silent mode
*
* @param mode The new mode to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
@ -201,6 +222,14 @@ namespace TUFManager {
});
}
/**
* The user was authorized to set the mode, here we do it
*
* @param mode The new mode to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
private void set_fan_mode_authorized (int mode, BusName sender) throws Error, TUFError {
locked.lock ();
var stream = FileStream.open (THERMAL_PATH, "w");
@ -219,6 +248,13 @@ namespace TUFManager {
procedure_finished ();
}
/**
* Get the current keyboard color
*
* @return Returns an RGBA struct containing the color
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public Gdk.RGBA get_keyboard_color () throws Error, TUFError {
string color = "#";
@ -267,6 +303,14 @@ namespace TUFManager {
return rgba;
}
/**
* Set the keyboard color
*
* @param color The new RGBA color to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public void set_keyboard_color (Gdk.RGBA color, BusName sender) throws Error, TUFError {
get_authorization.begin (sender, (obj, res) => {
bool authorized = false;
@ -298,6 +342,14 @@ namespace TUFManager {
});
}
/**
* The user was authorized to set the color, here we do it
*
* @param color The new RGBA color to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
private void set_keyboard_color_authorized (Gdk.RGBA color, BusName sender) throws Error, TUFError {
locked.lock ();
@ -346,6 +398,13 @@ namespace TUFManager {
procedure_finished ();
}
/**
* Get the current keyboard mode
*
* @return Returns the mode
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public int get_keyboard_mode () throws Error, TUFError {
var stream = FileStream.open (KEYBOARD_MODE_PATH, "r");
if (stream == null) {
@ -365,6 +424,19 @@ namespace TUFManager {
return mode;
}
/**
* Set a new keyboard mode
*
* * 0 - static
* * 1 - breathing
* * 2 - color cycle
* * 3 - strobing
*
* @param mode The new mode to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public void set_keyboard_mode (int mode, BusName sender) throws Error, TUFError {
get_authorization.begin (sender, (obj, res) => {
bool authorized = false;
@ -396,6 +468,14 @@ namespace TUFManager {
});
}
/**
* The user was authorized to set the mode, here we do it
*
* @param mode The new mode to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
private void set_keyboard_mode_authorized (int mode, BusName sender) throws Error, TUFError {
locked.lock ();
var keyboard_set = "1";
@ -431,6 +511,13 @@ namespace TUFManager {
procedure_finished ();
}
/**
* Get the current keyboard lighting speed
*
* @return The current speed
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public int get_keyboard_speed () throws Error, TUFError {
var stream = FileStream.open (KEYBOARD_SPEED_PATH, "r");
if (stream == null) {
@ -442,14 +529,26 @@ namespace TUFManager {
throw new TUFError.INVALID_VALUE (_ ("File is empty!"));
}
var mode = int.parse (line);
if (mode < 0 || mode > 2) {
var speed = int.parse (line);
if (speed < 0 || speed > 2) {
throw new TUFError.INVALID_VALUE (_ ("File contains invalid value!"));
}
return mode;
return speed;
}
/**
* Set a new keyboard speed
*
* * 0 - slow
* * 1 - medium
* * 2 - fast
*
* @param speed The new speed to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
public void set_keyboard_speed (int speed, BusName sender) throws Error, TUFError {
get_authorization.begin (sender, (obj, res) => {
bool authorized = false;
@ -481,6 +580,14 @@ namespace TUFManager {
});
}
/**
* The user was authorized to set the speed, here we do it
*
* @param speed The new speed to set
* @param sender The bus that sent the request
* @throws Error Thrown if there is a problem connecting to a dbus session or an IO error
* @throws TUFError Thrown if there is a problem writing a value to the stream
*/
private void set_keyboard_speed_authorized (int speed, BusName sender) throws Error, TUFError {
locked.lock ();
var keyboard_set = "1";