This directory contains the Electron wrapper for New API, allowing it to run as a native desktop application on Windows, macOS, and Linux.
This directory contains the Electron wrapper for New API, providing a native desktop application with system tray support for Windows, macOS, and Linux.
## Architecture
## Prerequisites
The Electron app consists of:
-**main.js**: Main process that spawns the Go backend server and creates the application window
-**preload.js**: Preload script for secure context isolation
-**package.json**: Electron dependencies and build configuration
### 1. Go Binary (Required)
The Electron app requires the compiled Go binary to function. You have two options:
## Development
### Prerequisites
1. Build the Go backend first:
**Option A: Use existing binary (without Go installed)**
```bash
cd ..
go build -onew-api
# If you have a pre-built binary (e.g., new-api-macos)
cp ../new-api-macos ../new-api
```
2. Install Electron dependencies:
**Option B: Build from source (requires Go)**
TODO
### 3. Electron Dependencies
```bash
cd electron
npm install
```
### Running in Development Mode
## Development
Run the app in development mode:
```bash
npm start
```
This will:
- Start the Go backend on port 3000
- Open an Electron window pointing to `http://localhost:3000`
- Enable DevTools for debugging
- Open an Electron window with DevTools enabled
- Create a system tray icon (menu bar on macOS)
- Store database in `../data/new-api.db`
## Building for Production
### Quick Build (Current Platform)
Use the provided build script:
### Quick Build
```bash
./build.sh
```
This will:
1. Build the frontend (web/dist)
2. Build the Go binary for your platform
3. Package the Electron app
### Manual Build Steps
1. Build frontend:
```bash
cd ../web
DISABLE_ESLINT_PLUGIN='true' bun run build
```
# Ensure Go binary exists in parent directory
ls ../new-api # Should exist
2. Build backend:
```bash
cd ..
# macOS/Linux
go build -ldflags="-s -w"-o new-api
# Windows
go build -ldflags="-s -w"-o new-api.exe
```
3. Build Electron app:
```bash
cd electron
npm install
# All platforms
# Build for current platform
npm run build
# Or specific platforms
npm run build:mac # macOS (DMG, ZIP)
npm run build:win # Windows (NSIS installer, Portable)
npm run build:linux # Linux (AppImage, DEB)
```
### Output
Built apps are located in `electron/dist/`:
-**macOS**: `.dmg` and `.zip`
-**Windows**: `.exe` installer and portable `.exe`
-**Linux**: `.AppImage` and `.deb`
## Cross-Platform Building
To build for other platforms:
```bash
# From macOS, build Windows app
npm run build:win
# From macOS, build Linux app
npm run build:linux
# Platform-specific builds
npm run build:mac # Creates .dmg and .zip
npm run build:win # Creates .exe installer
npm run build:linux # Creates .AppImage and .deb
```
Note: Building macOS apps requires macOS. Building Windows apps with code signing requires Windows.
### Build Output
- Built applications are in `electron/dist/`
- macOS: `.dmg` (installer) and `.zip` (portable)
- Windows: `.exe` (installer) and portable exe
- Linux: `.AppImage` and `.deb`
## Configuration
### Port
The app uses port 3000 by default. To change:
Edit `electron/main.js`:
Default port is 3000. To change, edit `main.js`:
```javascript
constPORT=3000;// Change to your desired port
constPORT=3000;// Change to desired port
```
### Data Directory
-**Development**: Uses `data/` in the project root