Skip to content

Commit d7f691f

Browse files
committed
Enhance self-update function with terminal detection and user prompt for updates
1 parent 7770612 commit d7f691f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

minecraft.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,25 @@ selfUpdate() {
4141
fi
4242
# Compare files byte-for-byte
4343
if ! cmp -s "$tmpfile" "$script_path"; then
44-
# If not running in a terminal, relaunch in a terminal emulator for the update prompt
44+
# --- Terminal Detection and Relaunch Logic ---
45+
# If not running in an interactive shell (no $PS1), not launched by a terminal program, and not attached to a tty,
46+
# then we are likely running from a GUI (e.g., .desktop launcher) and cannot prompt the user for input.
4547
if [ -z "$PS1" ] && [ -z "$TERM_PROGRAM" ] && ! tty -s; then
46-
# Try to find a terminal emulator
48+
# Try to find a terminal emulator to relaunch the script for the update prompt.
49+
# This loop checks for common terminal emulators in order of preference.
4750
for term in x-terminal-emulator gnome-terminal konsole xfce4-terminal xterm; do
4851
if command -v $term >/dev/null 2>&1; then
52+
# Relaunch this script in the found terminal emulator, passing all arguments.
4953
exec $term -e "$script_path" "$@"
5054
fi
5155
done
56+
# If no terminal emulator is found, print an error and exit.
5257
echo "[Self-Update] Update available, but no terminal found for prompt. Please run this script from a terminal to update." >&2
5358
rm -f "$tmpfile"
5459
exit 1
5560
fi
61+
# --- Interactive Update Prompt ---
62+
# If we are running in a terminal, prompt the user for update confirmation.
5663
echo "[Self-Update] A new version is available. Update now? [y/N]"
5764
read -r answer
5865
if [[ "$answer" =~ ^[Yy]$ ]]; then

0 commit comments

Comments
 (0)