{{ message }}
Repository navigation
fix(desktop): open files from a second instance started with --user-data-dir (#3020) - #5375
Merged
Merged
Conversation
This was referenced Sep 15, 2026
Contributor
…ata-dir (#3020) The running instance parsed the argv of the `second-instance` event, but Chromium lists switches before the other arguments there and appends switches of its own (--allow-file-access-from-files and, on macOS, --enable-avfoundation). `marktext file.md --user-data-dir Data` therefore arrived as `--user-data-dir --allow-file-access-from-files … file.md Data`, and parsing threw "option requires argument: --user-data-dir" instead of opening the file in a tab. A starting instance now sends its own process.argv as the additional data of the single instance lock, and the running instance parses that copy. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…-data-dir (#3020) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The e2e job on Linux saw the second instance end with no exit code. Keep its output and exit signal for the failure message, count the second-instance events the running instance receives, and check the opened tab even when the exit status is unexpected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… Linux
On the Linux CI runner the second instance aborted at startup ("The SUID
sandbox helper binary was found, but is not configured correctly") before
it reached the running instance. Playwright launches Electron with
--no-sandbox on Linux, so pass the same switch to the second instance.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Jocs
force-pushed
the
fix/3020-second-instance-argv
branch
from
September 16, 2026 03:32
f258124 to
e9a3df3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #3020
Summary
If MarkText is started with
--user-data-dirwhile an instance using that directory is already running, the file is not opened. For example, the report starts portable MarkText twice:Instead of opening
TestDoc2.mdin a new tab, the running instance showsArgError: option requires argument: --user-data-dir.Cause. The running instance parses the
argvof thesecond-instanceevent. Electron documents that thisargv"will not be exactly the same list of arguments as those passed to the second instance. The order might change and additional arguments might be appended" (see electron/electron#32933, closed as not planned). On develop (Electron 42, macOS), the running instance receives:Switches come first, so
--user-data-diris separated fromData. It is also followed by another switch, soargthrows. Only the--user-data-dir=Dataform survives this.Fix. Electron's recommendation is
additionalData.process.argvtoapp.requestSingleInstanceLock({ argv }).second-instancehandler parses that unchanged copy. If a second instance from a version without this change sends no data, the handler falls back toargvas before.Type of change
Test plan
issue-3020-second-instance-args.spec.ts(e2e, built app) opens a document, then starts a second instance withsecond.md --user-data-dir <same dir>. It checks that the second instance exits with 0 (the failure message includes its output), that the running instance receives onesecond-instanceevent and its listeners throw nothing, and thatsecond.mdopens as a tab without a new window.ArgError: option requires argument: --user-data-dir. With this change it passes (3/3 repeated runs).file --user-data-dir dir,--user-data-dir dir file,--user-data-dir=dir file,--user-data-dir dir --new-window file, andfile --user-data-dir dir --allow-file-access-from-files. On develop, every form except--user-data-dir=dirthrewArgErrorand opened nothing. With this change all five open the file, and--new-windowopens it in a new window.pnpm run typecheckpasses, eslint reports 0 errors on the changed files, all desktop unit tests pass (818/818), andlaunch.spec.ts+tabs.spec.tspass.Notes for reviewers
second-instancelisteners in a try/catch that records what they throw. Without the wrapper, the running instance hangs and never acknowledges the second instance. The second instance then carries on as an instance of its own, so the spec would time out instead of reporting theArgError.--no-sandboxon Linux. Playwright launches Electron with--no-sandboxon Linux, because the CI runner can't use Chromium's SUID sandbox. The spec passes the same switch to the second instance; without it, the second instance aborts at startup there, before it reaches the running instance.packages/desktop/src/main/index.ts: that PR changes theifaround the lock, this one changes the lock call. Whichever merges second needs a trivial rebase.🤖 Generated with Claude Code
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.