Skip to content

Commit 7c8fe51

Browse files
authored
Launch zwift using gamemode (#352)
* Launch Zwift itself using gamemode * Only enable gamemode if it is installed on the host * Fix confusing documentation about config files * Remove obsolete function * Clarify requirements * Clarify ANT+, Bluetooth, Wifi and Ethernet
1 parent dfea1f2 commit 7c8fe51

6 files changed

Lines changed: 60 additions & 58 deletions

File tree

docs/configuration/options.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ foo@bar:~$ WINE_EXPERIMENTAL_WAYLAND="1" zwift # start zwift using Wayland inste
3030

3131
### Configuration file
3232

33-
The zwift script automatically loads environment variables from the following configuration files:
33+
You can persist configuration options by creating a file. The zwift script will automatically load environment variables from
34+
these files, if present:
3435

3536
- `$HOME/.config/zwift/config`
3637
- `$HOME/.config/zwift/$USER-config`

docs/getting-started/installation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/netbrain/zwift/mast
1919
This script will:
2020

2121
- Download the Zwift container image
22-
- Create necessary configuration files
2322
- Add zwift command to your system path
2423
- Create desktop shortcut
2524

docs/getting-started/prerequisites.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ nav_order: 1
1818

1919
## Required Software
2020

21-
### Container Runtimes
21+
### Supported Container Runtimes
2222

23-
- **Docker**
24-
- Install from [Docker documentation](https://docs.docker.com/get-docker/)
25-
- **Podman** (Alternative)
26-
- Version 4.3+ recommended
27-
- Install from [Podman installation guide](https://podman.io/getting-started/installation)
23+
#### Podman (Recommended)
2824

29-
{: .warning }
30-
**Podman 4.3 and earlier**: Does not support `--userns=keep-id:uid=xxx,gid=xxx` and will not start correctly, this impacts
31-
Ubuntu 22.04 and related builds such as PopOS! 22.04.
25+
- Install by following the [Podman install guide](https://podman.io/docs/installation#installing-on-linux)
26+
- Podman 4.3 and earlier do not support `--userns=keep-id` and will not start correctly. This impacts Ubuntu 22.04 and related
27+
builds such as PopOS! 22.04.
28+
29+
#### Docker
30+
31+
- Rootless docker is not supported!
32+
- Install by following the [Docker CE install guide](https://docs.docker.com/engine/install/)
33+
- Add your user account to the docker group to be able to use docker without requiring sudo `sudo usermod -aG docker $USER`.
3234

3335
### Additional Dependencies for NVIDIA graphics cards
3436

35-
- **NVIDIA Container Toolkit**
36-
- Install from [NVIDIA Container Toolkit installation guide](
37-
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
38-
- Podman: Also follow the [Container Device Interface guide](
39-
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/cdi-support.html)
40-
41-
{: .note }
42-
**Podman and NVIDIA Container Toolkit before v1.18.0**: The cdi specification file needs to be generated manually each time the
43-
NVIDIA driver is updated using the following command: `sudo nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml`
44-
45-
{: .note }
46-
> If you're running Docker with cdi and Zwift fails to launch, try the long form
47-
> `VGA_DEVICE_FLAG=(--device="nvidia.com/gpu=all")` (instead of `--gpus=all`).
48-
>
49-
> See <https://github.com/netbrain/zwift/issues/208> for context.
37+
#### NVIDIA Container Toolkit
38+
39+
- Install by following the [NVIDIA Container Toolkit installation guide][install-nvctk]
40+
- Podman
41+
- Also follow the [Container Device Interface guide][install-nvcdi]
42+
- Container Toolkit version v1.17.9 and earlier do not automatically update the cdi specification file. Regenerate it manually
43+
after NVIDIA driver updates by running the command: `sudo nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml`.
44+
- Docker
45+
- If Zwift fails to launch, try setting `VGA_DEVICE_FLAG=(--device="nvidia.com/gpu=all")`. See
46+
[this issue](https://github.com/netbrain/zwift/issues/208) for context.
47+
48+
[install-nvctk]: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
49+
[install-nvcdi]: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/cdi-support.html

docs/getting-started/setup.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ nav_order: 3
66

77
# How do I connect my trainer, heart rate monitor, etc?
88

9-
You can [use your phone as a bridge](https://support.zwift.com/using-the-zwift-companion-app-Hybn8qzPr).
9+
## ANT+
1010

11-
For example, your Wahoo Kickr and Apple Watch connect to the Zwift Companion app on your iPhone; then the Companion app connects
11+
ANT+ devices are not supported.
12+
13+
## Bluetooth
14+
15+
Wine does not fully support bluetooth yet. Instead, you can [use your phone as a bridge][companion-app-bridge] to connect your
16+
bluetooth devices to Zwift.
17+
18+
For example, your Wahoo Kickr and Apple Watch connect to the Zwift Companion app on your iPhone, then the Companion app connects
1219
over wifi to your PC running Zwift.
1320

14-
{: .note }
15-
If you are using a direct connect (wifi or ethernet) enabled trainer, you may need to set `NETWORKING="host"` for Zwift to be
16-
able to communicate to the device.
21+
[companion-app-bridge]: https://support.zwift.com/en_us/using-the-zwift-companion-app-as-a-bridge-ByAnUzlLj
22+
23+
## Direct Connect
24+
25+
If you are using a direct connect (wifi or ethernet) enabled trainer, you do not need the Companion app. Setting the
26+
[NETWORKING](../../configuration/options/#networking) configuration option to `NETWORKING="host"` will allow Zwift to discover
27+
your device and connect to it directly.

src/run_zwift.sh

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ wait_until_wine_task_started() {
9393
wait_until "is_wine_task_running ${task_name}"
9494
}
9595

96-
wait_until_process_started() {
97-
local process_name="${1:?}"
98-
msgbox info "Waiting for ${process_name} to start..."
99-
wait_until "pgrep -f ${process_name} > /dev/null 2>&1"
100-
}
101-
10296
###########################
10397
##### Configure Zwift #####
10498

@@ -133,8 +127,8 @@ if [[ -n ${ZWIFT_USERNAME} ]] && [[ -n ${ZWIFT_PASSWORD} ]]; then
133127
fi
134128
fi
135129

136-
######################################################
137-
##### Start (and automatically stop) wine server #####
130+
##########################################
131+
##### Automatically stop wine server #####
138132

139133
cleanup() {
140134
msgbox info "Stopping wine server"
@@ -143,21 +137,6 @@ cleanup() {
143137

144138
trap cleanup EXIT
145139

146-
if [[ ${ZWIFT_NO_GAMEMODE} -eq 1 ]]; then
147-
msgbox warning "Not using gamemode"
148-
else
149-
msgbox info "Starting wine server in gamemode"
150-
151-
/usr/games/gamemoderun wineserver -w &
152-
153-
if wait_until_process_started wineserver; then
154-
msgbox ok "Started wine server"
155-
else
156-
msgbox error "Failed to start wine server!"
157-
exit 1
158-
fi
159-
fi
160-
161140
##################################
162141
##### Start Zwift using wine #####
163142

@@ -189,10 +168,17 @@ fi
189168
msgbox ok "Zwift launcher started using wine"
190169
msgbox info "Starting Zwift using wine"
191170

192-
declare -a wine_cmd
193-
wine_cmd=(wine start /exec /bin/runfromprocess-rs.exe "${launcher_pid}" ZwiftApp.exe "${zwift_args[@]}")
171+
declare -a zwift_cmd
172+
173+
if [[ ${ZWIFT_NO_GAMEMODE} -eq 1 ]]; then
174+
msgbox info "Not using gamemode"
175+
zwift_cmd=(wine start /exec /bin/runfromprocess-rs.exe "${launcher_pid}" ZwiftApp.exe "${zwift_args[@]}")
176+
else
177+
msgbox info "Using gamemode"
178+
zwift_cmd=(/usr/games/gamemoderun wine /bin/runfromprocess-rs.exe "${launcher_pid}" ZwiftApp.exe "${zwift_args[@]}")
179+
fi
194180

195-
if ! "${wine_cmd[@]}" || ! wait_until_wine_task_started ZwiftApp.exe; then
181+
if ! "${zwift_cmd[@]}" || ! wait_until_wine_task_started ZwiftApp.exe; then
196182
msgbox error "Failed to start Zwift using wine!"
197183
exit 1
198184
fi

src/zwift.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,14 @@ if [[ -n ${ZWIFT_OVERRIDE_RESOLUTION} ]]; then
448448
container_env_vars+=(ZWIFT_OVERRIDE_RESOLUTION="${ZWIFT_OVERRIDE_RESOLUTION}")
449449
fi
450450

451-
# Pass environment variable to container if gamemode should be disabled
451+
# Check if gamemode should be enabled
452452
if [[ ${ZWIFT_NO_GAMEMODE} -eq 1 ]]; then
453453
container_env_vars+=(ZWIFT_NO_GAMEMODE="1")
454+
elif command_exists gamemoded; then
455+
msgbox ok "Gamemode is installed, enabling gamemode for Zwift"
456+
else
457+
msgbox info "Gamemode is not installed, disabling gamemode for Zwift"
458+
container_env_vars+=(ZWIFT_NO_GAMEMODE="1")
454459
fi
455460

456461
# Interactive mode and run in foreground/background

0 commit comments

Comments
 (0)