Skip to content

IPC migration phase 1: remove direct process reads from Tier 1 renderer files#22

Merged
NamecoinGithub merged 1 commit into
Mergingfrom
copilot/scope-ipc-migration-project
Jul 11, 2026
Merged

IPC migration phase 1: remove direct process reads from Tier 1 renderer files#22
NamecoinGithub merged 1 commit into
Mergingfrom
copilot/scope-ipc-migration-project

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown

contextIsolation:true was previously reverted on the main window after it caused a blank/black GUI, because renderer code across ~29 files reads Node globals (process) and core modules (fs, http, etc.) directly — something that only works with contextIsolation:false. This PR lands the first, lowest-risk wave of the incremental migration needed to safely re-enable contextIsolation in the future: files that only read process.platform/process.env, with no fs/http involved.

Preload bridge

  • Extended window.nexusEnv (exposed by src/main/preload.js) to include platform, arch, HOME, and USERPROFILE, in addition to the existing NODE_ENV/PORT.
  • Added src/shared/lib/nexusEnv.ts, a typed helper renderer code should use instead of the raw process global. Logs an error rather than silently defaulting if the bridge is unexpectedly missing.

Migrated files

Replaced direct process.platform / process.env.NODE_ENV reads with the nexusEnv bridge in:

  • src/shared/lib/store.tsx
  • src/shared/lib/appMenu.ts
  • src/shared/lib/wallet.ts
  • src/App/Settings/Style/BackgroundPicker.tsx
  • src/App/Settings/Core/EmbeddedCoreSettings.tsx
// before
if (process.platform === 'darwin') { ... }

// after
import nexusEnv from 'lib/nexusEnv';
if (nexusEnv.platform === 'darwin') { ... }

Scope correction

ExternalIcon.tsx, ModuleIcon.tsx, and WebView.tsx were initially assumed to be simple process-only files, but they also perform direct fs reads — they need real IPC channels, not just the bridge, so they're deferred to the next (Tier 2) migration phase.

Not in this PR

contextIsolation remains false on the main window. The remaining Tier 2 (fs/path helpers, e.g. consts/paths.ts, geoip.ts, theme.ts) and Tier 3 (api.ts, core.ts, bootstrap.ts, module install pipeline, updater) files still read Node modules directly and require IPC conversion before the flag can be flipped and fully regression-tested.

@NamecoinGithub
NamecoinGithub marked this pull request as ready for review July 11, 2026 02:59
Copilot AI review requested due to automatic review settings July 11, 2026 02:59
@NamecoinGithub
NamecoinGithub merged commit 729a03f into Merging Jul 11, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a renderer-safe environment accessor (lib/nexusEnv) backed by the preload bridge (window.nexusEnv) and migrates a first batch of “process-only” Tier 1 renderer files off direct process.* reads, supporting future re-enablement of contextIsolation.

Changes:

  • Extend src/main/preload.js to expose additional environment/platform fields via window.nexusEnv.
  • Add src/shared/lib/nexusEnv.ts as a typed renderer helper for accessing window.nexusEnv (plus isDevelopment).
  • Replace process.platform / process.env.NODE_ENV checks with nexusEnv.platform / isDevelopment in the migrated renderer files.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/shared/lib/wallet.ts Replaces process.platform usage with nexusEnv.platform for macOS-specific behavior.
src/shared/lib/store.tsx Switches dev-mode detection from process.env.NODE_ENV to isDevelopment.
src/shared/lib/nexusEnv.ts Adds a typed accessor module for preload-injected env/platform values.
src/shared/lib/appMenu.ts Replaces dev-mode checks and macOS menu branching to use nexusEnv instead of process.
src/main/preload.js Extends window.nexusEnv bridge with platform/arch and home-directory related fields.
src/App/Settings/Style/BackgroundPicker.tsx Replaces Windows path normalization branch to use nexusEnv.platform.
src/App/Settings/Core/EmbeddedCoreSettings.tsx Replaces Windows filter selection branch to use nexusEnv.platform.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to +30
/** Mirrors `process.platform` from the main process. */
platform: NodeJS.Platform;
/** Mirrors `process.arch` from the main process. */
arch: string;
/** Mirrors `process.env.HOME`; populated on macOS/Linux. */
HOME: string;
/** Mirrors `process.env.USERPROFILE`; populated on Windows. */
USERPROFILE: string;
}

const fallbackNexusEnv: NexusEnv = {
NODE_ENV: 'production',
PORT: '',
platform: 'linux',
arch: '',
HOME: '',
USERPROFILE: '',
};
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.

3 participants