Skip to content

Commit 58922d9

Browse files
committed
feat: detect opengl version
1 parent e7e72ff commit 58922d9

5 files changed

Lines changed: 65 additions & 8 deletions

File tree

ou_dedetai/installer.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import sys
55
from pathlib import Path
66

7-
from ou_dedetai import system
87
from ou_dedetai.app import App, UserExitedFromAsk
98

109
from . import constants
1110
from . import network
11+
from . import system
1212
from . import utils
1313
from . import wine
1414

15+
from .system import OpenGLIncompatible
1516

1617
# This step doesn't do anything per-say, but "collects" all the choices in one step
1718
# The app would continue to work without this function
@@ -271,11 +272,23 @@ def ensure_launcher_shortcuts(app: App):
271272
f"Runmode is '{constants.RUNMODE}'. Won't create desktop shortcuts",
272273
)
273274

275+
276+
def ensure_opengl(app: App):
277+
app.status("Checking available OpenGL version…")
278+
opengl_version, reason = system.get_opengl_version()
279+
app.status(reason)
280+
if not opengl_version:
281+
raise OpenGLIncompatible
282+
283+
274284
def install(app: App):
275285
"""Entrypoint for installing"""
276286
app.status('Installing…')
277287
try:
288+
ensure_opengl(app)
278289
ensure_launcher_shortcuts(app)
290+
except OpenGLIncompatible:
291+
app.status(f"Incompatible OpenGL version.")
279292
except UserExitedFromAsk:
280293
# Reset choices, it's possible that the user didn't mean to select
281294
# one of the options they did - that is why they are exiting

ou_dedetai/logos.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def run_logos():
123123
self.processes[self.app.conf.logos_exe] = process
124124
self.logos_state = State.RUNNING
125125

126+
# Ensure OpenGL version is compatible with Logos on Wine.
127+
opengl_version, reason = system.get_opengl_version()
128+
if not opengl_version:
129+
self.app.exit(reason)
130+
126131
# Ensure wine version is compatible with Logos release version.
127132
good_wine, reason = wine.check_wine_rules(
128133
wine_release,

ou_dedetai/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import os
1414
import sys
1515

16-
from ou_dedetai.repair import detect_and_recover
16+
from .repair import detect_and_recover
1717

1818
from . import cli
1919
from . import constants

ou_dedetai/system.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from dataclasses import dataclass
2-
from pathlib import Path
3-
from typing import Optional, Tuple
4-
from collections.abc import MutableMapping
5-
import zipfile
1+
import re
2+
63
import distro
4+
import glfw
75
import logging
86
import os
97
import psutil
@@ -13,12 +11,19 @@
1311
import subprocess
1412
import sys
1513
import time
14+
import zipfile
15+
16+
from collections.abc import MutableMapping
17+
from dataclasses import dataclass
18+
from packaging.version import Version
19+
from pathlib import Path
20+
from typing import Optional, Tuple
1621

1722
from ou_dedetai import constants, network
1823
from ou_dedetai.app import App
1924

2025

21-
def fix_ld_library_path(env: Optional[MutableMapping[str, str]]) -> dict[str, str]:
26+
def fix_ld_library_path(env: Optional[MutableMapping[str, str]]) -> dict[str, str]:
2227
"""Removes pyinstaller bundled dynamic linked libraries when executing commands
2328
2429
- https://pyinstaller.org/en/latest/common-issues-and-pitfalls.html#launching-external-programs-from-the-frozen-application
@@ -366,6 +371,33 @@ class SuperuserCommandNotFound(Exception):
366371
"""Superuser command not found. Install pkexec or sudo or doas"""
367372

368373

374+
def get_opengl_version(required_version="3.2"):
375+
try:
376+
result = subprocess.run(['glxinfo'], capture_output=True, text=True, check=True)
377+
except FileNotFoundError:
378+
return False, "glxinfo command not found. Please install mesa-utils or equivalent."
379+
except subprocess.CalledProcessError as e:
380+
return False, f"glxinfo command failed: {e.stderr.strip()}"
381+
382+
match = re.search(r"OpenGL version string:\s+([\d\.]+)", result.stdout)
383+
if not match:
384+
return False, "Failed to parse OpenGL version from glxinfo output."
385+
386+
opengl_version = match.group(1)
387+
if Version(opengl_version) >= Version(required_version):
388+
message = f"OpenGL Version: {opengl_version} is supported (>= {required_version})."
389+
logging.info(message)
390+
return True, message
391+
else:
392+
message = f"OpenGL Version: {opengl_version} is not supported (must be >= {required_version})."
393+
logging.info(message)
394+
return False, message
395+
396+
397+
class OpenGLIncompatible(Exception):
398+
"""Superuser command not found. Install pkexec or sudo or doas"""
399+
400+
369401
def get_superuser_command() -> str:
370402
if shutil.which('pkexec'):
371403
return "pkexec"

ou_dedetai/tui_app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,12 @@ def utilities_menu_select(self, choice):
772772
self.reset_screen()
773773
self.logos.switch_logging()
774774
self.go_to_main_menu()
775+
elif choice == "Check OpenGL":
776+
self.reset_screen()
777+
opengl_version, reason = system.get_opengl_version()
778+
logging.info(reason)
779+
self.status(reason)
780+
self.go_to_main_menu()
775781
elif choice == "Uninstall":
776782
control.uninstall(self)
777783
self.go_to_main_menu()
@@ -1086,6 +1092,7 @@ def set_utilities_menu_options(self):
10861092
)
10871093
labels.append(label)
10881094

1095+
labels.append("Check OpenGL")
10891096
labels.append("Return to Main Menu")
10901097

10911098
options = self.which_dialog_options(labels)

0 commit comments

Comments
 (0)