macOS: Fix a regression in the previous release that caused --single-instance to not work when using macos-launch-services-cmdline

This commit is contained in:
Kovid Goyal 2024-08-23 15:27:26 +05:30
parent 0c1d239b5f
commit 036241fc6c
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 1 deletions

View file

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -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;

View file

@ -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: