mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-08-05 20:58:29 +02:00
Add support for user defined local script plugins
A much requested feature, this allows for providing custom scripts in the config file. An example in the man page is below and would trigger both a system notification, and allow control over a background crypto mining script automatically in gamemode. [custom] ; Custom scripts (executed using the shell) when gamemode starts and ends start=notify-send "GameMode started" /home/me/bin/stop_ethmining.sh end=notify-send "GameMode ended" /home/me/bin/start_ethmining.sh Scripts are run with system() and do not have any special privilages, as with the rest of the daemon, custom scripts that require root will need their own permissions set up externally. This commit also renames two defines as they needed to be moved to the public interface.
This commit is contained in:
@@ -161,6 +161,21 @@ static void game_mode_context_enter(GameModeContext *self)
|
||||
LOG_MSG("Entering Game Mode...\n");
|
||||
sd_notifyf(0, "STATUS=%sGameMode is now active.%s\n", "\x1B[1;32m", "\x1B[0m");
|
||||
|
||||
char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
|
||||
memset(scripts, 0, sizeof(scripts));
|
||||
config_get_gamemode_start_scripts(self->config, scripts);
|
||||
|
||||
unsigned int i = 0;
|
||||
while (*scripts[i] != '\0' && i < CONFIG_LIST_MAX) {
|
||||
LOG_MSG("Executing script [%s]\n", scripts[i]);
|
||||
int err;
|
||||
if ((err = system(scripts[i])) != 0) {
|
||||
/* Log the failure, but this is not fatal */
|
||||
LOG_ERROR("Script [%s] failed with error %d\n", scripts[i], err);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (!self->performance_mode && set_governors("performance")) {
|
||||
self->performance_mode = true;
|
||||
}
|
||||
@@ -180,6 +195,21 @@ static void game_mode_context_leave(GameModeContext *self)
|
||||
if (self->performance_mode && set_governors(NULL)) {
|
||||
self->performance_mode = false;
|
||||
}
|
||||
|
||||
char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
|
||||
memset(scripts, 0, sizeof(scripts));
|
||||
config_get_gamemode_end_scripts(self->config, scripts);
|
||||
|
||||
unsigned int i = 0;
|
||||
while (*scripts[i] != '\0' && i < CONFIG_LIST_MAX) {
|
||||
LOG_MSG("Executing script [%s]\n", scripts[i]);
|
||||
int err;
|
||||
if ((err = system(scripts[i])) != 0) {
|
||||
/* Log the failure, but this is not fatal */
|
||||
LOG_ERROR("Script [%s] failed with error %d\n", scripts[i], err);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user