Skip to content

Commit 1ae4210

Browse files
committed
foreground
1 parent d36e4a2 commit 1ae4210

4 files changed

Lines changed: 88 additions & 16 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,16 @@ platforms/linux/install-gnome-autostart.sh -- -c examples/t2.yml -n -i
218218
```
219219

220220
This writes `~/.config/autostart/ppuc-pinmame.desktop` with absolute paths to the
221-
generated `ppuc/ppuc-pinmame` binary and the selected config file. Pass the same
222-
arguments you normally use on the command line after `--`.
221+
generated launcher and starts `ppuc-pinmame` in a terminal window so the process
222+
stays attached to the foreground session. Pass the same arguments you normally
223+
use on the command line after `--`.
224+
225+
By default the installer prefers `gnome-terminal`, then `kgx`, then
226+
`x-terminal-emulator`. Override that with:
227+
228+
```shell
229+
platforms/linux/install-gnome-autostart.sh --terminal gnome-terminal -- -c examples/t2.yml -n -i
230+
```
223231

224232
Remove the autostart entry with:
225233

platforms/linux/autostart/ppuc-pinmame.desktop.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Version=1.0
44
Name=PPUC PinMAME
55
Comment=Start ppuc-pinmame automatically when the GNOME session begins
66
Terminal=false
7-
Path=@PPUC_WORKDIR@
8-
Exec=@PPUC_EXEC@
7+
Exec=@AUTOSTART_EXEC@
98
X-GNOME-Autostart-enabled=true
109
StartupNotify=false
1110
Categories=Game;

platforms/linux/install-gnome-autostart.sh

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ set -euo pipefail
55
usage() {
66
cat <<'USAGE'
77
Usage:
8-
platforms/linux/install-gnome-autostart.sh [--repo-root PATH] [--autostart-name NAME] -- <ppuc-pinmame args...>
8+
platforms/linux/install-gnome-autostart.sh [--repo-root PATH] [--autostart-name NAME] [--terminal CMD] -- <ppuc-pinmame args...>
99
1010
Examples:
1111
platforms/linux/install-gnome-autostart.sh -- -c examples/t2.yml -n -i
1212
platforms/linux/install-gnome-autostart.sh --repo-root /opt/ppuc -- -c /opt/ppuc/examples/t2.yml -n -i
13+
platforms/linux/install-gnome-autostart.sh --terminal kgx -- -c examples/t2.yml -n -i
1314
1415
Notes:
1516
- The script writes ~/.config/autostart/<name>.desktop for GNOME/XDG autostart.
17+
- It also writes a small launcher script under ~/.local/share/ppuc/autostart/.
1618
- The repo build output is expected at <repo-root>/ppuc/ppuc-pinmame.
1719
- Any relative paths after -- are resolved from <repo-root> before being written.
1820
USAGE
1921
}
2022

2123
repo_root="$(pwd)"
2224
autostart_name="ppuc-pinmame"
25+
terminal_cmd=""
2326

2427
while [[ $# -gt 0 ]]; do
2528
case "$1" in
@@ -33,6 +36,11 @@ while [[ $# -gt 0 ]]; do
3336
[[ $# -gt 0 ]] || { echo "Missing value for --autostart-name" >&2; exit 1; }
3437
autostart_name="$1"
3538
;;
39+
--terminal)
40+
shift
41+
[[ $# -gt 0 ]] || { echo "Missing value for --terminal" >&2; exit 1; }
42+
terminal_cmd="$1"
43+
;;
3644
--help|-h)
3745
usage
3846
exit 0
@@ -62,6 +70,9 @@ binary="$workdir/ppuc-pinmame"
6270
template="$repo_root/platforms/linux/autostart/ppuc-pinmame.desktop.in"
6371
autostart_dir="${XDG_CONFIG_HOME:-$HOME/.config}/autostart"
6472
desktop_file="$autostart_dir/$autostart_name.desktop"
73+
data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
74+
launcher_dir="$data_home/ppuc/autostart"
75+
launcher_script="$launcher_dir/$autostart_name.sh"
6576

6677
if [[ ! -x "$binary" ]]; then
6778
echo "Expected executable not found: $binary" >&2
@@ -93,16 +104,57 @@ for arg in "$@"; do
93104
esac
94105
done
95106

96-
printf -v quoted_exec '%q ' "$binary" "${resolved_args[@]}"
97-
quoted_exec="${quoted_exec% }"
107+
if [[ -z "$terminal_cmd" ]]; then
108+
if command -v gnome-terminal >/dev/null 2>&1; then
109+
terminal_cmd="gnome-terminal"
110+
elif command -v kgx >/dev/null 2>&1; then
111+
terminal_cmd="kgx"
112+
elif command -v x-terminal-emulator >/dev/null 2>&1; then
113+
terminal_cmd="x-terminal-emulator"
114+
else
115+
echo "No supported terminal emulator found. Use --terminal <command>." >&2
116+
exit 1
117+
fi
118+
fi
119+
98120
mkdir -p "$autostart_dir"
121+
mkdir -p "$launcher_dir"
122+
123+
{
124+
echo "#!/bin/bash"
125+
echo "set -euo pipefail"
126+
echo "cd $(printf '%q' "$workdir")"
127+
printf 'exec %q' "$binary"
128+
for arg in "${resolved_args[@]}"; do
129+
printf ' %q' "$arg"
130+
done
131+
printf '\n'
132+
} > "$launcher_script"
133+
134+
chmod 755 "$launcher_script"
135+
136+
case "$terminal_cmd" in
137+
gnome-terminal)
138+
printf -v autostart_exec '%q --wait -- %q' "$terminal_cmd" "$launcher_script"
139+
;;
140+
kgx)
141+
printf -v autostart_exec '%q -- %q' "$terminal_cmd" "$launcher_script"
142+
;;
143+
x-terminal-emulator)
144+
printf -v autostart_exec '%q -e %q' "$terminal_cmd" "$launcher_script"
145+
;;
146+
*)
147+
printf -v autostart_exec '%q -e %q' "$terminal_cmd" "$launcher_script"
148+
;;
149+
esac
99150

100151
sed \
101-
-e "s|@PPUC_WORKDIR@|$workdir|g" \
102-
-e "s|@PPUC_EXEC@|$quoted_exec|g" \
152+
-e "s|@AUTOSTART_EXEC@|$autostart_exec|g" \
103153
"$template" > "$desktop_file"
104154

105155
chmod 644 "$desktop_file"
106156

107157
echo "Installed GNOME autostart entry: $desktop_file"
108-
echo "Command: $quoted_exec"
158+
echo "Launcher: $launcher_script"
159+
echo "Terminal: $terminal_cmd"
160+
echo "Command: $binary ${resolved_args[*]}"

platforms/linux/uninstall-gnome-autostart.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Examples:
1313
1414
Notes:
1515
- The script removes ~/.config/autostart/<name>.desktop.
16-
- It only removes the per-user GNOME/XDG autostart entry and leaves the build output untouched.
16+
- It also removes the generated launcher script under ~/.local/share/ppuc/autostart/.
17+
- It only removes per-user autostart artifacts and leaves the build output untouched.
1718
USAGE
1819
}
1920

@@ -41,11 +42,23 @@ done
4142

4243
autostart_dir="${XDG_CONFIG_HOME:-$HOME/.config}/autostart"
4344
desktop_file="$autostart_dir/$autostart_name.desktop"
45+
data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
46+
launcher_script="$data_home/ppuc/autostart/$autostart_name.sh"
4447

45-
if [[ ! -e "$desktop_file" ]]; then
46-
echo "Autostart entry not found: $desktop_file"
47-
exit 0
48+
removed_any=0
49+
50+
if [[ -e "$desktop_file" ]]; then
51+
rm -f "$desktop_file"
52+
echo "Removed GNOME autostart entry: $desktop_file"
53+
removed_any=1
54+
fi
55+
56+
if [[ -e "$launcher_script" ]]; then
57+
rm -f "$launcher_script"
58+
echo "Removed launcher script: $launcher_script"
59+
removed_any=1
4860
fi
4961

50-
rm -f "$desktop_file"
51-
echo "Removed GNOME autostart entry: $desktop_file"
62+
if [[ "$removed_any" -eq 0 ]]; then
63+
echo "Autostart entry not found for name: $autostart_name"
64+
fi

0 commit comments

Comments
 (0)