Skip to content

fix: dev launches passing the script file instead of the app directory - #1121

Merged
FlorianRappl merged 1 commit into
ElectronNET:developfrom
Denny09310:feature/fix-dev-userdata-appname
Oct 22, 2026
Merged

FlorianRappl merged 1 commit into
ElectronNET:developfrom
Denny09310:feature/fix-dev-userdata-appname

Conversation

@Denny09310

Copy link
Copy Markdown
Contributor

Description

In unpackaged (dev) launches, Electron was started with main.js as its first
argument. Because that is a script file and not an app directory, Electron
routed through its built-in default app (default_app.asar), whose manifest is
named Electron. As a result, the app name and the default userData folder
were resolved by Chromium at process startup to:

%APPDATA%\Electron  (= <appData> + app.name)

This happens inside the Chromium layer long before app.on('ready') — so
GPU cache, network-service storage, etc. are created under that path at
startup, and any later correction (e.g. via app.setPath on ready) is
partial and leaves a stray %APPDATA%\Electron folder behind on every run.

The generated .electron/package.json (built by ElectronCreatePackageJson
from the template + MSBuild props) already contains the correct
name/productName — it just was never submitted to Electron as the app
manifest. It was only read as data by main.js; the process was pointed at
the script file instead of the directory.

Changes

  • ElectronProcessActive.cs (unpackaged/.NET-first branch): launch
    electron <.electron dir> instead of electron main.js, so Electron reads
    package.json as the app manifest and resolves app name + default
    userData from productName at startup — same mechanism as a packaged
    build. Covers the Windows and macOS (Electron.app/Contents/MacOS/Electron)
    launch paths.
  • launchSettings.json / docs: the "Electron-first" debug profiles and docs
    snippets now also pass the app directory (.) instead of main.js.
  • Changelog entry added.

Compatibility notes

  • main.js derives all paths (currentPath, manifest, currentBinPath) from
    __dirname, which is unchanged when the directory is the app argument.
  • app.isPackaged stays false with an unpackaged directory app, so
    getForwardedArgs() (process.argv.slice(app.isPackaged ? 1 : 2)) and the
    command-line switch handling are unaffected.
  • The packaged/publish flow already worked correctly and is unchanged.

Testing

  • dotnet run -unpackeddotnet (sample app, Windows): launched process
    command line is ...electron.exe . -unpackeddotnet --trace-warnings -electronforcedport=...
  • All Chromium child processes (GPU/network/renderer) report
    --user-data-dir=%APPDATA%\<productName>; no %APPDATA%\Electron
    folder is created on dev runs (previously it reappeared every launch)
  • Window/UI loads and the socket bridge connects (switch parsing intact)
  • Single-instance behavior with directory argument (macOS/Linux not yet
    verified)

Point the unpackaged dev launches at the .electron directory rather than
main.js, so Electron reads package.json as the app manifest and resolves
the app name and the default userData folder from productName at process
startup, instead of falling back to the default app's "Electron" name.
Covers the .NET-first branch in ElectronProcessActive and the
Electron-first launches (launchSettings and docs).
@github-actions

Copy link
Copy Markdown

pr-comment: Run #154

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1680 1518 0 0 0 162 0 5m 56s

🎉 All tests passed!

Github Test Reporter by CTRF 💚

@FlorianRappl FlorianRappl added this to the 1.0.0 milestone Oct 22, 2026

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - let's get the preview out.

@FlorianRappl
FlorianRappl merged commit 905e1bb into ElectronNET:develop Oct 22, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants