Skip to content

Commit e7cff5f

Browse files
committed
feat(profile): --profile flag for launch and install-shortcut
1 parent a52b8ea commit e7cff5f

3 files changed

Lines changed: 60 additions & 16 deletions

File tree

lib/launch.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33
# Sourced by setup; do not execute directly.
44
# Depends on: lib/config.sh, lib/utils.sh, lib/registry.sh
55

6+
# Parse `--profile NAME` out of an argv stream regardless of position.
7+
# Sets globals WG_PARSED_PROFILE and WG_PARSED_ARGS (array of leftovers).
8+
# Usage: _parse_profile_flag "$@"
9+
_parse_profile_flag() {
10+
WG_PARSED_PROFILE=""
11+
WG_PARSED_ARGS=()
12+
while [ $# -gt 0 ]; do
13+
case "$1" in
14+
--profile) WG_PARSED_PROFILE="$2"; shift 2 ;;
15+
--profile=*) WG_PARSED_PROFILE="${1#--profile=}"; shift ;;
16+
*) WG_PARSED_ARGS+=("$1"); shift ;;
17+
esac
18+
done
19+
}
20+
621
# Launch a registered launcher via Proton (Wine fallback if Proton absent).
7-
# Usage: launch_app "app-key"
22+
# Usage: launch_app [--profile NAME] <app-key> (flag accepted in any position)
823
launch_app() {
9-
local app_key="$1"
24+
_parse_profile_flag "$@"
25+
local app_key="${WG_PARSED_ARGS[0]:-}"
26+
local profile_override="${WG_PARSED_PROFILE}"
1027

1128
parse_app_config "$app_key" || return 1
1229

@@ -32,7 +49,13 @@ launch_app() {
3249
export __GL_THREADED_OPTIMIZATION=1
3350

3451
# Apply default + per-app profile (FPS cap, HUD, FSR, NVAPI, …).
35-
load_profile "$app_key"
52+
# If --profile was supplied, that named profile replaces the per-app one.
53+
if [ -n "$profile_override" ]; then
54+
load_profile "$profile_override"
55+
print_info "Profile override: $profile_override"
56+
else
57+
load_profile "$app_key"
58+
fi
3659

3760
if [ -x "$PROTON_DIR/proton" ]; then
3861
export STEAM_COMPAT_DATA_PATH="$WINEPREFIX"

lib/shortcuts.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ extract_exe_icon() {
7979
}
8080

8181
# Create a .desktop shortcut and a wrapper launcher script for an app.
82-
# Usage: create_shortcut "app-key" [display_name]
82+
# Usage: create_shortcut [--profile NAME] <app-key> [display_name]
83+
# When --profile is given, the shortcut is suffixed (key-profile.desktop) so
84+
# multiple profile-specific shortcuts can coexist for one app.
8385
create_shortcut() {
84-
local app_key="$1"
85-
local display_name="${2:-}"
86+
_parse_profile_flag "$@"
87+
local app_key="${WG_PARSED_ARGS[0]:-}"
88+
local display_name="${WG_PARSED_ARGS[1]:-}"
89+
local profile_name="${WG_PARSED_PROFILE}"
8690

8791
parse_app_config "$app_key" || return 1
8892

@@ -94,6 +98,7 @@ create_shortcut() {
9498
fi
9599

96100
display_name="${display_name:-$APP_NAME}"
101+
[ -n "$profile_name" ] && display_name="$display_name ($profile_name)"
97102

98103
# Attempt to extract the app icon from the installed exe for a better desktop shortcut.
99104
local app_icon="application-x-ms-dos-executable"
@@ -106,16 +111,23 @@ create_shortcut() {
106111
print_warning "Icon extraction failed — using default icon. Re-run after: sudo apt install icoutils"
107112
fi
108113

109-
local launcher="$BIN_DIR/$app_key"
110-
local desktop="$APPS_DIR/${app_key}.desktop"
114+
local file_suffix=""
115+
[ -n "$profile_name" ] && file_suffix="-${profile_name}"
116+
local launcher="$BIN_DIR/${app_key}${file_suffix}"
117+
local desktop="$APPS_DIR/${app_key}${file_suffix}.desktop"
111118
local setup_script_path
112119
setup_script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/setup"
113120

121+
# PROFILE_OVERRIDE is baked into the wrapper so the .desktop loads the named profile.
122+
local profile_export=""
123+
[ -n "$profile_name" ] && profile_export="WG_PROFILE_OVERRIDE=\"$profile_name\""
124+
114125
# Generate a standalone wrapper script that sources this project's libs.
115126
cat > "$launcher" <<'LAUNCHER_EOF'
116127
#!/bin/bash
117128
# Auto-generated launcher for Wine Proton app — do not edit manually.
118129
APP_KEY="%APP_KEY%"
130+
WG_PROFILE_OVERRIDE="%PROFILE_OVERRIDE%"
119131
WINE_DIR="%WINE_DIR%"
120132
WINEPREFIX="%WINEPREFIX%"
121133
PROTON_DIR="%PROTON_DIR%"
@@ -131,7 +143,7 @@ export WINEDLLOVERRIDES="winemenubuilder.exe=d"
131143
export VKD3D_SHADER_VERBOSE=0
132144
133145
# Source lib modules to get parse_app_config / find_app_exe / load_profile
134-
for _lib in config utils registry profile; do
146+
for _lib in config utils registry profile user_registry; do
135147
# shellcheck source=/dev/null
136148
source "$SCRIPT_DIR/lib/${_lib}.sh"
137149
done
@@ -140,7 +152,12 @@ unset _lib
140152
parse_app_config "$APP_KEY" || exit 1
141153
142154
# Apply default + per-app profile (FPS cap, HUD, FSR, NVAPI, gamemode, …)
143-
load_profile "$APP_KEY"
155+
# If WG_PROFILE_OVERRIDE was baked in by --profile, that named profile wins.
156+
if [ -n "$WG_PROFILE_OVERRIDE" ]; then
157+
load_profile "$WG_PROFILE_OVERRIDE"
158+
else
159+
load_profile "$APP_KEY"
160+
fi
144161
145162
EXE_PATH=$(find_app_exe "$APP_KEY")
146163
if [ -z "$EXE_PATH" ]; then
@@ -153,7 +170,7 @@ EXE_BIN=$(basename "$EXE_PATH")
153170
154171
cd "$EXE_DIR" || { echo "Error: Cannot cd to $EXE_DIR" >&2; exit 1; }
155172
156-
LOG_FILE="$WINE_DIR/${APP_KEY}.log"
173+
LOG_FILE="$WINE_DIR/${APP_KEY}${WG_PROFILE_OVERRIDE:+-$WG_PROFILE_OVERRIDE}.log"
157174
if [ -x "$PROTON_DIR/proton" ]; then
158175
eval "${WG_LAUNCH_PREFIX}\"\$PROTON_DIR/proton\" run \"\$EXE_BIN\"" >"$LOG_FILE" 2>&1 &
159176
else
@@ -162,6 +179,7 @@ fi
162179
LAUNCHER_EOF
163180

164181
sed -i "s|%APP_KEY%|$app_key|g" "$launcher"
182+
sed -i "s|%PROFILE_OVERRIDE%|$profile_name|g" "$launcher"
165183
sed -i "s|%WINE_DIR%|$WINE_DIR|g" "$launcher"
166184
sed -i "s|%WINEPREFIX%|$WINEPREFIX|g" "$launcher"
167185
sed -i "s|%PROTON_DIR%|$PROTON_DIR|g" "$launcher"

setup

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ APP MANAGEMENT:
4949
install-all Install all registered launchers
5050
uninstall <app-key> Remove a launcher from the prefix
5151
launch <key> Launch any registered app (launcher or user)
52+
launch <key> --profile <p> Launch with a specific profile (also: --profile <p> <key>)
5253
launch-exe <path> Launch any external .exe/.msi in managed prefix
5354
prefix-info Show managed prefix paths and env vars
5455
@@ -58,8 +59,9 @@ USER APP REGISTRY (games, standalone .exes):
5859
remove <key> Remove a user entry
5960
6061
SHORTCUT MANAGEMENT:
61-
install-shortcut <key|all> Create .desktop launcher shortcut (or all installed)
62-
remove-shortcut <key|all> Remove desktop shortcut (or all)
62+
install-shortcut <key|all> Create .desktop launcher shortcut (or all installed)
63+
install-shortcut --profile <p> <key> Create profile-specific shortcut (key-p.desktop)
64+
remove-shortcut <key|all> Remove desktop shortcut (or all)
6365
6466
PROFILE MANAGEMENT (per-app Proton/DXVK tuning):
6567
profile menu [app-key] Interactive knob editor (FPS cap, HUD, FSR, …)
@@ -138,7 +140,7 @@ main() {
138140
install) install_app "$2" "$3" ;;
139141
install-all) install_all_launchers ;;
140142
uninstall) uninstall_app "$2" ;;
141-
launch) launch_app "$2" ;;
143+
launch) shift; launch_app "$@" ;;
142144
launch-exe) launch_external_exe "$2" ;;
143145
prefix-info) prefix_info ;;
144146

@@ -148,8 +150,9 @@ main() {
148150

149151
# Shortcut management
150152
install-shortcut)
151-
if [ "$2" = "all" ]; then create_all_shortcuts
152-
else create_shortcut "$2" "$3"; fi ;;
153+
shift
154+
if [ "$1" = "all" ]; then create_all_shortcuts
155+
else create_shortcut "$@"; fi ;;
153156
remove-shortcut)
154157
if [ "$2" = "all" ]; then remove_all_shortcuts
155158
else remove_shortcut "$2"; fi ;;

0 commit comments

Comments
 (0)