Skip to content

Commit

Permalink
Merge pull request #295 from dynobo/feature/avoid-issue-with-gtk-nocs…
Browse files Browse the repository at this point in the history
…d-within-flatpak

Clear LD_PRELOAD env inside flatpak to fix #290
  • Loading branch information
dynobo authored Oct 25, 2022
2 parents eb2af06 + 4f8cc56 commit d8be4d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/normcap/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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()

Expand Down
14 changes: 14 additions & 0 deletions src/normcap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down

0 comments on commit d8be4d6

Please sign in to comment.