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

@@ -312,6 +312,10 @@ sleep_cmd = null
# Specifies the key used for sleep (F1-F12) # Specifies the key used for sleep (F1-F12)
sleep_key = F3 sleep_key = F3
# Command executed when starting Ly (before the TTY is taken control of)
# If null, no command will be executed
start_cmd = null
# Center the session name. # Center the session name.
text_in_center = false text_in_center = false

View File

@@ -48,6 +48,7 @@ err_pwnam = فشل في جلب معلومات المستخدم
err_sleep = فشل في تنفيذ أمر sleep err_sleep = فشل في تنفيذ أمر sleep
err_tty_ctrl = فشل في نقل تحكم الطرفية (TTY) err_tty_ctrl = فشل في نقل تحكم الطرفية (TTY)

View File

@@ -46,6 +46,7 @@ err_perm_group = неуспешно понижаване на правата н
err_perm_user = неуспешно понижаване на правата на потребителя err_perm_user = неуспешно понижаване на правата на потребителя
err_pwnam = неуспешно получаване на информация за потребителя err_pwnam = неуспешно получаване на информация за потребителя
err_sleep = неуспешно изпълнение на командата за заспиване err_sleep = неуспешно изпълнение на командата за заспиване
err_battery = неуспешно зареждане на състоянието на батерията err_battery = неуспешно зареждане на състоянието на батерията
err_switch_tty = неуспешна смяна на TTY err_switch_tty = неуспешна смяна на TTY
err_tty_ctrl = неуспешно прехвърляне на контрола над TTY err_tty_ctrl = неуспешно прехвърляне на контрола над TTY

View File

@@ -51,6 +51,7 @@ err_pwnam = error en obtenir la informació de l'usuari
err_user_gid = error en establir el GID de l'usuari err_user_gid = error en establir el GID de l'usuari
err_user_init = error en inicialitzar usuari err_user_init = error en inicialitzar usuari
err_user_uid = error en establir l'UID de l'usuari err_user_uid = error en establir l'UID de l'usuari

View File

@@ -51,6 +51,7 @@ err_pwnam = nelze získat informace o uživateli
err_user_gid = nastavení GID uživatele selhalo err_user_gid = nastavení GID uživatele selhalo
err_user_init = inicializace uživatele selhala err_user_init = inicializace uživatele selhala
err_user_uid = nastavení UID uživateli selhalo err_user_uid = nastavení UID uživateli selhalo

View File

@@ -48,6 +48,7 @@ err_pwnam = Abrufen der Benutzerinformationen fehlgeschlagen
err_sleep = Sleep-Befehl fehlgeschlagen err_sleep = Sleep-Befehl fehlgeschlagen
err_tty_ctrl = Fehler bei der TTY-Uebergabe err_tty_ctrl = Fehler bei der TTY-Uebergabe

View File

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

View File

@@ -51,6 +51,7 @@ err_pwnam = error al obtener la información del usuario
err_user_gid = error al establecer el GID del usuario err_user_gid = error al establecer el GID del usuario
err_user_init = error al inicializar usuario err_user_init = error al inicializar usuario
err_user_uid = error al establecer el UID del usuario err_user_uid = error al establecer el UID del usuario

View File

@@ -46,6 +46,7 @@ err_perm_group = échec du déclassement des permissions de groupe
err_perm_user = échec du déclassement des permissions utilisateur err_perm_user = échec du déclassement des permissions utilisateur
err_pwnam = échec de lecture des infos utilisateur err_pwnam = échec de lecture des infos utilisateur
err_sleep = échec de l'exécution de la commande de veille err_sleep = échec de l'exécution de la commande de veille
err_start = échec de l'exécution de la commande de démarrage
err_battery = échec de lecture de l'état de la batterie err_battery = échec de lecture de l'état de la batterie
err_switch_tty = échec du changement de terminal err_switch_tty = échec du changement de terminal
err_tty_ctrl = échec du transfert de contrôle du terminal err_tty_ctrl = échec du transfert de contrôle du terminal

View File

@@ -51,6 +51,7 @@ err_pwnam = impossibile ottenere dati utente
err_user_gid = impossibile impostare GID utente err_user_gid = impossibile impostare GID utente
err_user_init = impossibile inizializzare utente err_user_init = impossibile inizializzare utente
err_user_uid = impossible impostare UID utente err_user_uid = impossible impostare UID utente

View File

@@ -48,6 +48,7 @@ err_pwnam = ユーザー情報の取得に失敗しました
err_sleep = スリープコマンドの実行に失敗しました err_sleep = スリープコマンドの実行に失敗しました
err_tty_ctrl = TTY制御の転送に失敗しました err_tty_ctrl = TTY制御の転送に失敗しました

View File

@@ -46,6 +46,7 @@ err_perm_group = neizdevās pazemināt grupas atļaujas
err_perm_user = neizdevās pazemināt lietotāja atļaujas err_perm_user = neizdevās pazemināt lietotāja atļaujas
err_pwnam = neizdevās iegūt lietotāja informāciju err_pwnam = neizdevās iegūt lietotāja informāciju
err_sleep = neizdevās izpildīt miega komandu err_sleep = neizdevās izpildīt miega komandu
err_battery = neizdevās ielādēt akumulatora stāvokli err_battery = neizdevās ielādēt akumulatora stāvokli
err_switch_tty = neizdevās pārslēgt tty err_switch_tty = neizdevās pārslēgt tty
err_tty_ctrl = tty vadības nodošana neizdevās err_tty_ctrl = tty vadības nodošana neizdevās

View File

@@ -46,6 +46,7 @@ err_perm_group = nie udało się obniżyć uprawnień grupy
err_perm_user = nie udało się obniżyć uprawnień użytkownika err_perm_user = nie udało się obniżyć uprawnień użytkownika
err_pwnam = nie udało się uzyskać informacji o użytkowniku err_pwnam = nie udało się uzyskać informacji o użytkowniku
err_sleep = nie udało się wykonać polecenia sleep err_sleep = nie udało się wykonać polecenia sleep
err_battery = nie udało się sprawdzić statusu baterii err_battery = nie udało się sprawdzić statusu baterii
err_switch_tty = nie można przełączyć tty err_switch_tty = nie można przełączyć tty
err_tty_ctrl = nie udało się przekazać kontroli tty err_tty_ctrl = nie udało się przekazać kontroli tty

View File

@@ -51,6 +51,7 @@ err_pwnam = erro ao obter informação do utilizador
err_user_gid = erro ao definir o GID do utilizador err_user_gid = erro ao definir o GID do utilizador
err_user_init = erro ao iniciar o utilizador err_user_init = erro ao iniciar o utilizador
err_user_uid = erro ao definir o UID do utilizador err_user_uid = erro ao definir o UID do utilizador

View File

@@ -51,6 +51,7 @@ err_pwnam = não foi possível obter informações do usuário
err_user_gid = não foi possível definir o GID do usuário err_user_gid = não foi possível definir o GID do usuário
err_user_init = não foi possível iniciar o usuário err_user_init = não foi possível iniciar o usuário
err_user_uid = não foi possível definir o UID do usuário err_user_uid = não foi possível definir o UID do usuário

View File

@@ -60,6 +60,7 @@ err_perm_user = nu s-a putut face downgrade permisiunilor de utilizator
login = utilizator login = utilizator
logout = opreşte sesiunea logout = opreşte sesiunea

View File

@@ -46,6 +46,7 @@ err_perm_group = не удалось понизить права доступа
err_perm_user = не удалось понизить права доступа пользователя err_perm_user = не удалось понизить права доступа пользователя
err_pwnam = не удалось получить информацию о пользователе err_pwnam = не удалось получить информацию о пользователе
err_sleep = не удалось выполнить команду sleep err_sleep = не удалось выполнить команду sleep
err_battery = не удалось получить статус батареи err_battery = не удалось получить статус батареи
err_switch_tty = не удалось переключить tty err_switch_tty = не удалось переключить tty
err_tty_ctrl = передача управления tty не удалась err_tty_ctrl = передача управления tty не удалась

View File

@@ -51,6 +51,7 @@ err_pwnam = neuspijesno skupljanje informacija o korisniku
err_user_gid = neuspijesno postavljanje korisničkog GID-a err_user_gid = neuspijesno postavljanje korisničkog GID-a
err_user_init = neuspijensa inicijalizacija korisnika err_user_init = neuspijensa inicijalizacija korisnika
err_user_uid = neuspijesno postavljanje UID-a korisnika err_user_uid = neuspijesno postavljanje UID-a korisnika

View File

@@ -51,6 +51,7 @@ err_pwnam = misslyckades att hämta användarinfo
err_user_gid = misslyckades att ställa in användar-GID err_user_gid = misslyckades att ställa in användar-GID
err_user_init = misslyckades att initialisera användaren err_user_init = misslyckades att initialisera användaren
err_user_uid = misslyckades att ställa in användar-UID err_user_uid = misslyckades att ställa in användar-UID

View File

@@ -51,6 +51,7 @@ err_pwnam = kullanici bilgileri alinamadi
err_user_gid = kullanici icin GID ayarlanamadi err_user_gid = kullanici icin GID ayarlanamadi
err_user_init = kullanici oturumu baslatilamadi err_user_init = kullanici oturumu baslatilamadi
err_user_uid = kullanici icin UID ayarlanamadi err_user_uid = kullanici icin UID ayarlanamadi

View File

@@ -51,6 +51,7 @@ err_pwnam = не вдалося отримати дані користувача
err_user_gid = не вдалося змінити GID користувача err_user_gid = не вдалося змінити GID користувача
err_user_init = не вдалося ініціалізувати користувача err_user_init = не вдалося ініціалізувати користувача
err_user_uid = не вдалося змінити UID користувача err_user_uid = не вдалося змінити UID користувача

View File

@@ -51,6 +51,7 @@ err_pwnam = 获取用户信息失败
err_user_gid = 设置用户GID失败 err_user_gid = 设置用户GID失败
err_user_init = 初始化用户失败 err_user_init = 初始化用户失败
err_user_uid = 设置用户UID失败 err_user_uid = 设置用户UID失败

View File

@@ -79,6 +79,7 @@ shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
shutdown_key: []const u8 = "F1", shutdown_key: []const u8 = "F1",
sleep_cmd: ?[]const u8 = null, sleep_cmd: ?[]const u8 = null,
sleep_key: []const u8 = "F3", sleep_key: []const u8 = "F3",
start_cmd: ?[]const u8 = null,
text_in_center: bool = false, text_in_center: bool = false,
vi_default_mode: ViMode = .normal, vi_default_mode: ViMode = .normal,
vi_mode: bool = false, 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_perm_user: []const u8 = "failed to downgrade user permissions",
err_pwnam: []const u8 = "failed to get user info", err_pwnam: []const u8 = "failed to get user info",
err_sleep: []const u8 = "failed to execute sleep command", 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_battery: []const u8 = "failed to load battery status",
err_switch_tty: []const u8 = "failed to switch tty", err_switch_tty: []const u8 = "failed to switch tty",
err_tty_ctrl: []const u8 = "tty control transfer failed", err_tty_ctrl: []const u8 = "tty control transfer failed",

View File

@@ -124,6 +124,7 @@ pub fn main() !void {
var lang: Lang = undefined; var lang: Lang = undefined;
var old_save_file_exists = false; var old_save_file_exists = false;
var maybe_config_load_error: ?anyerror = null; var maybe_config_load_error: ?anyerror = null;
var start_cmd_exit_code: u8 = 0;
var can_get_lock_state = true; var can_get_lock_state = true;
var can_draw_clock = true; var can_draw_clock = true;
var can_draw_battery = true; var can_draw_battery = true;
@@ -282,6 +283,19 @@ pub fn main() !void {
restart_cmd = try temporary_allocator.dupe(u8, config.restart_cmd); restart_cmd = try temporary_allocator.dupe(u8, config.restart_cmd);
commands_allocated = true; 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 // Initialize termbox
try log_writer.writeAll("initializing termbox2\n"); try log_writer.writeAll("initializing termbox2\n");
_ = termbox.tb_init(); _ = 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)}); 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| { 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 // 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); try info_line.addMessage("unable to parse config file", config.error_bg, config.error_fg);