Files
OmniRoute/electron
diegosouzapw d3ace8d611 fix: security hardening, tests, docs for Electron desktop & memory optimization
## Security Fixes
- Sanitize OMNIROUTE_MEMORY_MB with parseInt + range validation (64-16384)
  to prevent command injection via spawn() args
- Validate URL protocol in shell.openExternal (http/https only)
  to prevent RCE in Electron renderer compromise
- Bump default memory from 256MB to 512MB

## Electron package-lock.json
- Added to .gitignore (5278 lines removed from tracking)

## Test Suite (64 tests, 9 suites)
- electron-main.test.mjs: URL validation, IPC channels, window handler
- electron-preload.test.mjs: channel whitelist, API surface, open-external
- cli-memory.test.mjs: injection prevention, boundary values, .env parsing

## Documentation
- Desktop App section added to all 30 READMEs (9 fully translated)
- USER_GUIDE.md updated with 512MB default
- .env.example reflects new defaults
2026-02-28 07:59:38 -03:00
..
2026-02-28 11:54:41 +05:30

OmniRoute Electron Desktop App

This directory contains the Electron desktop application wrapper for OmniRoute.

Structure

electron/
├── main.js          # Main process (window management, IPC)
├── preload.js       # Preload script (secure bridge to renderer)
├── package.json     # Electron-specific dependencies
├── types.d.ts       # TypeScript definitions
└── assets/          # Application icons and resources

Development

Prerequisites

  1. Build the Next.js app first:
npm run build
  1. Install Electron dependencies:
cd electron
npm install

Running in Development

  1. Start the Next.js development server:
npm run dev
  1. In another terminal, start Electron:
cd electron
npm run dev

Running in Production Mode

  1. Build Next.js in standalone mode:
npm run build
  1. 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
npm run build:mac

# Linux
npm run build:linux

Output

Built applications are placed in dist-electron/:

  • Windows: .exe installer (NSIS)
  • macOS: .dmg installer
  • Linux: .AppImage

Features

  • System Tray Integration: Minimize to tray, quick actions
  • Native Notifications: Desktop notifications
  • Window Management: Minimize, maximize, close
  • Auto-start: Option to launch on system startup
  • Offline Support: Local server bundled with the app

Configuration

Environment Variables

The Electron app respects these environment variables:

  • OMNIROUTE_PORT: Server port (default: 20128)
  • NODE_ENV: Set to 'production' for production builds

Custom Icon

Place your icons in assets/:

  • icon.ico - Windows icon (256x256)
  • icon.icns - macOS icon bundle
  • icon.png - Linux/general use (512x512)
  • tray-icon.png - System tray icon (16x16 or 32x32)

IPC Channels

Channel Direction Description
get-app-info Renderer → Main Get app name, version, platform
open-external Renderer → Main Open URL in default browser
get-data-dir Renderer → Main Get data directory path
restart-server Renderer → Main Restart the internal server
server-status Main → Renderer Server status updates
port-changed Main → Renderer Port change notifications

Security

  • contextIsolation: true - Isolates renderer from Node.js
  • nodeIntegration: false - No direct Node.js access in renderer
  • Preload script validates IPC channels
  • No remote code execution

Troubleshooting

App Won't Start

  1. Check if port 20128 is available
  2. Check logs in the console
  3. Verify the build output exists

White Screen

  1. Verify Next.js build exists
  2. Check the server URL in main.js
  3. Check for console errors

Build Fails

  1. Ensure you have build tools installed:
    • Windows: Visual Studio Build Tools
    • macOS: Xcode Command Line Tools
    • Linux: build-essential, libsecret-1-dev

License

MIT