diff --git a/src/normcap/app.py b/src/normcap/app.py index 772cc904..4fb999d4 100644 --- a/src/normcap/app.py +++ b/src/normcap/app.py @@ -15,6 +15,7 @@ from normcap.utils import ( create_argparser, init_logger, + set_environ_for_flatpak, set_environ_for_prebuild_package, set_environ_for_wayland, ) @@ -44,6 +45,8 @@ def main(): set_environ_for_prebuild_package() if system_info.display_manager_is_wayland(): set_environ_for_wayland() + if system_info.is_flatpak_package(): + set_environ_for_flatpak() if system_info.is_prebuild_package() or system_info.is_flatpak_package(): utils.copy_tessdata_files_to_config_dir() diff --git a/src/normcap/utils.py b/src/normcap/utils.py index 5c3fbd8e..19c44d1d 100644 --- a/src/normcap/utils.py +++ b/src/normcap/utils.py @@ -58,6 +58,20 @@ def set_environ_for_wayland(): os.environ["QT_QPA_PLATFORM"] = "wayland" +def set_environ_for_flatpak(): + # Unity DE (and maybe others) use gtk-nocsd to remove client side decorations. + # It doesn't work within FlatPak, and the error message make pytesseract crash. + # Therefore we deactivate it within the Flatpak. + # See: https://github.com/dynobo/normcap/issues/290#issuecomment-1289629427 + ld_preload = os.environ.get("LD_PRELOAD", "") + if "nocsd" in ld_preload.lower(): + logger.warning( + "Found LD_PRELOAD='%s'. Setting to LD_PRELOAD='' to avoid issues.", + ld_preload, + ) + os.environ["LD_PRELOAD"] = "" + + # Some overrides when running in prebuild package def set_environ_for_prebuild_package():