Add option to run command before UI is initialised (closes #798)

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2025-12-02 22:23:10 +01:00
parent b249dba092
commit 1c99574f73
25 changed files with 46 additions and 0 deletions

View File

@@ -79,6 +79,7 @@ shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
shutdown_key: []const u8 = "F1",
sleep_cmd: ?[]const u8 = null,
sleep_key: []const u8 = "F3",
start_cmd: ?[]const u8 = null,
text_in_center: bool = false,
vi_default_mode: ViMode = .normal,
vi_mode: bool = false,

View File

@@ -51,6 +51,7 @@ err_perm_group: []const u8 = "failed to downgrade group permissions",
err_perm_user: []const u8 = "failed to downgrade user permissions",
err_pwnam: []const u8 = "failed to get user info",
err_sleep: []const u8 = "failed to execute sleep command",
err_start: []const u8 = "failed to execute start command",
err_battery: []const u8 = "failed to load battery status",
err_switch_tty: []const u8 = "failed to switch tty",
err_tty_ctrl: []const u8 = "tty control transfer failed",

View File

@@ -124,6 +124,7 @@ pub fn main() !void {
var lang: Lang = undefined;
var old_save_file_exists = false;
var maybe_config_load_error: ?anyerror = null;
var start_cmd_exit_code: u8 = 0;
var can_get_lock_state = true;
var can_draw_clock = true;
var can_draw_battery = true;
@@ -282,6 +283,19 @@ pub fn main() !void {
restart_cmd = try temporary_allocator.dupe(u8, config.restart_cmd);
commands_allocated = true;
if (config.start_cmd) |start_cmd| {
var sleep = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", start_cmd }, allocator);
sleep.stdout_behavior = .Ignore;
sleep.stderr_behavior = .Ignore;
handle_start_cmd: {
const process_result = sleep.spawnAndWait() catch {
break :handle_start_cmd;
};
start_cmd_exit_code = process_result.Exited;
}
}
// Initialize termbox
try log_writer.writeAll("initializing termbox2\n");
_ = termbox.tb_init();
@@ -351,6 +365,11 @@ pub fn main() !void {
try log_writer.print("failed to get uid range: {s}; falling back to default\n", .{@errorName(err)});
}
if (start_cmd_exit_code != 0) {
try info_line.addMessage(lang.err_start, config.error_bg, config.error_fg);
try log_writer.print("failed to execute start command: exit code {d}\n", .{start_cmd_exit_code});
}
if (maybe_config_load_error) |err| {
// We can't localize this since the config failed to load so we'd fallback to the default language anyway
try info_line.addMessage("unable to parse config file", config.error_bg, config.error_fg);