Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::ui::{MessageType, UI};
use crate::utils;
use gtk::prelude::*;

pub struct GUI {
Expand Down Expand Up @@ -38,6 +39,20 @@ impl UI for GUI {
}

pub fn run_command(command: &str, escalate: bool) -> bool {
// For simple operations that don't need user interaction, run directly without terminal
// This prevents unnecessary terminal windows for operations like systemctl enable/disable
// Check if command is a simple systemctl enable/disable operation
let is_simple_command = command.trim_start().starts_with("systemctl")
&& (command.contains(" enable ") || command.contains(" disable "))
&& !command.contains("status") // status commands might need output
&& !command.contains("log"); // log commands need output

if is_simple_command {
// Run directly without spawning a terminal window
return utils::run_cmd(command.to_string(), escalate).map(|s| s.success()).unwrap_or(false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as of now it shouldn't spawn terminal window as it's using run_cmd

it also shouldn't spawn unnecessary auth prompts for systemctl operations as its handled by systemd already

Copy link
Copy Markdown
Author

@Obsidian-Jackal Obsidian-Jackal Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how the original flow of the code handled it. Are you sure you thoroughly tested how it was originally, before you made that comment?

Copy link
Copy Markdown
Member

@vnepogodin vnepogodin Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, wasn't able to reproduce it either

}

// For operations that may need user interaction or output viewing, use terminal
let cmd_formated = format!("{command}; read -p 'Press enter to exit'");
let mut args: Vec<&str> = vec![];
if escalate {
Expand Down
11 changes: 10 additions & 1 deletion src/scripts/rootshell.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/bin/bash
# Modified to run commands directly without spawning a terminal
# This allows pkexec to show authentication popup without terminal window

exec bash $@
# If arguments are provided, execute them directly as a command
if [ $# -gt 0 ]; then
# Execute the command directly without spawning interactive shell
exec bash -c "$*"
else
# If no arguments, just run bash non-interactively (should not happen)
exec bash --norc --noprofile
fi
30 changes: 26 additions & 4 deletions src/scripts/terminal-helper
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare -A terminals=(
["terminator"]="terminator -x $cmd"
["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'"
["xterm"]="xterm -e $cmd"
["x-terminal-emulator"]="x-terminal-emulator -e $cmd"
)
declare -a term_order=(
"alacritty"
Expand All @@ -77,6 +78,17 @@ declare -a term_order=(
"terminator"
)

# Check $TERMINAL environment variable first (as per invariants)
if [ -n "$TERMINAL" ] && command -v "$TERMINAL" >/dev/null 2>&1; then
terminal="$TERMINAL"
fi

# Check x-terminal-emulator second (distribution-specific mechanism)
if [ -z "$terminal" ] && command -v x-terminal-emulator >/dev/null 2>&1; then
terminal="x-terminal-emulator"
fi

# Fall back to hardcoded list if neither $TERMINAL nor x-terminal-emulator worked
if [ -z "$terminal" ] || ! command -v "$terminal" &>/dev/null; then
for entry in "${term_order[@]}"; do
if command -v "$entry" >/dev/null 2>&1; then
Expand All @@ -94,10 +106,20 @@ if [ -z "$terminal" ]; then
exit 1
fi

eval "${terminals[${terminal}]}" 2>/dev/null || {
if [[ "$terminal" != "kgx" ]]; then
# Execute the terminal command
if [ -n "${terminals[${terminal}]}" ]; then
# Terminal is in our predefined list, use the configured command
eval "${terminals[${terminal}]}" 2>/dev/null || {
if [[ "$terminal" != "kgx" ]]; then
rm "$file"
exit 2
fi
}
else
# Terminal is not in our list (e.g., from $TERMINAL env var), use generic -e flag
eval "$terminal -e $cmd" 2>/dev/null || {
rm "$file"
exit 2
fi
}
}
fi
rm "$file"
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub fn run_cmd_terminal(callback: RunCmdCallback, cmd: String, escalate: bool) -

pub fn run_cmd(cmd: String, escalate: bool) -> anyhow::Result<ExitStatus> {
if escalate {
// pkexec bash -c doesn't spawn a terminal, just shows auth dialog
Ok(Exec::cmd("/sbin/pkexec").arg("bash").arg("-c").arg(cmd).join()?)
} else {
Ok(Exec::cmd("/sbin/bash").arg("-c").arg(cmd).join()?)
Expand Down