From 036241fc6c8a8d213542190052e152982aea30f7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 23 Aug 2024 15:27:26 +0530 Subject: [PATCH] macOS: Fix a regression in the previous release that caused --single-instance to not work when using macos-launch-services-cmdline --- docs/changelog.rst | 2 ++ kitty/logging.c | 1 + kitty/main.py | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4e3aaaeb3..6d7245598 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -85,6 +85,8 @@ Detailed list of changes - OSC 52: Fix a regression in the previous release that broke handling of invalid base64 encoded data in OSC 52 requests (:iss:`7757`) +- macOS: Fix a regression in the previous release that caused :option:`--single-instance` to not work when using :file:`macos-launch-services-cmdline` + 0.36.0 [2024-08-17] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/logging.c b/kitty/logging.c index 00e538ce9..f45919373 100644 --- a/kitty/logging.c +++ b/kitty/logging.c @@ -86,6 +86,7 @@ bool init_logging(PyObject *module) { if (PyModule_AddFunctions(module, module_methods) != 0) return false; #ifdef __APPLE__ + // This env var can be either 1 or 2 if (getenv("KITTY_LAUNCHED_BY_LAUNCH_SERVICES") != NULL) use_os_log = true; #endif return true; diff --git a/kitty/main.py b/kitty/main.py index 14f9a62f9..bb93cec90 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -320,6 +320,11 @@ def macos_cmdline(argv_args: list[str]) -> list[str]: ans = list(shlex_split(raw)) if ans and ans[0] == 'kitty': del ans[0] + if '-1' in ans or '--single-instance' in ans: + # Re-exec with new argv so that the C code that handles single instance + # can pick up the modified argv + os.environ['KITTY_LAUNCHED_BY_LAUNCH_SERVICES'] = '2' # so that use_os_log is set in the re-execed process + os.execl(kitty_exe(), 'kitty', *(ans + argv_args)) return ans + argv_args @@ -446,7 +451,6 @@ def _main() -> None: if is_macos and os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1': os.chdir(os.path.expanduser('~')) args = macos_cmdline(args) - getattr(sys, 'kitty_run_data')['launched_by_launch_services'] = True try: cwd_ok = os.path.isdir(os.getcwd()) except Exception: