From 62c297e5a12798ebdc8fd3ee0aa28b18f0d71fb2 Mon Sep 17 00:00:00 2001 From: nelsoduarte Date: Sun, 10 May 2026 23:12:32 +0100 Subject: [PATCH] fix(i18n): clear all PyInstaller env vars (not only home dir) on relaunch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #50 cleared _PYI_APPLICATION_HOME_DIR but left _PYI_PARENT_PROCESS_LEVEL and _PYI_ARCHIVE_FILE inherited. The child bootloader sees _PYI_PARENT_PROCESS_LEVEL=1 from the parent, concludes it is a phase-2 (child-phase) launch, then tries to read _PYI_APPLICATION_HOME_DIR — which we cleared — and aborts with _PYI_APPLICATION_HOME_DIR environment variable is not defined! Switch to a pattern-based clear that removes anything matching _PYI_* or _MEIPASS*, so the relaunched process truly starts fresh and is robust against future PyInstaller versions adding new internal vars. Verified locally with a build + smoke test + relaunch simulation. Bumps APP_VERSION to 1.13.11. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/constants.py | 2 +- app/window.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/constants.py b/app/constants.py index a689815..8837454 100644 --- a/app/constants.py +++ b/app/constants.py @@ -3,7 +3,7 @@ import os as _os DESKTOP = _os.path.join(_os.path.expanduser("~"), "Desktop") -APP_VERSION = "1.13.10" +APP_VERSION = "1.13.11" GITHUB_REPO = "nelsonduarte/PDFApps" ACCENT = "#14B8A6" # main teal diff --git a/app/window.py b/app/window.py index c676079..4cd44ed 100644 --- a/app/window.py +++ b/app/window.py @@ -948,17 +948,24 @@ def _restart_app(self): program = sys.executable args = [script] + pdf_args cwd = os.path.dirname(script) or os.getcwd() - # PyInstaller --onefile points _PYI_APPLICATION_HOME_DIR (or the - # legacy _MEIPASS2) at our temp extraction folder. The parent - # deletes that folder on exit, so the child must perform its - # own extraction instead of reusing ours. + # PyInstaller --onefile uses several env vars to coordinate the + # two-phase bootloader handoff: _PYI_APPLICATION_HOME_DIR (the + # extracted temp path), _PYI_PARENT_PROCESS_LEVEL (phase marker) + # and _PYI_ARCHIVE_FILE, plus the legacy _MEIPASS2. The parent + # deletes its temp folder on exit, so the child must perform its + # own extraction instead of reusing ours. We must clear ALL of + # these — leaving any one set makes the child's bootloader think + # it's a child-phase launch and either reuse the about-to-be- + # deleted folder or, if some vars are missing, abort with + # "_PYI_APPLICATION_HOME_DIR environment variable is not defined!". proc = QProcess() proc.setProgram(program) proc.setArguments(args) proc.setWorkingDirectory(cwd) env = QProcessEnvironment.systemEnvironment() - env.remove("_PYI_APPLICATION_HOME_DIR") - env.remove("_MEIPASS2") + for _k in list(env.keys()): + if _k.startswith("_PYI_") or _k.startswith("_MEIPASS"): + env.remove(_k) proc.setProcessEnvironment(env) proc.startDetached() QApplication.instance().exit(0)