diff --git a/Programs/FletIdentity.py b/Programs/FletIdentity.py index 4a27e3c..3f3dcb3 100644 --- a/Programs/FletIdentity.py +++ b/Programs/FletIdentity.py @@ -26,7 +26,10 @@ from pathlib import Path OriginalId = b"com.appveyor.flet" # Flet's window needs libsecret, which isn't part of GTK and some systems don't # install. SaraSuite keeps copies of it and what it needs (from its AppImage) -# here; MissingLibraries puts the ones this system lacks beside the client. +# here; AddMissingLibraries puts the ones this system lacks in a fallback-libs +# folder beside the client copy, which the program's Launch.sh adds to +# LD_LIBRARY_PATH (a plugin loads libsecret, so the client's own lib folder, +# its RUNPATH, wouldn't be searched for it). LibrariesDir = Path(os.environ.get("XDG_DATA_HOME") or Path.home() / ".local" / "share") / "SaraSuite" / "Libraries" FallbackLibraries = ("libgpg-error.so.0", "libgcrypt.so.20", "libsecret-1.so.0") CopiesDir = Path.home() / ".cache" / "SaraSuite" / "FletClient" @@ -48,15 +51,16 @@ def _SystemHas(Name: str) -> bool: return any(Line.strip().startswith(Name + " ") for Line in Cache.splitlines()) -def AddMissingLibraries(ClientLib: Path) -> None: - """Copies SaraSuite's fallback libraries the system doesn't have into the - client's lib folder (it looks there first: its RUNPATH is $ORIGIN/lib).""" - if not sys.platform.startswith("linux") or not LibrariesDir.is_dir() or not ClientLib.is_dir(): +def AddMissingLibraries(Folder: Path) -> None: + """Copies SaraSuite's fallback libraries the system doesn't have into + Folder (created only if one is needed).""" + if not sys.platform.startswith("linux") or not LibrariesDir.is_dir(): return for Name in FallbackLibraries: Source = LibrariesDir / Name - if Source.is_file() and not (ClientLib / Name).exists() and not _SystemHas(Name): - shutil.copy2(Source, ClientLib / Name) + if Source.is_file() and not (Folder / Name).exists() and not _SystemHas(Name): + Folder.mkdir(parents=True, exist_ok=True) + shutil.copy2(Source, Folder / Name) def ClientFor(AppId: str) -> str: @@ -70,7 +74,6 @@ def ClientFor(AppId: str) -> str: from flet_desktop import ensure_client_cached # the program's own Flet version Original = Path(ensure_client_cached()) / "flet" - AddMissingLibraries(Original / "lib") Binary = (Original / "flet").read_bytes() Copy = CopiesDir / f"{Original.parent.name}-{AppId}" / "flet" Patched = Binary.replace( @@ -80,6 +83,7 @@ def ClientFor(AppId: str) -> str: if Binary.count(b"\x00" + OriginalId + b"\x00") != 1: return "" # not the client layout this was written for + AddMissingLibraries(Copy.parent / "fallback-libs") Target = Copy / "flet" if not (Target.exists() and Target.read_bytes() == Patched): Copy.mkdir(parents=True, exist_ok=True) diff --git a/Programs/SaraFem/Templates/Launch.sh b/Programs/SaraFem/Templates/Launch.sh index 70e1413..72b2ae9 100644 --- a/Programs/SaraFem/Templates/Launch.sh +++ b/Programs/SaraFem/Templates/Launch.sh @@ -4,5 +4,9 @@ # matches the window to {Name}.desktop (StartupWMClass) instead of showing it # as "com.appveyor.flet". Empty if that fails: Flet then uses its own client. export FLET_VIEW_PATH="$("{Python}" "{ProgramDir}/FletIdentity.py" "srhtnin.{Name}")" +# Libraries Flet's window needs that this system lacks (libsecret), from +# SaraSuite: FletIdentity.py puts them beside the client copy. +Fallback="$FLET_VIEW_PATH/../fallback-libs" +[ -n "$FLET_VIEW_PATH" ] && [ -d "$Fallback" ] && export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$Fallback" cd "{AppDir}" || exit 1 exec "{Python}" Main.py "$@" diff --git a/Programs/SaraSort/Templates/Launch.sh b/Programs/SaraSort/Templates/Launch.sh index 70e1413..72b2ae9 100755 --- a/Programs/SaraSort/Templates/Launch.sh +++ b/Programs/SaraSort/Templates/Launch.sh @@ -4,5 +4,9 @@ # matches the window to {Name}.desktop (StartupWMClass) instead of showing it # as "com.appveyor.flet". Empty if that fails: Flet then uses its own client. export FLET_VIEW_PATH="$("{Python}" "{ProgramDir}/FletIdentity.py" "srhtnin.{Name}")" +# Libraries Flet's window needs that this system lacks (libsecret), from +# SaraSuite: FletIdentity.py puts them beside the client copy. +Fallback="$FLET_VIEW_PATH/../fallback-libs" +[ -n "$FLET_VIEW_PATH" ] && [ -d "$Fallback" ] && export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$Fallback" cd "{AppDir}" || exit 1 exec "{Python}" Main.py "$@" diff --git a/Programs/SaraTag/Templates/Launch.sh b/Programs/SaraTag/Templates/Launch.sh index 70e1413..72b2ae9 100644 --- a/Programs/SaraTag/Templates/Launch.sh +++ b/Programs/SaraTag/Templates/Launch.sh @@ -4,5 +4,9 @@ # matches the window to {Name}.desktop (StartupWMClass) instead of showing it # as "com.appveyor.flet". Empty if that fails: Flet then uses its own client. export FLET_VIEW_PATH="$("{Python}" "{ProgramDir}/FletIdentity.py" "srhtnin.{Name}")" +# Libraries Flet's window needs that this system lacks (libsecret), from +# SaraSuite: FletIdentity.py puts them beside the client copy. +Fallback="$FLET_VIEW_PATH/../fallback-libs" +[ -n "$FLET_VIEW_PATH" ] && [ -d "$Fallback" ] && export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$Fallback" cd "{AppDir}" || exit 1 exec "{Python}" Main.py "$@" diff --git a/Programs/SaraTune/Templates/Launch.sh b/Programs/SaraTune/Templates/Launch.sh index d8142dc..f81ce86 100644 --- a/Programs/SaraTune/Templates/Launch.sh +++ b/Programs/SaraTune/Templates/Launch.sh @@ -6,5 +6,9 @@ export FLET_DESKTOP_FLAVOR=full # matches the window to {Name}.desktop (StartupWMClass) instead of showing it # as "com.appveyor.flet". Empty if that fails: Flet then uses its own client. export FLET_VIEW_PATH="$("{Python}" "{ProgramDir}/FletIdentity.py" "srhtnin.{Name}")" +# Libraries Flet's window needs that this system lacks (libsecret), from +# SaraSuite: FletIdentity.py puts them beside the client copy. +Fallback="$FLET_VIEW_PATH/../fallback-libs" +[ -n "$FLET_VIEW_PATH" ] && [ -d "$Fallback" ] && export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$Fallback" cd "{AppDir}" || exit 1 exec "{Python}" Main.py "$@" diff --git a/Programs/SaraView/Templates/Launch.sh b/Programs/SaraView/Templates/Launch.sh index b48bad9..d33a056 100755 --- a/Programs/SaraView/Templates/Launch.sh +++ b/Programs/SaraView/Templates/Launch.sh @@ -4,5 +4,9 @@ # matches the window to {Name}.desktop (StartupWMClass) instead of showing it # as "com.appveyor.flet". Empty if that fails: Flet then uses its own client. export FLET_VIEW_PATH="$("{Python}" "{ProgramDir}/FletIdentity.py" "srhtnin.{Name}")" +# Libraries Flet's window needs that this system lacks (libsecret), from +# SaraSuite: FletIdentity.py puts them beside the client copy. +Fallback="$FLET_VIEW_PATH/../fallback-libs" +[ -n "$FLET_VIEW_PATH" ] && [ -d "$Fallback" ] && export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$Fallback" cd "{AppDir}/Client" || exit 1 exec "{Python}" Main.py "$@"