-
Notifications
You must be signed in to change notification settings - Fork 23
fix(electron): make launch-chooser selections authoritative + harden provisioning #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danshapiro
wants to merge
6
commits into
main
Choose a base branch
from
fix/electron-launch-chooser-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d10566
fix(electron): make launch-chooser selections authoritative + harden …
codex dc35143
fix(electron): harden forced-launch IPC, port collisions, and provisi…
codex f33c67e
fix(electron): authoritative main-process port check for "Start local"
codex 328348f
fix(electron): runtime-validate launch IPC, bind-test ports, preserve…
codex 57b3049
fix(electron): drop renderer port-collision guard; trust the authorit…
codex 2cbd540
fix(electron): URL-encode the auth token in the window load URL
codex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import type { DesktopConfig } from './types.js' | ||
|
|
||
| /** | ||
| * One-time provisioning from a silent installer. | ||
| * | ||
| * The installer cannot safely emit JSON (it has no string-escaping), so it | ||
| * writes raw values to a line-based `desktop.provision` file instead. We parse | ||
| * that file here and persist a real config via `patchDesktopConfig`, whose | ||
| * `JSON.stringify` serialization escapes quotes/backslashes correctly. | ||
| */ | ||
|
|
||
| export interface ParsedProvisioning { | ||
| remoteUrl?: string | ||
| remoteToken?: string | ||
| } | ||
|
|
||
| /** | ||
| * Parse `KEY=value` lines. The value keeps every character after the first `=` | ||
| * verbatim (so a token may contain `=`, `"`, `\`, or meaningful surrounding | ||
| * whitespace); only the line ending is stripped, by the split. The key is | ||
| * trimmed for tolerance. Unknown or malformed lines are ignored. | ||
| */ | ||
| export function parseProvisioning(content: string): ParsedProvisioning { | ||
| const result: ParsedProvisioning = {} | ||
| for (const line of content.split(/\r?\n/)) { | ||
| const idx = line.indexOf('=') | ||
| if (idx === -1) continue | ||
| const key = line.slice(0, idx).trim() | ||
| const value = line.slice(idx + 1) | ||
| if (key === 'FRESHELL_REMOTE_URL') result.remoteUrl = value | ||
| else if (key === 'FRESHELL_TOKEN') result.remoteToken = value | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| export interface ProvisioningDeps { | ||
| /** Returns the file contents, or undefined if the provision file is absent. */ | ||
| readFile: (path: string) => string | undefined | ||
| deleteFile: (path: string) => void | ||
| patchDesktopConfig: (patch: Partial<DesktopConfig>) => Promise<DesktopConfig | void> | ||
| } | ||
|
|
||
| /** | ||
| * Apply a provision file if present, then always remove it (so it only takes | ||
| * effect once). A malformed file must never block startup, so persistence | ||
| * errors are swallowed. Returns true when a file was found and consumed. | ||
| */ | ||
| export async function applyProvisioningFile( | ||
| provisionPath: string, | ||
| deps: ProvisioningDeps, | ||
| ): Promise<boolean> { | ||
| let content: string | undefined | ||
| try { | ||
| content = deps.readFile(provisionPath) | ||
| } catch { | ||
| // The file exists but is unreadable (locked, a directory, bad perms). | ||
| // It must not brick startup, and it must not wedge every launch, so make a | ||
| // best-effort attempt to clear it and bail. | ||
| deps.deleteFile(provisionPath) | ||
| return true | ||
| } | ||
|
|
||
| if (content === undefined) return false | ||
|
|
||
| try { | ||
| const { remoteUrl, remoteToken } = parseProvisioning(content) | ||
| if (remoteUrl && remoteToken) { | ||
| await deps.patchDesktopConfig({ | ||
| serverMode: 'remote', | ||
| remoteUrl, | ||
| remoteToken, | ||
| setupCompleted: true, | ||
| }) | ||
| } | ||
| } catch { | ||
| // A malformed provision file or persist failure must not brick startup. | ||
| } finally { | ||
| deps.deleteFile(provisionPath) | ||
| } | ||
| return true | ||
| } | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a silent installer provisions an already-configured desktop that previously enabled
alwaysAskOnLaunch, this patch merges only the remote fields into the existing config, so the preservedalwaysAskOnLaunch: truemakeschooseLaunchAction()show the chooser instead of connecting to the newly provisioned remote server on first launch. The old installer overwrotedesktop.jsonwithout this field, causing the schema default (false) to apply, so this is a regression for managed reinstall/update flows; includealwaysAskOnLaunch: false(or otherwise force the provisioned launch) with the provisioning patch.Useful? React with 👍 / 👎.