mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
* fix(build): spawn npx.cmd through a shell in the electron better-sqlite3 rebuild Node's CVE-2024-27980 hardening makes spawnSync of .cmd/.bat shims fail with status null unless shell:true — the v3.8.47 tag build died on the Windows job with 'better-sqlite3 rebuild against electron 43.1.0 failed (exit null)'. Extracted the spawn plan into electronRebuildPlan.mjs (pure, import-safe) with a regression test; args are fixed literals, no untrusted input reaches the shell. * fix(build): ship head-response-guard.cjs in the npm tarball (#7065) The prepublish prune allowlist (pack-artifact-policy.ts) lacked head-response-guard.cjs, so assembleStandalone copied it and the prune deleted it — every boot of the published 3.8.47 crashed with ERR_MODULE_NOT_FOUND (3rd occurrence of this class; tls-options/3.8.41). Also added to PACK_ARTIFACT_REQUIRED_PATHS so check:pack-artifact fails loudly, plus a closure test that derives every server-ws.mjs sibling import and asserts both lists cover it. * fix(ci): zero the Sonar quality-gate findings on new code - ci.yml sonarqube job: download the coverage artifact into coverage/ so lcov.info lands where sonar.javascript.lcov.reportPaths points — the upload strips the common coverage/ prefix, so 'path: .' left new-code coverage at 0% on every scan - kiro auto-import: await the async isCloudEnabled() gate (S6544 — a bare truthiness check on the Promise made syncToCloud run even with cloud sync disabled) - stream.ts: real JSON fallback in the reasoning-split clone (S3923 — both ternary branches called structuredClone, the promised fallback was dead) - codex executor: handle the async reader.cancel() rejection (S4822) - deterministic localeCompare sorts (S2871 x2) - classify-pr-changes.mjs: confine the argv list file to the workspace (jssecurity:S8707 path-traversal guard) + behavioral tests - Dockerfile: rebuild better-sqlite3 with npm's bundled node-gyp instead of npx --yes (docker:S6505 — no on-demand registry install) * chore(ci): make the Sonar quality gate informational (wait=false) The org's SonarCloud FREE plan cannot associate a custom quality gate — only the built-in Sonar way (80% new coverage) applies, which no full-cycle release PR can realistically meet. The scan still uploads (dashboard, PR decoration); the CI job just no longer fails on the gate. A tuned 'OmniRoute way' gate (coverage >=60, duplication <=5) is already configured in the org for the day the plan is upgraded — re-enable wait=true then. * chore(release): v3.8.48 hotfix bump + changelog (npm 3.8.47 unbootable, #7065) * test: align pack-artifact + dockerfile guards to the corrected contracts pack-artifact-policy.test.ts encoded the pre-#7065 REQUIRED list (without head-response-guard.cjs) and dockerfile-better-sqlite3-node-gyp-6700.test.ts asserted the npx invocation the Sonar fix replaced with npm's bundled node-gyp — both now assert the corrected behavior.
OmniRoute Electron Desktop App
This directory contains the Electron desktop application wrapper for OmniRoute.
Architecture (v1.6.4)
electron/
├── main.js # Main process — window, tray, server lifecycle, CSP, IPC
├── preload.js # Preload script — secure IPC bridge with disposer pattern
├── package.json # Electron-specific dependencies & electron-builder config
├── types.d.ts # TypeScript definitions (AppInfo, ServerStatus, ElectronAPI)
└── assets/ # Application icons and resources
src/shared/hooks/
└── useElectron.ts # React hooks — useSyncExternalStore, zero re-renders
Key Design Decisions
| Decision | Rationale |
|---|---|
waitForServer() polling |
Prevents blank screen on cold start — polls http://localhost:PORT before loading |
stdio: 'pipe' |
Captures server stdout/stderr for logging + readiness detection (not inherit) |
| Disposer pattern | onServerStatus() returns () => void for precise listener cleanup (no removeAllListeners) |
useSyncExternalStore |
Zero re-renders for useIsElectron() — no useState + useEffect cycle |
| CSP via session headers | Content-Security-Policy restricts script-src, connect-src etc. per Electron best practices |
| Platform-conditional titlebar | titleBarStyle: 'hiddenInset' only on macOS; default on Windows/Linux |
Development
Prerequisites
- Build the Next.js app first:
npm run build
- Install Electron dependencies:
cd electron
npm install
Running in Development
- Start the Next.js development server:
npm run dev
- In another terminal, start Electron:
cd electron
npm run dev
Running in Production Mode
- Build Next.js in standalone mode:
npm run build
- Start Electron:
cd electron
npm start
Building
Build for Current Platform
cd electron
npm run build
Build for Specific Platforms
# Windows
npm run build:win
# macOS (x64 + arm64)
npm run build:mac
# Linux
npm run build:linux
Output
Built applications are placed in dist-electron/:
- Windows:
.exeinstaller (NSIS) + portable.exe - macOS:
.dmginstaller (Intel + Apple Silicon) - Linux:
.AppImage
Installation
macOS
- Download the latest
.dmgfrom the Releases page. - Open the
.dmgfile. - Drag
OmniRoute.appto the Applications folder. - Launch from Applications.
⚠️ Note: The app is not signed with an Apple Developer certificate yet. If macOS blocks the app, run:
xattr -cr /Applications/OmniRoute.appOr right-click the app → Open → Open (to bypass Gatekeeper on first launch).
Windows
Installer (Recommended):
- Download
OmniRoute.Setup.*.exefrom Releases. - Run the installer.
- Launch from Start Menu or Desktop shortcut.
Portable (No Installation):
- Download
OmniRoute.exefrom Releases. - Run directly from any folder.
Linux
- Download the
.AppImagefrom Releases. - Make it executable:
chmod +x OmniRoute-*.AppImage - Run:
./OmniRoute-*.AppImage
Features
- Server Readiness — Waits for health check before showing window
- System Tray — Minimize to tray with quick actions (open, port change, quit)
- Port Management — Change port from tray menu (server restarts automatically)
- Window Controls — Custom minimize, maximize, close via IPC
- Content Security Policy — Restrictive CSP via session headers
- Offline Support — Bundled Next.js standalone server
- Single Instance — Only one app instance can run at a time
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
OMNIROUTE_PORT |
20128 |
Server port |
OMNIROUTE_MEMORY_MB |
512 |
Node.js heap limit (64–16384 MB) |
NODE_ENV |
production |
Set to development for dev mode |
Custom Icon
Place your icons in assets/:
icon.ico— Windows icon (256×256)icon.icns— macOS icon bundleicon.png— Linux/general use (512×512)tray-icon.png— System tray icon (16×16 or 32×32)
IPC Channels
Invoke (Renderer → Main, async)
| Channel | Returns | Description |
|---|---|---|
get-app-info |
AppInfo |
App name, version, platform, isDev, port |
open-external |
void |
Open URL in default browser (http/https only) |
get-data-dir |
string |
Get userData directory path |
restart-server |
{ success } |
Stop + restart server (5s timeout + SIGKILL) |
Send (Renderer → Main, fire-and-forget)
| Channel | Description |
|---|---|
window-minimize |
Minimize window |
window-maximize |
Toggle maximize/restore |
window-close |
Close window (minimize to tray) |
Receive (Main → Renderer, events)
| Channel | Payload | Emitted When |
|---|---|---|
server-status |
ServerStatus |
Server starts, stops, errors, or restarts |
port-changed |
number |
Port change via tray menu |
Note
: Listeners return disposer functions for precise cleanup. See
useServerStatusandusePortChangedhooks.
Security
| Feature | Implementation |
|---|---|
| Context Isolation | contextIsolation: true — renderer cannot access Node.js |
| Node Integration | nodeIntegration: false — no require() in renderer |
| IPC Whitelist | Channel names validated in preload via safeInvoke/safeSend/safeOn |
| URL Validation | shell.openExternal() only allows http: / https: protocols |
| CSP | Content-Security-Policy header set via session.webRequest.onHeadersReceived |
| Web Security | webSecurity: true — same-origin policy enforced |
React Hooks
| Hook | Returns | Description |
|---|---|---|
useIsElectron() |
boolean |
Zero-render detection via useSyncExternalStore |
useElectronAppInfo() |
{ appInfo, loading, error } |
App info from main process |
useDataDir() |
{ dataDir, loading, error } |
User data directory |
useWindowControls() |
{ minimize, maximize, close } |
Window control actions |
useOpenExternal() |
{ openExternal } |
Open URLs in browser |
useServerControls() |
{ restart, restarting } |
Server restart control |
useServerStatus(cb) |
Disposer | Listen for server status events |
usePortChanged(cb) |
Disposer | Listen for port change events |
Troubleshooting
App Won't Start
- Check if port 20128 is available:
lsof -i :20128 - Check console logs for
[Electron]prefix - Verify the build output exists in
.build/next/standalone
White Screen
- Verify Next.js build exists — server readiness waits 30s max
- Check
[Server]and[Server:err]log output - Look for CSP violations in developer console
Build Fails
Ensure you have build tools installed:
- Windows: Visual Studio Build Tools
- macOS: Xcode Command Line Tools
- Linux:
build-essential,libsecret-1-dev
License
MIT