commit
Browse files- .gitattributes +79 -79
- .gitignore +81 -0
- README.md +232 -232
- index.html +11 -1
- main.js +1122 -1066
- package-lock.json +35 -1
- package.json +9 -4
- packages/@chahuadev/dev-launcher/README.md +206 -18
- preload.js +26 -23
- scripts/before-pack-obfuscate.js +42 -5
- scripts/build-v8-bytecode.js +127 -21
- web/renderer.js +282 -58
- web/styles.css +34 -2
.gitattributes
CHANGED
|
@@ -1,80 +1,80 @@
|
|
| 1 |
-
# Dependencies
|
| 2 |
-
node_modules/
|
| 3 |
-
npm-debug.log*
|
| 4 |
-
yarn-debug.log*
|
| 5 |
-
yarn-error.log*
|
| 6 |
-
package-lock.json
|
| 7 |
-
yarn.lock
|
| 8 |
-
|
| 9 |
-
# Runtime
|
| 10 |
-
*.log
|
| 11 |
-
logs/
|
| 12 |
-
pids/
|
| 13 |
-
*.pid
|
| 14 |
-
*.seed
|
| 15 |
-
*.pid.lock
|
| 16 |
-
|
| 17 |
-
# Coverage and testing
|
| 18 |
-
coverage/
|
| 19 |
-
.nyc_output/
|
| 20 |
-
.jest/
|
| 21 |
-
|
| 22 |
-
# Environment
|
| 23 |
-
.env
|
| 24 |
-
.env.local
|
| 25 |
-
.env.development.local
|
| 26 |
-
.env.test.local
|
| 27 |
-
.env.production.local
|
| 28 |
-
|
| 29 |
-
# Editor files
|
| 30 |
-
.vscode/
|
| 31 |
-
.idea/
|
| 32 |
-
*.swp
|
| 33 |
-
*.swo
|
| 34 |
-
*~
|
| 35 |
-
|
| 36 |
-
# OS generated files
|
| 37 |
-
.DS_Store
|
| 38 |
-
.DS_Store?
|
| 39 |
-
._*
|
| 40 |
-
.Spotlight-V100
|
| 41 |
-
.Trashes
|
| 42 |
-
ehthumbs.db
|
| 43 |
-
Thumbs.db
|
| 44 |
-
|
| 45 |
-
# Backup directories (created by this tool)
|
| 46 |
-
emoji-backup-*/
|
| 47 |
-
backup-*/
|
| 48 |
-
|
| 49 |
-
# Temporary test files
|
| 50 |
-
test/temp/
|
| 51 |
-
test/fixtures/temp/
|
| 52 |
-
test
|
| 53 |
-
|
| 54 |
-
# Distribution
|
| 55 |
-
dist/
|
| 56 |
-
build/
|
| 57 |
-
|
| 58 |
-
# NPM
|
| 59 |
-
.npm
|
| 60 |
-
.npmrc
|
| 61 |
-
|
| 62 |
-
# Ignore binary images
|
| 63 |
-
|
| 64 |
-
# Layout files (auto-generated per project)
|
| 65 |
-
layouts/*.json
|
| 66 |
-
|
| 67 |
-
# Python runtime โ€” downloaded at build time, never committed
|
| 68 |
-
# Run: npm run download-python-win (Windows only, ~12 MB)
|
| 69 |
-
runtimes/
|
| 70 |
-
|
| 71 |
-
# Python compiled cache
|
| 72 |
-
__pycache__/
|
| 73 |
-
*.pyc
|
| 74 |
-
*.pyo
|
| 75 |
-
|
| 76 |
-
# .NET build artifacts
|
| 77 |
-
engines/cs_scanner/bin/
|
| 78 |
-
engines/cs_scanner/obj/
|
| 79 |
-
*.pyd
|
| 80 |
icons/
|
|
|
|
| 1 |
+
# Dependencies
|
| 2 |
+
node_modules/
|
| 3 |
+
npm-debug.log*
|
| 4 |
+
yarn-debug.log*
|
| 5 |
+
yarn-error.log*
|
| 6 |
+
package-lock.json
|
| 7 |
+
yarn.lock
|
| 8 |
+
|
| 9 |
+
# Runtime
|
| 10 |
+
*.log
|
| 11 |
+
logs/
|
| 12 |
+
pids/
|
| 13 |
+
*.pid
|
| 14 |
+
*.seed
|
| 15 |
+
*.pid.lock
|
| 16 |
+
|
| 17 |
+
# Coverage and testing
|
| 18 |
+
coverage/
|
| 19 |
+
.nyc_output/
|
| 20 |
+
.jest/
|
| 21 |
+
|
| 22 |
+
# Environment
|
| 23 |
+
.env
|
| 24 |
+
.env.local
|
| 25 |
+
.env.development.local
|
| 26 |
+
.env.test.local
|
| 27 |
+
.env.production.local
|
| 28 |
+
|
| 29 |
+
# Editor files
|
| 30 |
+
.vscode/
|
| 31 |
+
.idea/
|
| 32 |
+
*.swp
|
| 33 |
+
*.swo
|
| 34 |
+
*~
|
| 35 |
+
|
| 36 |
+
# OS generated files
|
| 37 |
+
.DS_Store
|
| 38 |
+
.DS_Store?
|
| 39 |
+
._*
|
| 40 |
+
.Spotlight-V100
|
| 41 |
+
.Trashes
|
| 42 |
+
ehthumbs.db
|
| 43 |
+
Thumbs.db
|
| 44 |
+
|
| 45 |
+
# Backup directories (created by this tool)
|
| 46 |
+
emoji-backup-*/
|
| 47 |
+
backup-*/
|
| 48 |
+
|
| 49 |
+
# Temporary test files
|
| 50 |
+
test/temp/
|
| 51 |
+
test/fixtures/temp/
|
| 52 |
+
test
|
| 53 |
+
|
| 54 |
+
# Distribution
|
| 55 |
+
dist/
|
| 56 |
+
build/
|
| 57 |
+
|
| 58 |
+
# NPM
|
| 59 |
+
.npm
|
| 60 |
+
.npmrc
|
| 61 |
+
|
| 62 |
+
# Ignore binary images
|
| 63 |
+
|
| 64 |
+
# Layout files (auto-generated per project)
|
| 65 |
+
layouts/*.json
|
| 66 |
+
|
| 67 |
+
# Python runtime โ€” downloaded at build time, never committed
|
| 68 |
+
# Run: npm run download-python-win (Windows only, ~12 MB)
|
| 69 |
+
runtimes/
|
| 70 |
+
|
| 71 |
+
# Python compiled cache
|
| 72 |
+
__pycache__/
|
| 73 |
+
*.pyc
|
| 74 |
+
*.pyo
|
| 75 |
+
|
| 76 |
+
# .NET build artifacts
|
| 77 |
+
engines/cs_scanner/bin/
|
| 78 |
+
engines/cs_scanner/obj/
|
| 79 |
+
*.pyd
|
| 80 |
icons/
|
.gitignore
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dependencies
|
| 2 |
+
node_modules/
|
| 3 |
+
npm-debug.log*
|
| 4 |
+
yarn-debug.log*
|
| 5 |
+
yarn-error.log*
|
| 6 |
+
package-lock.json
|
| 7 |
+
yarn.lock
|
| 8 |
+
|
| 9 |
+
# Runtime
|
| 10 |
+
*.log
|
| 11 |
+
logs/
|
| 12 |
+
pids/
|
| 13 |
+
*.pid
|
| 14 |
+
*.seed
|
| 15 |
+
*.pid.lock
|
| 16 |
+
|
| 17 |
+
# Coverage and testing
|
| 18 |
+
coverage/
|
| 19 |
+
.nyc_output/
|
| 20 |
+
.jest/
|
| 21 |
+
|
| 22 |
+
# Environment
|
| 23 |
+
.env
|
| 24 |
+
.env.local
|
| 25 |
+
.env.development.local
|
| 26 |
+
.env.test.local
|
| 27 |
+
.env.production.local
|
| 28 |
+
|
| 29 |
+
# Editor files
|
| 30 |
+
.vscode/
|
| 31 |
+
.idea/
|
| 32 |
+
*.swp
|
| 33 |
+
*.swo
|
| 34 |
+
*~
|
| 35 |
+
|
| 36 |
+
# OS generated files
|
| 37 |
+
.DS_Store
|
| 38 |
+
.DS_Store?
|
| 39 |
+
._*
|
| 40 |
+
.Spotlight-V100
|
| 41 |
+
.Trashes
|
| 42 |
+
ehthumbs.db
|
| 43 |
+
Thumbs.db
|
| 44 |
+
|
| 45 |
+
# Backup directories (created by this tool)
|
| 46 |
+
emoji-backup-*/
|
| 47 |
+
backup-*/
|
| 48 |
+
|
| 49 |
+
# Temporary test files
|
| 50 |
+
test/temp/
|
| 51 |
+
test/fixtures/temp/
|
| 52 |
+
test
|
| 53 |
+
|
| 54 |
+
# Distribution
|
| 55 |
+
dist/
|
| 56 |
+
build/
|
| 57 |
+
|
| 58 |
+
# NPM
|
| 59 |
+
.npm
|
| 60 |
+
.npmrc
|
| 61 |
+
|
| 62 |
+
# Ignore binary images
|
| 63 |
+
|
| 64 |
+
# Layout files (auto-generated per project)
|
| 65 |
+
layouts/*.json
|
| 66 |
+
|
| 67 |
+
# Python runtime โ€” downloaded at build time, never committed
|
| 68 |
+
# Run: npm run download-python-win (Windows only, ~12 MB)
|
| 69 |
+
runtimes/
|
| 70 |
+
|
| 71 |
+
# Python compiled cache
|
| 72 |
+
__pycache__/
|
| 73 |
+
*.pyc
|
| 74 |
+
*.pyo
|
| 75 |
+
|
| 76 |
+
# .NET build artifacts
|
| 77 |
+
engines/cs_scanner/bin/
|
| 78 |
+
engines/cs_scanner/obj/
|
| 79 |
+
*.pyd
|
| 80 |
+
icons/
|
| 81 |
+
dev-launcher.exe
|
README.md
CHANGED
|
@@ -1,232 +1,232 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: other
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
-
tags:
|
| 6 |
-
- code-analysis
|
| 7 |
-
- static-analysis
|
| 8 |
-
- javascript
|
| 9 |
-
- electron
|
| 10 |
-
- emoji-cleaner
|
| 11 |
-
- junk-sweeper
|
| 12 |
-
- plugin-management
|
| 13 |
-
- desktop-app
|
| 14 |
-
- electron-app
|
| 15 |
-
- security
|
| 16 |
-
---
|
| 17 |
-
<div align="center">
|
| 18 |
-
<p align="center">
|
| 19 |
-
<img src="https://huggingface.co/datasets/chahuadev/chahuadev-png/resolve/main/chahuadev-dev-launcher.png" width="700" alt="Junk Sweeper — Main Dashboard">
|
| 20 |
-
</p>
|
| 21 |
-
|
| 22 |
-
<p align="center">
|
| 23 |
-
<a href="https://www.npmjs.com/package/@chahuadev/junk-sweeper-app"><img src="https://img.shields.io/npm/v/@chahuadev/dev-launcher?style=for-the-badge&color=blue" alt="NPM Version"></a>
|
| 24 |
-
<a href="https://www.npmjs.com/package/@chahuadev/dev-launcher"><img src="https://img.shields.io/npm/dt/@chahuadev/dev-launcher?style=for-the-badge&color=success" alt="NPM Downloads"></a>
|
| 25 |
-
<a href="https://huggingface.co/datasets/chahuadev/chahuadev-dev-launcher"><img src="https://img.shields.io/badge/%20HuggingFace-Dataset-yellow?style=for-the-badge" alt="HuggingFace Dataset"></a>
|
| 26 |
-
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Non--Commercial-blue?style=for-the-badge" alt="Non-Commercial License"></a>
|
| 27 |
-
<img src="https://img.shields.io/badge/Electron-40+-47848F?style=for-the-badge&logo=electron&logoColor=white" alt="Electron 40+">
|
| 28 |
-
<img src="https://img.shields.io/badge/Node.js-%E2%89%A522.0.0-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js 22">
|
| 29 |
-
<img src="https://img.shields.io/badge/Platform-Windows-0078D4?style=for-the-badge&logo=windows&logoColor=white" alt="Windows">
|
| 30 |
-
<img src="https://img.shields.io/badge/Analysis-Read--Only%20%E2%9C%93-blue?style=for-the-badge" alt="Read-Only Analysis">
|
| 31 |
-
<img src="https://img.shields.io/badge/Security-10--Layer%20Gateway-red?style=for-the-badge&logo=shield&logoColor=white" alt="7-Layer Security">
|
| 32 |
-
</p>
|
| 33 |
-
|
| 34 |
-
# Chahuadev Dev Launcher
|
| 35 |
-
|
| 36 |
-
Portable desktop command runner for development projects.
|
| 37 |
-
|
| 38 |
-
## Purpose
|
| 39 |
-
|
| 40 |
-
- Drop `dev-launcher.exe` inside a project folder.
|
| 41 |
-
- Auto-detect project type from `package.json`.
|
| 42 |
-
- Run grouped commands from one UI.
|
| 43 |
-
- Manage Cloudflare R2 upload flow for build artifacts.
|
| 44 |
-
|
| 45 |
-
## Repository layout
|
| 46 |
-
|
| 47 |
-
- `main.js`, `preload.js`, `index.html`, `web/`: Electron runtime + UI
|
| 48 |
-
- `build-desktop.bat`, `build-linux-wsl.sh`: local build scripts
|
| 49 |
-
- `dist/`: desktop build outputs
|
| 50 |
-
- `packages/`: npm publish package workspace
|
| 51 |
-
|
| 52 |
-
## NPM publish package
|
| 53 |
-
|
| 54 |
-
The npm-uploadable package lives in:
|
| 55 |
-
|
| 56 |
-
- `packages/@chahuadev/dev-launcher/`
|
| 57 |
-
|
| 58 |
-
This package is designed to:
|
| 59 |
-
|
| 60 |
-
1. Download platform binary at install time (`postinstall`)
|
| 61 |
-
2. Expose launcher CLI command (`dev-launcher`)
|
| 62 |
-
3. Run downloaded binary from `bin/`
|
| 63 |
-
|
| 64 |
-
See package docs here:
|
| 65 |
-
|
| 66 |
-
- `packages/README.md`
|
| 67 |
-
- `packages/@chahuadev/dev-launcher/README.md`
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
## NPM Install Commands (Published Package)
|
| 71 |
-
|
| 72 |
-
Global install on Windows:
|
| 73 |
-
|
| 74 |
-
```bash
|
| 75 |
-
npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
Global install on Linux:
|
| 79 |
-
|
| 80 |
-
```bash
|
| 81 |
-
sudo npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 82 |
-
```
|
| 83 |
-
## Home Overview (Detailed)
|
| 84 |
-
|
| 85 |
-
Dev Launcher focuses on a practical project-local flow:
|
| 86 |
-
|
| 87 |
-
- Place the launcher in a project root.
|
| 88 |
-
- Detect project type automatically from `package.json`.
|
| 89 |
-
- Render grouped commands in the left panel.
|
| 90 |
-
- Stream complete process output in the terminal panel.
|
| 91 |
-
|
| 92 |
-
Recent major additions reflected in Home:
|
| 93 |
-
|
| 94 |
-
- Simplified R2 flow with login/logout and gated actions.
|
| 95 |
-
- Safer command execution and external URL controls.
|
| 96 |
-
- Improved build support, including V8 command path and Linux WSL fallback.
|
| 97 |
-
- Better command output visibility with progress-oriented terminal messages.
|
| 98 |
-
|
| 99 |
-
## Features Snapshot
|
| 100 |
-
|
| 101 |
-
- Auto project detection for Expo, React Native, Electron, Next.js, Vite, and plain npm projects.
|
| 102 |
-
- One-click command groups for Metro, Gradle, ADB, Electron build scripts, and package scripts.
|
| 103 |
-
- Real-time stdout/stderr streaming with ANSI color support.
|
| 104 |
-
- Process-tree kill behavior for long-running child processes.
|
| 105 |
-
- R2 configuration, target suggestion, and upload workflow in-app.
|
| 106 |
-
|
| 107 |
-
## Security Snapshot
|
| 108 |
-
|
| 109 |
-
- Context isolation enabled.
|
| 110 |
-
- Node integration disabled in renderer.
|
| 111 |
-
- Narrow IPC bridge via preload APIs.
|
| 112 |
-
- External URL allowlist enforcement.
|
| 113 |
-
- Command allowlist enforcement before spawn.
|
| 114 |
-
- Request/navigation/popup restrictions in production mode.
|
| 115 |
-
- Audit logging with sensitive field redaction.
|
| 116 |
-
|
| 117 |
-
## NPM Commands (Repository Source)
|
| 118 |
-
|
| 119 |
-
Install dependencies:
|
| 120 |
-
|
| 121 |
-
```bash
|
| 122 |
-
npm install
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
Run locally:
|
| 126 |
-
|
| 127 |
-
```bash
|
| 128 |
-
npm run start
|
| 129 |
-
```
|
| 130 |
-
|
| 131 |
-
Development run:
|
| 132 |
-
|
| 133 |
-
```bash
|
| 134 |
-
npm run dev
|
| 135 |
-
```
|
| 136 |
-
|
| 137 |
-
Build commands:
|
| 138 |
-
|
| 139 |
-
```bash
|
| 140 |
-
npm run build
|
| 141 |
-
npm run build-win
|
| 142 |
-
npm run build-exe
|
| 143 |
-
npm run build-v8
|
| 144 |
-
npm run build-nsis
|
| 145 |
-
npm run build-msi
|
| 146 |
-
npm run build:linux
|
| 147 |
-
npm run build:linux:wsl
|
| 148 |
-
```
|
| 149 |
-
Run launcher command:
|
| 150 |
-
|
| 151 |
-
```bash
|
| 152 |
-
dev-launcher
|
| 153 |
-
```
|
| 154 |
-
|
| 155 |
-
## Home Content Expansion
|
| 156 |
-
|
| 157 |
-
The Home page currently presents this product definition:
|
| 158 |
-
|
| 159 |
-
- Open Source and Free Forever.
|
| 160 |
-
- Portable command runner for project-local workflows.
|
| 161 |
-
- Auto-detection from `package.json` with no manual project setup.
|
| 162 |
-
|
| 163 |
-
Home stat strip values:
|
| 164 |
-
|
| 165 |
-
- Project Types: 6
|
| 166 |
-
- Terminal Output Coverage: 100%
|
| 167 |
-
- Distribution Form: 1 portable executable
|
| 168 |
-
- Configuration Required: Zero for baseline command usage
|
| 169 |
-
|
| 170 |
-
## Home "What We Added" Details
|
| 171 |
-
|
| 172 |
-
- Workflow: project-local runner model, no browse/open project switching dependency.
|
| 173 |
-
- Security: stricter command allowlist and external URL host allowlist enforcement.
|
| 174 |
-
- R2 UX: single login/logout flow with operation gating.
|
| 175 |
-
- Build: V8 build path exposure and Linux WSL resilience improvements.
|
| 176 |
-
|
| 177 |
-
## Home Feature Cards (Detailed)
|
| 178 |
-
|
| 179 |
-
- Auto Project Detection
|
| 180 |
-
- Detects framework/runtime profile from dependency graph and scripts.
|
| 181 |
-
- One-Click Commands
|
| 182 |
-
- Grouped left-panel actions for Expo, Gradle, ADB, Electron, and NPM scripts.
|
| 183 |
-
- Full Terminal Output
|
| 184 |
-
- Streams command output in real time, including stderr, without hidden buffering loss.
|
| 185 |
-
- Portable Single EXE
|
| 186 |
-
- Designed for drop-in usage directly in target project folder.
|
| 187 |
-
- Command Group Generator
|
| 188 |
-
- Generates command sets from project type and script inventory.
|
| 189 |
-
- Process Tree Kill
|
| 190 |
-
- Terminates parent and child command processes to prevent orphan runners.
|
| 191 |
-
|
| 192 |
-
## Home Flow Section (Step-by-Step)
|
| 193 |
-
|
| 194 |
-
1. Place executable in the project root (next to `package.json`).
|
| 195 |
-
2. Launch app and allow automatic project detection.
|
| 196 |
-
3. Select and execute command from grouped command panel.
|
| 197 |
-
4. Monitor full output stream in the terminal pane.
|
| 198 |
-
|
| 199 |
-
## Home Compatibility Matrix (Expanded)
|
| 200 |
-
|
| 201 |
-
- Expo / React Native
|
| 202 |
-
- Typical commands: `expo start`, `expo run:android`, `expo prebuild`
|
| 203 |
-
- Android / Gradle
|
| 204 |
-
- Typical commands: `installDebug`, `assembleRelease`, `clean`
|
| 205 |
-
- Electron
|
| 206 |
-
- Typical commands: `npm run build`, `npm run build-win`, `npm run build-nsis`, `npm run dist`
|
| 207 |
-
- Next.js
|
| 208 |
-
- Typical commands: `npm run dev`, `npm run build`, `npm run start`, `npm run lint`
|
| 209 |
-
- Vite
|
| 210 |
-
- Typical commands: `npm run dev`, `npm run build`, `npm run preview`
|
| 211 |
-
- NPM Scripts
|
| 212 |
-
- Additional scripts surfaced automatically from project `package.json`
|
| 213 |
-
- ADB Utilities
|
| 214 |
-
- Typical commands: `adb devices`, `adb logcat`, `adb reverse tcp:8081 tcp:8081`
|
| 215 |
-
|
| 216 |
-
## Home Security Cards (Expanded)
|
| 217 |
-
|
| 218 |
-
- Context Isolation enabled for renderer boundary hardening.
|
| 219 |
-
- Node Integration disabled in renderer to reduce direct OS/runtime surface.
|
| 220 |
-
- Main-process-only sensitive logic for command construction and execution.
|
| 221 |
-
- Narrow preload bridge with explicit IPC methods.
|
| 222 |
-
- External access constrained by protocol and host policy.
|
| 223 |
-
- Strict shell policy and no inline handler dependency in host shell UI.
|
| 224 |
-
- Popup/navigation/request guard behavior in production.
|
| 225 |
-
- Controlled process spawn model with allowlist checks.
|
| 226 |
-
- Build-time credential hygiene for saved R2 config lifecycle.
|
| 227 |
-
|
| 228 |
-
## Notes For Teams
|
| 229 |
-
|
| 230 |
-
- Home page documentation should be treated as the UX-level contract.
|
| 231 |
-
- README is the implementation-facing mirror of that contract.
|
| 232 |
-
- When Home sections change, update this README section set to match.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- code-analysis
|
| 7 |
+
- static-analysis
|
| 8 |
+
- javascript
|
| 9 |
+
- electron
|
| 10 |
+
- emoji-cleaner
|
| 11 |
+
- junk-sweeper
|
| 12 |
+
- plugin-management
|
| 13 |
+
- desktop-app
|
| 14 |
+
- electron-app
|
| 15 |
+
- security
|
| 16 |
+
---
|
| 17 |
+
<div align="center">
|
| 18 |
+
<p align="center">
|
| 19 |
+
<img src="https://huggingface.co/datasets/chahuadev/chahuadev-png/resolve/main/chahuadev-dev-launcher.png" width="700" alt="Junk Sweeper — Main Dashboard">
|
| 20 |
+
</p>
|
| 21 |
+
|
| 22 |
+
<p align="center">
|
| 23 |
+
<a href="https://www.npmjs.com/package/@chahuadev/junk-sweeper-app"><img src="https://img.shields.io/npm/v/@chahuadev/dev-launcher?style=for-the-badge&color=blue" alt="NPM Version"></a>
|
| 24 |
+
<a href="https://www.npmjs.com/package/@chahuadev/dev-launcher"><img src="https://img.shields.io/npm/dt/@chahuadev/dev-launcher?style=for-the-badge&color=success" alt="NPM Downloads"></a>
|
| 25 |
+
<a href="https://huggingface.co/datasets/chahuadev/chahuadev-dev-launcher"><img src="https://img.shields.io/badge/%20HuggingFace-Dataset-yellow?style=for-the-badge" alt="HuggingFace Dataset"></a>
|
| 26 |
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Non--Commercial-blue?style=for-the-badge" alt="Non-Commercial License"></a>
|
| 27 |
+
<img src="https://img.shields.io/badge/Electron-40+-47848F?style=for-the-badge&logo=electron&logoColor=white" alt="Electron 40+">
|
| 28 |
+
<img src="https://img.shields.io/badge/Node.js-%E2%89%A522.0.0-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js 22">
|
| 29 |
+
<img src="https://img.shields.io/badge/Platform-Windows-0078D4?style=for-the-badge&logo=windows&logoColor=white" alt="Windows">
|
| 30 |
+
<img src="https://img.shields.io/badge/Analysis-Read--Only%20%E2%9C%93-blue?style=for-the-badge" alt="Read-Only Analysis">
|
| 31 |
+
<img src="https://img.shields.io/badge/Security-10--Layer%20Gateway-red?style=for-the-badge&logo=shield&logoColor=white" alt="7-Layer Security">
|
| 32 |
+
</p>
|
| 33 |
+
|
| 34 |
+
# Chahuadev Dev Launcher
|
| 35 |
+
|
| 36 |
+
Portable desktop command runner for development projects.
|
| 37 |
+
|
| 38 |
+
## Purpose
|
| 39 |
+
|
| 40 |
+
- Drop `dev-launcher.exe` inside a project folder.
|
| 41 |
+
- Auto-detect project type from `package.json`.
|
| 42 |
+
- Run grouped commands from one UI.
|
| 43 |
+
- Manage Cloudflare R2 upload flow for build artifacts.
|
| 44 |
+
|
| 45 |
+
## Repository layout
|
| 46 |
+
|
| 47 |
+
- `main.js`, `preload.js`, `index.html`, `web/`: Electron runtime + UI
|
| 48 |
+
- `build-desktop.bat`, `build-linux-wsl.sh`: local build scripts
|
| 49 |
+
- `dist/`: desktop build outputs
|
| 50 |
+
- `packages/`: npm publish package workspace
|
| 51 |
+
|
| 52 |
+
## NPM publish package
|
| 53 |
+
|
| 54 |
+
The npm-uploadable package lives in:
|
| 55 |
+
|
| 56 |
+
- `packages/@chahuadev/dev-launcher/`
|
| 57 |
+
|
| 58 |
+
This package is designed to:
|
| 59 |
+
|
| 60 |
+
1. Download platform binary at install time (`postinstall`)
|
| 61 |
+
2. Expose launcher CLI command (`dev-launcher`)
|
| 62 |
+
3. Run downloaded binary from `bin/`
|
| 63 |
+
|
| 64 |
+
See package docs here:
|
| 65 |
+
|
| 66 |
+
- `packages/README.md`
|
| 67 |
+
- `packages/@chahuadev/dev-launcher/README.md`
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## NPM Install Commands (Published Package)
|
| 71 |
+
|
| 72 |
+
Global install on Windows:
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
Global install on Linux:
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
sudo npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 82 |
+
```
|
| 83 |
+
## Home Overview (Detailed)
|
| 84 |
+
|
| 85 |
+
Dev Launcher focuses on a practical project-local flow:
|
| 86 |
+
|
| 87 |
+
- Place the launcher in a project root.
|
| 88 |
+
- Detect project type automatically from `package.json`.
|
| 89 |
+
- Render grouped commands in the left panel.
|
| 90 |
+
- Stream complete process output in the terminal panel.
|
| 91 |
+
|
| 92 |
+
Recent major additions reflected in Home:
|
| 93 |
+
|
| 94 |
+
- Simplified R2 flow with login/logout and gated actions.
|
| 95 |
+
- Safer command execution and external URL controls.
|
| 96 |
+
- Improved build support, including V8 command path and Linux WSL fallback.
|
| 97 |
+
- Better command output visibility with progress-oriented terminal messages.
|
| 98 |
+
|
| 99 |
+
## Features Snapshot
|
| 100 |
+
|
| 101 |
+
- Auto project detection for Expo, React Native, Electron, Next.js, Vite, and plain npm projects.
|
| 102 |
+
- One-click command groups for Metro, Gradle, ADB, Electron build scripts, and package scripts.
|
| 103 |
+
- Real-time stdout/stderr streaming with ANSI color support.
|
| 104 |
+
- Process-tree kill behavior for long-running child processes.
|
| 105 |
+
- R2 configuration, target suggestion, and upload workflow in-app.
|
| 106 |
+
|
| 107 |
+
## Security Snapshot
|
| 108 |
+
|
| 109 |
+
- Context isolation enabled.
|
| 110 |
+
- Node integration disabled in renderer.
|
| 111 |
+
- Narrow IPC bridge via preload APIs.
|
| 112 |
+
- External URL allowlist enforcement.
|
| 113 |
+
- Command allowlist enforcement before spawn.
|
| 114 |
+
- Request/navigation/popup restrictions in production mode.
|
| 115 |
+
- Audit logging with sensitive field redaction.
|
| 116 |
+
|
| 117 |
+
## NPM Commands (Repository Source)
|
| 118 |
+
|
| 119 |
+
Install dependencies:
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
npm install
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
Run locally:
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
npm run start
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Development run:
|
| 132 |
+
|
| 133 |
+
```bash
|
| 134 |
+
npm run dev
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
Build commands:
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
npm run build
|
| 141 |
+
npm run build-win
|
| 142 |
+
npm run build-exe
|
| 143 |
+
npm run build-v8
|
| 144 |
+
npm run build-nsis
|
| 145 |
+
npm run build-msi
|
| 146 |
+
npm run build:linux
|
| 147 |
+
npm run build:linux:wsl
|
| 148 |
+
```
|
| 149 |
+
Run launcher command:
|
| 150 |
+
|
| 151 |
+
```bash
|
| 152 |
+
dev-launcher
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
## Home Content Expansion
|
| 156 |
+
|
| 157 |
+
The Home page currently presents this product definition:
|
| 158 |
+
|
| 159 |
+
- Open Source and Free Forever.
|
| 160 |
+
- Portable command runner for project-local workflows.
|
| 161 |
+
- Auto-detection from `package.json` with no manual project setup.
|
| 162 |
+
|
| 163 |
+
Home stat strip values:
|
| 164 |
+
|
| 165 |
+
- Project Types: 6
|
| 166 |
+
- Terminal Output Coverage: 100%
|
| 167 |
+
- Distribution Form: 1 portable executable
|
| 168 |
+
- Configuration Required: Zero for baseline command usage
|
| 169 |
+
|
| 170 |
+
## Home "What We Added" Details
|
| 171 |
+
|
| 172 |
+
- Workflow: project-local runner model, no browse/open project switching dependency.
|
| 173 |
+
- Security: stricter command allowlist and external URL host allowlist enforcement.
|
| 174 |
+
- R2 UX: single login/logout flow with operation gating.
|
| 175 |
+
- Build: V8 build path exposure and Linux WSL resilience improvements.
|
| 176 |
+
|
| 177 |
+
## Home Feature Cards (Detailed)
|
| 178 |
+
|
| 179 |
+
- Auto Project Detection
|
| 180 |
+
- Detects framework/runtime profile from dependency graph and scripts.
|
| 181 |
+
- One-Click Commands
|
| 182 |
+
- Grouped left-panel actions for Expo, Gradle, ADB, Electron, and NPM scripts.
|
| 183 |
+
- Full Terminal Output
|
| 184 |
+
- Streams command output in real time, including stderr, without hidden buffering loss.
|
| 185 |
+
- Portable Single EXE
|
| 186 |
+
- Designed for drop-in usage directly in target project folder.
|
| 187 |
+
- Command Group Generator
|
| 188 |
+
- Generates command sets from project type and script inventory.
|
| 189 |
+
- Process Tree Kill
|
| 190 |
+
- Terminates parent and child command processes to prevent orphan runners.
|
| 191 |
+
|
| 192 |
+
## Home Flow Section (Step-by-Step)
|
| 193 |
+
|
| 194 |
+
1. Place executable in the project root (next to `package.json`).
|
| 195 |
+
2. Launch app and allow automatic project detection.
|
| 196 |
+
3. Select and execute command from grouped command panel.
|
| 197 |
+
4. Monitor full output stream in the terminal pane.
|
| 198 |
+
|
| 199 |
+
## Home Compatibility Matrix (Expanded)
|
| 200 |
+
|
| 201 |
+
- Expo / React Native
|
| 202 |
+
- Typical commands: `expo start`, `expo run:android`, `expo prebuild`
|
| 203 |
+
- Android / Gradle
|
| 204 |
+
- Typical commands: `installDebug`, `assembleRelease`, `clean`
|
| 205 |
+
- Electron
|
| 206 |
+
- Typical commands: `npm run build`, `npm run build-win`, `npm run build-nsis`, `npm run dist`
|
| 207 |
+
- Next.js
|
| 208 |
+
- Typical commands: `npm run dev`, `npm run build`, `npm run start`, `npm run lint`
|
| 209 |
+
- Vite
|
| 210 |
+
- Typical commands: `npm run dev`, `npm run build`, `npm run preview`
|
| 211 |
+
- NPM Scripts
|
| 212 |
+
- Additional scripts surfaced automatically from project `package.json`
|
| 213 |
+
- ADB Utilities
|
| 214 |
+
- Typical commands: `adb devices`, `adb logcat`, `adb reverse tcp:8081 tcp:8081`
|
| 215 |
+
|
| 216 |
+
## Home Security Cards (Expanded)
|
| 217 |
+
|
| 218 |
+
- Context Isolation enabled for renderer boundary hardening.
|
| 219 |
+
- Node Integration disabled in renderer to reduce direct OS/runtime surface.
|
| 220 |
+
- Main-process-only sensitive logic for command construction and execution.
|
| 221 |
+
- Narrow preload bridge with explicit IPC methods.
|
| 222 |
+
- External access constrained by protocol and host policy.
|
| 223 |
+
- Strict shell policy and no inline handler dependency in host shell UI.
|
| 224 |
+
- Popup/navigation/request guard behavior in production.
|
| 225 |
+
- Controlled process spawn model with allowlist checks.
|
| 226 |
+
- Build-time credential hygiene for saved R2 config lifecycle.
|
| 227 |
+
|
| 228 |
+
## Notes For Teams
|
| 229 |
+
|
| 230 |
+
- Home page documentation should be treated as the UX-level contract.
|
| 231 |
+
- README is the implementation-facing mirror of that contract.
|
| 232 |
+
- When Home sections change, update this README section set to match.
|
index.html
CHANGED
|
@@ -3,8 +3,9 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; frame-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'">
|
| 7 |
<title>Dev Launcher</title>
|
|
|
|
| 8 |
<link rel="stylesheet" href="./web/styles.css">
|
| 9 |
</head>
|
| 10 |
<body>
|
|
@@ -56,6 +57,13 @@
|
|
| 56 |
<div id="footer">
|
| 57 |
<button id="btn-kill" disabled>■ Kill</button>
|
| 58 |
<button id="btn-clear">Clear</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
<div id="status-dot"></div>
|
| 60 |
<span id="status-text">Idle</span>
|
| 61 |
<span id="running-label"></span>
|
|
@@ -142,6 +150,8 @@
|
|
| 142 |
</div>
|
| 143 |
</div>
|
| 144 |
|
|
|
|
|
|
|
| 145 |
<script src="./web/renderer.js"></script>
|
| 146 |
</body>
|
| 147 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; frame-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'">
|
| 7 |
<title>Dev Launcher</title>
|
| 8 |
+
<link rel="stylesheet" href="./node_modules/@xterm/xterm/css/xterm.css">
|
| 9 |
<link rel="stylesheet" href="./web/styles.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 57 |
<div id="footer">
|
| 58 |
<button id="btn-kill" disabled>■ Kill</button>
|
| 59 |
<button id="btn-clear">Clear</button>
|
| 60 |
+
<div id="stream-mode-wrap" title="Real-time = immediate chunks. Stable = small batching to reduce UI jitter.">
|
| 61 |
+
<label for="stream-mode">Stream</label>
|
| 62 |
+
<select id="stream-mode" aria-label="Output stream mode">
|
| 63 |
+
<option value="realtime" selected>Real-time</option>
|
| 64 |
+
<option value="stable">Stable</option>
|
| 65 |
+
</select>
|
| 66 |
+
</div>
|
| 67 |
<div id="status-dot"></div>
|
| 68 |
<span id="status-text">Idle</span>
|
| 69 |
<span id="running-label"></span>
|
|
|
|
| 150 |
</div>
|
| 151 |
</div>
|
| 152 |
|
| 153 |
+
<script src="./node_modules/@xterm/xterm/lib/xterm.js"></script>
|
| 154 |
+
<script src="./node_modules/@xterm/addon-fit/lib/addon-fit.js"></script>
|
| 155 |
<script src="./web/renderer.js"></script>
|
| 156 |
</body>
|
| 157 |
</html>
|
main.js
CHANGED
|
@@ -1,1066 +1,1122 @@
|
|
| 1 |
-
'use strict'
|
| 2 |
-
|
| 3 |
-
const { app, BrowserWindow, ipcMain, shell, dialog, safeStorage, session } = require('electron')
|
| 4 |
-
const path = require('path')
|
| 5 |
-
const fs = require('fs')
|
| 6 |
-
const { spawn, spawnSync } = require('child_process')
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
let
|
| 10 |
-
let
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
const
|
| 14 |
-
|
| 15 |
-
const
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
})
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
if (isDev)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
})
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
const
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
function
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
})
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
const
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
}
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
}
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
}
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
}
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
const
|
| 435 |
-
const
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
'
|
| 440 |
-
|
| 441 |
-
const
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
}
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
if (
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
const
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
{ label: prettyCmdLabel('npm', ['run',
|
| 641 |
-
|
| 642 |
-
}
|
| 643 |
-
}
|
| 644 |
-
|
| 645 |
-
// ──
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
})
|
| 656 |
-
}
|
| 657 |
-
|
| 658 |
-
// ──
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
const
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
}
|
| 689 |
-
}
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
const
|
| 699 |
-
const
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
const
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
}
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
let
|
| 742 |
-
let
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
const
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
})
|
| 886 |
-
|
| 887 |
-
ipcMain.handle('r2-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
}
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
return { ok:
|
| 912 |
-
}
|
| 913 |
-
}
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
return { ok: false, error:
|
| 922 |
-
}
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
const
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
}
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
| 1065 |
-
|
| 1066 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { app, BrowserWindow, ipcMain, shell, dialog, safeStorage, session, Menu } = require('electron')
|
| 4 |
+
const path = require('path')
|
| 5 |
+
const fs = require('fs')
|
| 6 |
+
const { spawn, spawnSync } = require('child_process')
|
| 7 |
+
const pty = require('node-pty')
|
| 8 |
+
|
| 9 |
+
let win = null
|
| 10 |
+
let splashWin = null
|
| 11 |
+
let currentProc = null
|
| 12 |
+
let currentProcKind = null
|
| 13 |
+
const secureConfigPath = path.join(app.getPath('userData'), 'secure-r2-config.json')
|
| 14 |
+
const auditLogPath = path.join(app.getPath('userData'), 'audit.log')
|
| 15 |
+
const isDev = !app.isPackaged
|
| 16 |
+
let requestGuardInstalled = false
|
| 17 |
+
const EXTERNAL_HOST_ALLOWLIST = new Set(['dash.cloudflare.com'])
|
| 18 |
+
|
| 19 |
+
// Project root: where the exe is placed (production) or this folder (dev)
|
| 20 |
+
// PORTABLE_EXECUTABLE_DIR = ตำแหน่งที่ user วาง .exe ไว้ (ไม่ใช่ Temp)
|
| 21 |
+
let projectRoot = app.isPackaged
|
| 22 |
+
? (process.env.PORTABLE_EXECUTABLE_DIR || path.dirname(process.execPath))
|
| 23 |
+
: __dirname
|
| 24 |
+
let selectedExternalProjectRoot = null
|
| 25 |
+
let selectedExternalProjectMode = null
|
| 26 |
+
|
| 27 |
+
function getEffectiveProjectRoot() {
|
| 28 |
+
return selectedExternalProjectRoot || projectRoot
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function isExternalDevOnlyModeForRoot(root) {
|
| 32 |
+
if (!selectedExternalProjectRoot) return false
|
| 33 |
+
if (selectedExternalProjectMode !== 'npm-run-dev-only') return false
|
| 34 |
+
return path.resolve(String(root || '')) === path.resolve(selectedExternalProjectRoot)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
function buildDevOnlyGroups(root) {
|
| 38 |
+
return [
|
| 39 |
+
{
|
| 40 |
+
label: 'Dev Mode', icon: 'npm', color: '#e84040',
|
| 41 |
+
cmds: [
|
| 42 |
+
{ label: prettyCmdLabel('npm', ['run', 'dev']), cmd: 'npm', args: ['run', 'dev'], cwd: root }
|
| 43 |
+
]
|
| 44 |
+
}
|
| 45 |
+
]
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function buildCommandGroupsForProject(pkg, root, hasAndroid) {
|
| 49 |
+
if (isExternalDevOnlyModeForRoot(root)) {
|
| 50 |
+
return buildDevOnlyGroups(root)
|
| 51 |
+
}
|
| 52 |
+
return buildGroups(pkg, root, hasAndroid)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function createSplashWindow() {
|
| 56 |
+
splashWin = new BrowserWindow({
|
| 57 |
+
width: 520,
|
| 58 |
+
height: 320,
|
| 59 |
+
frame: false,
|
| 60 |
+
resizable: false,
|
| 61 |
+
alwaysOnTop: true,
|
| 62 |
+
skipTaskbar: true,
|
| 63 |
+
center: true,
|
| 64 |
+
backgroundColor: '#09080f',
|
| 65 |
+
webPreferences: { nodeIntegration: false, contextIsolation: true }
|
| 66 |
+
})
|
| 67 |
+
splashWin.loadFile(path.join(__dirname, 'splash.html'))
|
| 68 |
+
splashWin.webContents.on('will-navigate', (e) => e.preventDefault())
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function createWindow() {
|
| 72 |
+
win = new BrowserWindow({
|
| 73 |
+
width: 960,
|
| 74 |
+
height: 660,
|
| 75 |
+
minWidth: 740,
|
| 76 |
+
minHeight: 520,
|
| 77 |
+
backgroundColor: '#0d0d1a',
|
| 78 |
+
icon: path.join(__dirname, 'icons', 'icon.png'),
|
| 79 |
+
webPreferences: {
|
| 80 |
+
preload: path.join(__dirname, 'preload.js'),
|
| 81 |
+
contextIsolation: true,
|
| 82 |
+
nodeIntegration: false,
|
| 83 |
+
sandbox: false,
|
| 84 |
+
devTools: isDev
|
| 85 |
+
},
|
| 86 |
+
title: 'Dev Launcher',
|
| 87 |
+
show: false
|
| 88 |
+
})
|
| 89 |
+
|
| 90 |
+
win.loadFile(path.join(__dirname, 'index.html'))
|
| 91 |
+
installAppMenu()
|
| 92 |
+
|
| 93 |
+
// Always deny renderer popups/navigation handoff.
|
| 94 |
+
win.webContents.setWindowOpenHandler(() => ({ action: 'deny' }))
|
| 95 |
+
win.webContents.on('will-navigate', (e, url) => {
|
| 96 |
+
const allowed = String(url || '').startsWith('file:')
|
| 97 |
+
if (!allowed) {
|
| 98 |
+
e.preventDefault()
|
| 99 |
+
writeAudit('blocked_navigation', { url: String(url || '') })
|
| 100 |
+
if (!isDev) {
|
| 101 |
+
dialog.showErrorBox('Security Blocked', 'Unauthorized external navigation attempt detected. The app will close.')
|
| 102 |
+
app.quit()
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
if (!isDev) {
|
| 108 |
+
// Block common DevTools shortcuts in production builds.
|
| 109 |
+
win.webContents.on('before-input-event', (event, input) => {
|
| 110 |
+
const key = String(input.key || '').toLowerCase()
|
| 111 |
+
const openDevTools =
|
| 112 |
+
key === 'f12' ||
|
| 113 |
+
((input.control || input.meta) && input.shift && (key === 'i' || key === 'j' || key === 'c'))
|
| 114 |
+
if (openDevTools) event.preventDefault()
|
| 115 |
+
})
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
win.once('ready-to-show', () => {
|
| 119 |
+
// Show main window and close splash after a short delay
|
| 120 |
+
setTimeout(() => {
|
| 121 |
+
if (splashWin && !splashWin.isDestroyed()) {
|
| 122 |
+
splashWin.close()
|
| 123 |
+
splashWin = null
|
| 124 |
+
}
|
| 125 |
+
win.show()
|
| 126 |
+
}, 1800)
|
| 127 |
+
})
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
async function chooseExternalProjectFolder(mode = 'full-project') {
|
| 131 |
+
const targetWin = win && !win.isDestroyed() ? win : null
|
| 132 |
+
const res = await dialog.showOpenDialog(targetWin, {
|
| 133 |
+
title: mode === 'npm-run-dev-only'
|
| 134 |
+
? 'Select Project Folder (npm run dev only)'
|
| 135 |
+
: 'Select Project Folder',
|
| 136 |
+
properties: ['openDirectory']
|
| 137 |
+
})
|
| 138 |
+
|
| 139 |
+
if (res.canceled || !res.filePaths || !res.filePaths[0]) return
|
| 140 |
+
|
| 141 |
+
const picked = path.resolve(res.filePaths[0])
|
| 142 |
+
const pkgPath = path.join(picked, 'package.json')
|
| 143 |
+
if (!fs.existsSync(pkgPath)) {
|
| 144 |
+
dialog.showErrorBox('Invalid Project', `No package.json found in:\n${picked}`)
|
| 145 |
+
return
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
selectedExternalProjectRoot = picked
|
| 149 |
+
selectedExternalProjectMode = mode === 'npm-run-dev-only' ? 'npm-run-dev-only' : 'full-project'
|
| 150 |
+
writeAudit('set_external_project_root', { root: picked, mode: selectedExternalProjectMode })
|
| 151 |
+
sendToRenderer('project-root-changed', {
|
| 152 |
+
root: getEffectiveProjectRoot(),
|
| 153 |
+
external: true,
|
| 154 |
+
mode: selectedExternalProjectMode
|
| 155 |
+
})
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
function useLauncherProjectRoot() {
|
| 159 |
+
selectedExternalProjectRoot = null
|
| 160 |
+
selectedExternalProjectMode = null
|
| 161 |
+
writeAudit('reset_project_root', { root: projectRoot })
|
| 162 |
+
sendToRenderer('project-root-changed', {
|
| 163 |
+
root: getEffectiveProjectRoot(),
|
| 164 |
+
external: false,
|
| 165 |
+
mode: 'default'
|
| 166 |
+
})
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function installAppMenu() {
|
| 170 |
+
const template = [
|
| 171 |
+
{
|
| 172 |
+
label: 'Dev',
|
| 173 |
+
submenu: [
|
| 174 |
+
{
|
| 175 |
+
label: 'Select External Project Folder...',
|
| 176 |
+
accelerator: 'Ctrl+Shift+O',
|
| 177 |
+
click: () => { chooseExternalProjectFolder('full-project').catch(() => {}) }
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
label: 'Select External Project Folder (npm run dev only)...',
|
| 181 |
+
accelerator: 'Ctrl+Shift+D',
|
| 182 |
+
click: () => { chooseExternalProjectFolder('npm-run-dev-only').catch(() => {}) }
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
label: 'Use Launcher Project',
|
| 186 |
+
accelerator: 'Ctrl+Shift+R',
|
| 187 |
+
click: () => useLauncherProjectRoot()
|
| 188 |
+
},
|
| 189 |
+
{ type: 'separator' },
|
| 190 |
+
{
|
| 191 |
+
label: 'Reload',
|
| 192 |
+
accelerator: 'Ctrl+R',
|
| 193 |
+
click: () => { if (win && !win.isDestroyed()) win.reload() }
|
| 194 |
+
}
|
| 195 |
+
]
|
| 196 |
+
}
|
| 197 |
+
]
|
| 198 |
+
const menu = Menu.buildFromTemplate(template)
|
| 199 |
+
Menu.setApplicationMenu(menu)
|
| 200 |
+
if (win && !win.isDestroyed()) win.setMenu(menu)
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
function installRequestGuard() {
|
| 204 |
+
if (requestGuardInstalled) return
|
| 205 |
+
requestGuardInstalled = true
|
| 206 |
+
|
| 207 |
+
const ses = session.defaultSession
|
| 208 |
+
if (!ses) return
|
| 209 |
+
|
| 210 |
+
// Deny all permission prompts by default (camera/mic/notifications/etc.).
|
| 211 |
+
ses.setPermissionRequestHandler((_, __, callback) => callback(false))
|
| 212 |
+
|
| 213 |
+
if (isDev) return
|
| 214 |
+
|
| 215 |
+
ses.webRequest.onBeforeRequest((details, callback) => {
|
| 216 |
+
const url = String(details.url || '')
|
| 217 |
+
const allowed =
|
| 218 |
+
url.startsWith('file:') ||
|
| 219 |
+
url.startsWith('data:') ||
|
| 220 |
+
url.startsWith('about:blank')
|
| 221 |
+
|
| 222 |
+
if (allowed) {
|
| 223 |
+
callback({ cancel: false })
|
| 224 |
+
return
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
callback({ cancel: true })
|
| 228 |
+
writeAudit('blocked_request', { url })
|
| 229 |
+
|
| 230 |
+
// External request from renderer context is considered a policy violation.
|
| 231 |
+
dialog.showErrorBox('Security Blocked', `Unauthorized external request detected:\n${url}\n\nThe app will close.`)
|
| 232 |
+
app.quit()
|
| 233 |
+
})
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
app.whenReady().then(() => {
|
| 237 |
+
installRequestGuard()
|
| 238 |
+
createSplashWindow()
|
| 239 |
+
createWindow()
|
| 240 |
+
})
|
| 241 |
+
|
| 242 |
+
app.on('window-all-closed', () => {
|
| 243 |
+
killCurrentProc()
|
| 244 |
+
app.quit()
|
| 245 |
+
})
|
| 246 |
+
|
| 247 |
+
function killCurrentProc() {
|
| 248 |
+
if (!currentProc) return
|
| 249 |
+
try {
|
| 250 |
+
if (currentProcKind === 'pty' && typeof currentProc.kill === 'function') {
|
| 251 |
+
currentProc.kill()
|
| 252 |
+
}
|
| 253 |
+
// Kill process tree on Windows
|
| 254 |
+
if (currentProc && currentProc.pid) {
|
| 255 |
+
spawn('taskkill', ['/pid', String(currentProc.pid), '/f', '/t'], { shell: false, windowsHide: true })
|
| 256 |
+
}
|
| 257 |
+
} catch {}
|
| 258 |
+
currentProc = null
|
| 259 |
+
currentProcKind = null
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
function sendToRenderer(channel, data) {
|
| 263 |
+
if (win && !win.isDestroyed()) {
|
| 264 |
+
win.webContents.send(channel, data)
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
function writeAudit(event, meta = {}) {
|
| 269 |
+
try {
|
| 270 |
+
const safeMeta = { ...meta }
|
| 271 |
+
delete safeMeta.accessKeyId
|
| 272 |
+
delete safeMeta.secretAccessKey
|
| 273 |
+
delete safeMeta.accountId
|
| 274 |
+
const line = `${new Date().toISOString()} ${event} ${JSON.stringify(safeMeta)}\n`
|
| 275 |
+
fs.appendFileSync(auditLogPath, line, 'utf8')
|
| 276 |
+
} catch {}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
function sanitizeExternalUrl(input) {
|
| 280 |
+
try {
|
| 281 |
+
const u = new URL(String(input || ''))
|
| 282 |
+
const host = String(u.hostname || '').toLowerCase()
|
| 283 |
+
const protocolOk = u.protocol === 'https:'
|
| 284 |
+
if (!protocolOk) return { ok: false, error: 'Only https URLs are allowed' }
|
| 285 |
+
if (!EXTERNAL_HOST_ALLOWLIST.has(host)) return { ok: false, error: `Host is not allowlisted: ${host}` }
|
| 286 |
+
return { ok: true, url: u.toString(), host }
|
| 287 |
+
} catch {
|
| 288 |
+
return { ok: false, error: 'Invalid URL' }
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
function normalizeExecName(cmd) {
|
| 293 |
+
let c = String(cmd || '').trim()
|
| 294 |
+
if (!c) return c
|
| 295 |
+
if (process.platform !== 'win32') return c
|
| 296 |
+
const lc = c.toLowerCase()
|
| 297 |
+
if (lc === 'npm') return 'npm.cmd'
|
| 298 |
+
if (lc === 'npx') return 'npx.cmd'
|
| 299 |
+
if (lc === 'pnpm') return 'pnpm.cmd'
|
| 300 |
+
if (lc === 'yarn') return 'yarn.cmd'
|
| 301 |
+
return c
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
function shouldUseShellForCommand(cmd) {
|
| 305 |
+
const c = String(cmd || '').toLowerCase()
|
| 306 |
+
return c.endsWith('.bat') || c.endsWith('.cmd')
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
function quoteWindowsArg(arg) {
|
| 310 |
+
const s = String(arg || '')
|
| 311 |
+
if (!s) return '""'
|
| 312 |
+
if (!/[\s"]/g.test(s)) return s
|
| 313 |
+
return `"${s.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/g, '$1$1')}"`
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
function buildWindowsCommandLine(cmd, args) {
|
| 317 |
+
return [cmd, ...(args || [])].map(quoteWindowsArg).join(' ')
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
function commandKey(cmd, args, cwd) {
|
| 321 |
+
const a = (args || []).map(x => String(x || '').trim())
|
| 322 |
+
const dir = path.resolve(String(cwd || projectRoot))
|
| 323 |
+
return `${String(cmd || '').trim().toLowerCase()}\u241f${a.join('\u241f').toLowerCase()}\u241f${dir.toLowerCase()}`
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
function buildAllowedCommandSet(root) {
|
| 327 |
+
try {
|
| 328 |
+
const pkgPath = path.join(root, 'package.json')
|
| 329 |
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
| 330 |
+
const hasAndroid = fs.existsSync(path.join(root, 'android', 'gradlew.bat'))
|
| 331 |
+
const groups = buildCommandGroupsForProject(pkg, root, hasAndroid)
|
| 332 |
+
const out = new Set()
|
| 333 |
+
for (const g of groups) {
|
| 334 |
+
for (const c of (g.cmds || [])) {
|
| 335 |
+
out.add(commandKey(c.cmd, c.args || [], c.cwd || root))
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
return out
|
| 339 |
+
} catch {
|
| 340 |
+
return new Set()
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
function deriveAppBase(pkgName) {
|
| 345 |
+
let slug = String(pkgName || 'app').toLowerCase()
|
| 346 |
+
slug = slug.replace(/^@/, '').replace('/', '-')
|
| 347 |
+
slug = slug.replace(/\s+/g, '-')
|
| 348 |
+
slug = slug.replace(/^chahuadev-/, '')
|
| 349 |
+
slug = slug.replace(/-(app|apk)$/i, '')
|
| 350 |
+
return slug || 'app'
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
function normalizeCredential(value) {
|
| 354 |
+
return String(value || '').replace(/[\r\n\t ]+/g, '').trim()
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
function friendlyAwsError(raw) {
|
| 358 |
+
const msg = String(raw || '').trim()
|
| 359 |
+
if (!msg) return 'Unknown AWS CLI error'
|
| 360 |
+
if (msg.includes('SignatureDoesNotMatch')) {
|
| 361 |
+
return 'SignatureDoesNotMatch: R2 credentials do not match this Account ID/Bucket. Check Account ID, Access Key, Secret Key.'
|
| 362 |
+
}
|
| 363 |
+
if (msg.includes('InvalidAccessKeyId')) {
|
| 364 |
+
return 'InvalidAccessKeyId: R2 access key is invalid.'
|
| 365 |
+
}
|
| 366 |
+
if (msg.includes('AccessDenied')) {
|
| 367 |
+
return 'AccessDenied: credentials are valid but do not have permission for this bucket/path.'
|
| 368 |
+
}
|
| 369 |
+
return msg
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function isEncryptionReady() {
|
| 373 |
+
try {
|
| 374 |
+
return !!safeStorage && safeStorage.isEncryptionAvailable()
|
| 375 |
+
} catch {
|
| 376 |
+
return false
|
| 377 |
+
}
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
function encryptValue(value) {
|
| 381 |
+
if (!isEncryptionReady()) {
|
| 382 |
+
throw new Error('OS encryption service is not available on this machine')
|
| 383 |
+
}
|
| 384 |
+
return safeStorage.encryptString(String(value)).toString('base64')
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
function decryptValue(value) {
|
| 388 |
+
if (!isEncryptionReady()) {
|
| 389 |
+
throw new Error('OS encryption service is not available on this machine')
|
| 390 |
+
}
|
| 391 |
+
return safeStorage.decryptString(Buffer.from(String(value), 'base64'))
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
function loadSecureConfigRaw() {
|
| 395 |
+
if (!fs.existsSync(secureConfigPath)) return null
|
| 396 |
+
return JSON.parse(fs.readFileSync(secureConfigPath, 'utf-8'))
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
function loadSecureR2Config() {
|
| 400 |
+
const raw = loadSecureConfigRaw()
|
| 401 |
+
if (!raw || !raw.r2) return null
|
| 402 |
+
return {
|
| 403 |
+
accountId: decryptValue(raw.r2.accountId),
|
| 404 |
+
bucket: decryptValue(raw.r2.bucket),
|
| 405 |
+
accessKeyId: decryptValue(raw.r2.accessKeyId),
|
| 406 |
+
secretAccessKey: decryptValue(raw.r2.secretAccessKey),
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
function saveSecureR2Config(cfg) {
|
| 411 |
+
const raw = loadSecureConfigRaw() || { version: 1 }
|
| 412 |
+
const payload = {
|
| 413 |
+
...raw,
|
| 414 |
+
version: 1,
|
| 415 |
+
updatedAt: new Date().toISOString(),
|
| 416 |
+
r2: {
|
| 417 |
+
accountId: encryptValue(cfg.accountId),
|
| 418 |
+
bucket: encryptValue(cfg.bucket),
|
| 419 |
+
accessKeyId: encryptValue(cfg.accessKeyId),
|
| 420 |
+
secretAccessKey: encryptValue(cfg.secretAccessKey),
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
fs.writeFileSync(secureConfigPath, JSON.stringify(payload, null, 2), 'utf-8')
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
function maskMiddle(value, left = 4, right = 4) {
|
| 427 |
+
const s = String(value || '')
|
| 428 |
+
if (!s) return ''
|
| 429 |
+
if (s.length <= left + right) return '*'.repeat(Math.max(6, s.length))
|
| 430 |
+
return `${s.slice(0, left)}${'*'.repeat(Math.max(6, s.length - (left + right)))}${s.slice(-right)}`
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
function listR2Folders(cfg) {
|
| 434 |
+
const endpoint = `https://${cfg.accountId}.r2.cloudflarestorage.com`
|
| 435 |
+
const env = {
|
| 436 |
+
...process.env,
|
| 437 |
+
AWS_ACCESS_KEY_ID: cfg.accessKeyId,
|
| 438 |
+
AWS_SECRET_ACCESS_KEY: cfg.secretAccessKey,
|
| 439 |
+
AWS_DEFAULT_REGION: 'auto'
|
| 440 |
+
}
|
| 441 |
+
const result = spawnSync(normalizeExecName('aws'), ['s3', 'ls', `s3://${cfg.bucket}/`, '--endpoint-url', endpoint], {
|
| 442 |
+
env,
|
| 443 |
+
shell: false,
|
| 444 |
+
windowsHide: true,
|
| 445 |
+
encoding: 'utf8'
|
| 446 |
+
})
|
| 447 |
+
|
| 448 |
+
if (result.error) {
|
| 449 |
+
throw new Error(`Unable to run AWS CLI: ${result.error.message}`)
|
| 450 |
+
}
|
| 451 |
+
if (result.status !== 0) {
|
| 452 |
+
const msg = friendlyAwsError(result.stderr || result.stdout || 'Unknown AWS CLI error')
|
| 453 |
+
throw new Error(`AWS CLI failed while listing bucket: ${msg}`)
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
const lines = (result.stdout || '').split(/\r?\n/)
|
| 457 |
+
const out = []
|
| 458 |
+
for (const line of lines) {
|
| 459 |
+
const m = line.match(/\bPRE\s+([^\s/]+)\/?/)
|
| 460 |
+
if (m && m[1]) out.push(m[1])
|
| 461 |
+
}
|
| 462 |
+
return out
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
function testR2Config(cfg) {
|
| 466 |
+
const endpoint = `https://${cfg.accountId}.r2.cloudflarestorage.com`
|
| 467 |
+
const env = {
|
| 468 |
+
...process.env,
|
| 469 |
+
AWS_ACCESS_KEY_ID: cfg.accessKeyId,
|
| 470 |
+
AWS_SECRET_ACCESS_KEY: cfg.secretAccessKey,
|
| 471 |
+
AWS_DEFAULT_REGION: 'auto'
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
const result = spawnSync(normalizeExecName('aws'), ['s3', 'ls', `s3://${cfg.bucket}/`, '--endpoint-url', endpoint], {
|
| 475 |
+
env,
|
| 476 |
+
shell: false,
|
| 477 |
+
windowsHide: true,
|
| 478 |
+
encoding: 'utf8'
|
| 479 |
+
})
|
| 480 |
+
|
| 481 |
+
if (result.error) {
|
| 482 |
+
return { ok: false, error: `Unable to run AWS CLI: ${result.error.message}` }
|
| 483 |
+
}
|
| 484 |
+
if (result.status !== 0) {
|
| 485 |
+
return { ok: false, error: friendlyAwsError(result.stderr || result.stdout || 'Unknown AWS CLI error') }
|
| 486 |
+
}
|
| 487 |
+
return { ok: true }
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
function chooseR2Target(folders, appBase) {
|
| 491 |
+
if (!folders.length) return appBase
|
| 492 |
+
const exact = folders.find(f => f.toLowerCase() === appBase.toLowerCase())
|
| 493 |
+
if (exact) return exact
|
| 494 |
+
const contains = folders.find(f => f.toLowerCase().includes(appBase.toLowerCase()))
|
| 495 |
+
if (contains) return contains
|
| 496 |
+
return appBase
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
function clearSecureR2Config() {
|
| 500 |
+
try {
|
| 501 |
+
if (fs.existsSync(secureConfigPath)) fs.unlinkSync(secureConfigPath)
|
| 502 |
+
return { ok: true }
|
| 503 |
+
} catch (e) {
|
| 504 |
+
return { ok: false, error: e.message }
|
| 505 |
+
}
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
function listR2UploadCandidates(distPath) {
|
| 509 |
+
const exts = new Set(['.exe', '.msi', '.appimage'])
|
| 510 |
+
const out = []
|
| 511 |
+
const stack = [distPath]
|
| 512 |
+
|
| 513 |
+
while (stack.length > 0) {
|
| 514 |
+
const dir = stack.pop()
|
| 515 |
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
| 516 |
+
for (const entry of entries) {
|
| 517 |
+
const abs = path.join(dir, entry.name)
|
| 518 |
+
if (entry.isDirectory()) {
|
| 519 |
+
stack.push(abs)
|
| 520 |
+
continue
|
| 521 |
+
}
|
| 522 |
+
if (!entry.isFile()) continue
|
| 523 |
+
|
| 524 |
+
const ext = path.extname(entry.name).toLowerCase()
|
| 525 |
+
if (!exts.has(ext)) continue
|
| 526 |
+
|
| 527 |
+
const rel = path.relative(distPath, abs).replace(/\\/g, '/')
|
| 528 |
+
out.push({ abs, rel })
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
out.sort((a, b) => a.rel.localeCompare(b.rel))
|
| 533 |
+
return out
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
function prettyCmdLabel(cmd, args) {
|
| 537 |
+
const c = String(cmd || '').trim()
|
| 538 |
+
const a = (args || []).map(x => String(x || '').trim()).filter(Boolean)
|
| 539 |
+
if (!c) return ''
|
| 540 |
+
return [c, ...a].join(' ')
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// ── Project type detection (Node side — not exposed to renderer) ──────────────
|
| 544 |
+
function detectType(pkg) {
|
| 545 |
+
const d = { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies }
|
| 546 |
+
const has = (name) => !!d[name]
|
| 547 |
+
|
| 548 |
+
const kinds = []
|
| 549 |
+
if (has('electron')) kinds.push('Electron')
|
| 550 |
+
if (has('expo')) kinds.push('Expo')
|
| 551 |
+
if (has('react-native')) kinds.push('React Native')
|
| 552 |
+
if (has('next')) kinds.push('Next.js')
|
| 553 |
+
if (has('vite')) kinds.push('Vite')
|
| 554 |
+
if (has('@angular/core')) kinds.push('Angular')
|
| 555 |
+
if (has('nuxt') || has('nuxt3')) kinds.push('Nuxt')
|
| 556 |
+
if (has('svelte') || has('@sveltejs/kit')) kinds.push('Svelte')
|
| 557 |
+
if (has('astro')) kinds.push('Astro')
|
| 558 |
+
if (has('remix') || has('@remix-run/node')) kinds.push('Remix')
|
| 559 |
+
if (has('gatsby')) kinds.push('Gatsby')
|
| 560 |
+
if (has('vue')) kinds.push('Vue')
|
| 561 |
+
if (has('react')) kinds.push('React')
|
| 562 |
+
if (has('nestjs') || has('@nestjs/core')) kinds.push('NestJS')
|
| 563 |
+
if (has('express')) kinds.push('Express')
|
| 564 |
+
if (has('fastify')) kinds.push('Fastify')
|
| 565 |
+
if (has('koa')) kinds.push('Koa')
|
| 566 |
+
|
| 567 |
+
const primaryType =
|
| 568 |
+
has('electron') ? 'electron' :
|
| 569 |
+
has('expo') ? 'expo' :
|
| 570 |
+
has('react-native') ? 'rn' :
|
| 571 |
+
has('next') ? 'nextjs' :
|
| 572 |
+
has('vite') ? 'vite' :
|
| 573 |
+
'npm'
|
| 574 |
+
|
| 575 |
+
const badgeClass =
|
| 576 |
+
primaryType === 'expo' ? 'badge-expo' :
|
| 577 |
+
primaryType === 'rn' ? 'badge-rn' :
|
| 578 |
+
primaryType === 'electron' ? 'badge-electron' :
|
| 579 |
+
primaryType === 'nextjs' ? 'badge-nextjs' :
|
| 580 |
+
primaryType === 'vite' ? 'badge-vite' :
|
| 581 |
+
'badge-npm'
|
| 582 |
+
|
| 583 |
+
const withNode = kinds.includes('Node.js') ? kinds : [...kinds, 'Node.js']
|
| 584 |
+
const label = withNode.length ? withNode.join(' + ') : 'Node.js'
|
| 585 |
+
return { type: primaryType, label, badgeClass }
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
function buildGroups(pkg, root, hasAndroid) {
|
| 589 |
+
const d = { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies }
|
| 590 |
+
const has = (name) => !!d[name]
|
| 591 |
+
const isExpoLike = has('expo') || has('react-native')
|
| 592 |
+
const isElectron = has('electron')
|
| 593 |
+
const isNext = has('next')
|
| 594 |
+
const isVite = has('vite')
|
| 595 |
+
const androidPath = path.join(root, 'android')
|
| 596 |
+
const groups = []
|
| 597 |
+
|
| 598 |
+
// ── Expo / RN ────────────────────────────────────────────────────────────────
|
| 599 |
+
if (isExpoLike) {
|
| 600 |
+
groups.push({
|
| 601 |
+
label: 'Expo / Metro', icon: 'expo', color: '#7c6cf6',
|
| 602 |
+
cmds: [
|
| 603 |
+
{ label: 'expo start', cmd: 'npx', args: ['expo', 'start'], cwd: root },
|
| 604 |
+
{ label: 'expo run:android', cmd: 'npx', args: ['expo', 'run:android'], cwd: root },
|
| 605 |
+
{ label: 'expo prebuild', cmd: 'npx', args: ['expo', 'prebuild', '--platform', 'android'], cwd: root },
|
| 606 |
+
]
|
| 607 |
+
})
|
| 608 |
+
if (hasAndroid) {
|
| 609 |
+
groups.push({
|
| 610 |
+
label: 'Android / Gradle', icon: 'android', color: '#3ddc84',
|
| 611 |
+
cmds: [
|
| 612 |
+
{ label: 'installDebug ▶', cmd: 'gradlew.bat', args: ['app:installDebug', '--daemon', '--console=rich'], cwd: androidPath },
|
| 613 |
+
{ label: 'installRelease', cmd: 'gradlew.bat', args: ['app:installRelease', '--daemon', '--console=rich'], cwd: androidPath },
|
| 614 |
+
{ label: 'assembleDebug', cmd: 'gradlew.bat', args: ['app:assembleDebug', '--daemon', '--console=rich'], cwd: androidPath },
|
| 615 |
+
{ label: 'assembleRelease', cmd: 'gradlew.bat', args: ['app:assembleRelease','--daemon', '--console=rich'], cwd: androidPath },
|
| 616 |
+
{ label: 'clean', cmd: 'gradlew.bat', args: ['clean', '--console=rich'], cwd: androidPath },
|
| 617 |
+
{ label: 'clean + install', cmd: 'gradlew.bat', args: ['clean','app:installDebug','--daemon', '--console=rich'], cwd: androidPath },
|
| 618 |
+
]
|
| 619 |
+
})
|
| 620 |
+
groups.push({
|
| 621 |
+
label: 'ADB', icon: 'adb', color: '#f39c12',
|
| 622 |
+
cmds: [
|
| 623 |
+
{ label: 'adb devices', cmd: 'adb', args: ['devices'], cwd: root },
|
| 624 |
+
{ label: 'adb logcat', cmd: 'adb', args: ['logcat'], cwd: root },
|
| 625 |
+
{ label: 'adb reverse', cmd: 'adb', args: ['reverse','tcp:8081','tcp:8081'], cwd: root },
|
| 626 |
+
]
|
| 627 |
+
})
|
| 628 |
+
}
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
// ── Electron ─────────────────────────────────────────────────────────────────
|
| 632 |
+
const usedScripts = new Set()
|
| 633 |
+
if (isElectron) {
|
| 634 |
+
const buildKeys = ['build','build-win','build-exe','build-v8','build-nsis','build-msi','build:linux','build:linux:wsl','pack','dist']
|
| 635 |
+
const foundKeys = buildKeys.filter(s => (pkg.scripts || {})[s])
|
| 636 |
+
foundKeys.forEach(s => usedScripts.add(s))
|
| 637 |
+
if (foundKeys.length) {
|
| 638 |
+
groups.push({
|
| 639 |
+
label: 'Electron Build', icon: 'electron', color: '#47c4e2',
|
| 640 |
+
cmds: foundKeys.map(s => ({ label: prettyCmdLabel('npm', ['run', s]), cmd: 'npm', args: ['run', s], cwd: root }))
|
| 641 |
+
})
|
| 642 |
+
}
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
// ── Next.js ──────────────────────────────────────────────────────────────────
|
| 646 |
+
if (isNext) {
|
| 647 |
+
groups.push({
|
| 648 |
+
label: 'Next.js', icon: 'nextjs', color: '#ffffff',
|
| 649 |
+
cmds: [
|
| 650 |
+
{ label: prettyCmdLabel('npm', ['run','dev']), cmd: 'npm', args: ['run','dev'], cwd: root },
|
| 651 |
+
{ label: prettyCmdLabel('npm', ['run','build']), cmd: 'npm', args: ['run','build'], cwd: root },
|
| 652 |
+
{ label: prettyCmdLabel('npm', ['run','start']), cmd: 'npm', args: ['run','start'], cwd: root },
|
| 653 |
+
{ label: prettyCmdLabel('npm', ['run','lint']), cmd: 'npm', args: ['run','lint'], cwd: root },
|
| 654 |
+
]
|
| 655 |
+
})
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
// ── Vite ─────────────────────────────────────────────────────────────────────
|
| 659 |
+
if (isVite) {
|
| 660 |
+
groups.push({
|
| 661 |
+
label: 'Vite', icon: 'vite', color: '#bd34fe',
|
| 662 |
+
cmds: [
|
| 663 |
+
{ label: prettyCmdLabel('npm', ['run','dev']), cmd: 'npm', args: ['run','dev'], cwd: root },
|
| 664 |
+
{ label: prettyCmdLabel('npm', ['run','build']), cmd: 'npm', args: ['run','build'], cwd: root },
|
| 665 |
+
{ label: prettyCmdLabel('npm', ['run','preview']), cmd: 'npm', args: ['run','preview'], cwd: root },
|
| 666 |
+
]
|
| 667 |
+
})
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
// ── NPM Scripts (auto from package.json) ──────────────────────────────────────
|
| 671 |
+
const scripts = pkg.scripts || {}
|
| 672 |
+
const skipPrefixes = ['pre', 'post']
|
| 673 |
+
const scriptEntries = Object.keys(scripts).filter(s =>
|
| 674 |
+
!skipPrefixes.some(p => s.startsWith(p)) && !usedScripts.has(s)
|
| 675 |
+
)
|
| 676 |
+
if (scriptEntries.length) {
|
| 677 |
+
groups.push({
|
| 678 |
+
label: 'NPM Scripts', icon: 'scripts', color: '#f7c948',
|
| 679 |
+
cmds: scriptEntries.map(s => ({ label: prettyCmdLabel('npm', ['run', s]), cmd: 'npm', args: ['run', s], cwd: root }))
|
| 680 |
+
})
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
// ── Always: npm install ───────────────────────────────────────────────────────
|
| 684 |
+
groups.push({
|
| 685 |
+
label: 'NPM', icon: 'npm', color: '#e84040',
|
| 686 |
+
cmds: [
|
| 687 |
+
{ label: 'npm install', cmd: 'npm', args: ['install'], cwd: root },
|
| 688 |
+
{ label: 'npm install --legacy-peer-deps', cmd: 'npm', args: ['install','--legacy-peer-deps'], cwd: root },
|
| 689 |
+
{ label: 'npm ci', cmd: 'npm', args: ['ci'], cwd: root },
|
| 690 |
+
]
|
| 691 |
+
})
|
| 692 |
+
|
| 693 |
+
return groups
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
// ── IPC: get project info (returns processed data only — no raw pkg exposed) ──
|
| 697 |
+
ipcMain.handle('get-project', () => {
|
| 698 |
+
const root = getEffectiveProjectRoot()
|
| 699 |
+
const pkgPath = path.join(root, 'package.json')
|
| 700 |
+
try {
|
| 701 |
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
| 702 |
+
const hasAndroid = fs.existsSync(path.join(root, 'android', 'gradlew.bat'))
|
| 703 |
+
const typeInfo = isExternalDevOnlyModeForRoot(root)
|
| 704 |
+
? { type: 'npm-dev-only', label: 'NPM Dev Mode', badgeClass: 'badge-npm' }
|
| 705 |
+
: detectType(pkg)
|
| 706 |
+
const groups = buildCommandGroupsForProject(pkg, root, hasAndroid)
|
| 707 |
+
return {
|
| 708 |
+
ok: true,
|
| 709 |
+
projectRoot: root,
|
| 710 |
+
projectName: pkg.name || null,
|
| 711 |
+
typeInfo, // { type, label, badgeClass }
|
| 712 |
+
groups, // ready-to-render — no raw pkg sent to renderer
|
| 713 |
+
}
|
| 714 |
+
} catch (e) {
|
| 715 |
+
return { ok: false, error: e.message, projectRoot: root }
|
| 716 |
+
}
|
| 717 |
+
})
|
| 718 |
+
|
| 719 |
+
// ── IPC: run a command ────────────────────────────────────────────────────────
|
| 720 |
+
ipcMain.handle('run-cmd', (event, { cmd, args, cwd, streamMode, cols, rows }) => {
|
| 721 |
+
killCurrentProc()
|
| 722 |
+
|
| 723 |
+
const normalizedCmd = normalizeExecName(cmd)
|
| 724 |
+
const normalizedArgs = (args || []).map(x => String(x || ''))
|
| 725 |
+
const effectiveRoot = getEffectiveProjectRoot()
|
| 726 |
+
const normalizedCwd = path.resolve(String(cwd || effectiveRoot))
|
| 727 |
+
const allowed = buildAllowedCommandSet(effectiveRoot)
|
| 728 |
+
const directKey = commandKey(cmd, normalizedArgs, normalizedCwd)
|
| 729 |
+
const normalizedKey = commandKey(normalizedCmd, normalizedArgs, normalizedCwd)
|
| 730 |
+
if (!allowed.has(directKey) && !allowed.has(normalizedKey)) {
|
| 731 |
+
const msg = `Command is not allowlisted: ${String(cmd || '')} ${(normalizedArgs || []).join(' ')}`
|
| 732 |
+
writeAudit('blocked_command', { cmd: String(cmd || ''), args: normalizedArgs, cwd: normalizedCwd })
|
| 733 |
+
sendToRenderer('proc-out', `\n[ERROR] ${msg}\n`)
|
| 734 |
+
sendToRenderer('proc-done', 1)
|
| 735 |
+
return { ok: false, error: msg }
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
const useShell = shouldUseShellForCommand(normalizedCmd)
|
| 739 |
+
writeAudit('run_command', { cmd: normalizedCmd, args: normalizedArgs, cwd: normalizedCwd, shell: useShell })
|
| 740 |
+
|
| 741 |
+
let ptyFile = normalizedCmd
|
| 742 |
+
let ptyArgs = normalizedArgs
|
| 743 |
+
if (process.platform === 'win32' && useShell) {
|
| 744 |
+
const comspec = process.env.COMSPEC || 'cmd.exe'
|
| 745 |
+
ptyFile = comspec
|
| 746 |
+
ptyArgs = ['/d', '/s', '/c', buildWindowsCommandLine(normalizedCmd, normalizedArgs)]
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
let proc
|
| 750 |
+
const ptyCols = Number.isFinite(Number(cols)) ? Math.max(20, Math.floor(Number(cols))) : 120
|
| 751 |
+
const ptyRows = Number.isFinite(Number(rows)) ? Math.max(5, Math.floor(Number(rows))) : 30
|
| 752 |
+
const procEnv = {
|
| 753 |
+
...process.env,
|
| 754 |
+
FORCE_COLOR: '1',
|
| 755 |
+
CLICOLOR: '1',
|
| 756 |
+
CLICOLOR_FORCE: '1',
|
| 757 |
+
COLORTERM: 'truecolor',
|
| 758 |
+
TERM: 'xterm-256color',
|
| 759 |
+
npm_config_color: 'always',
|
| 760 |
+
}
|
| 761 |
+
try {
|
| 762 |
+
proc = pty.spawn(ptyFile, ptyArgs, {
|
| 763 |
+
cwd: normalizedCwd,
|
| 764 |
+
env: procEnv,
|
| 765 |
+
cols: ptyCols,
|
| 766 |
+
rows: ptyRows,
|
| 767 |
+
name: 'xterm-256color',
|
| 768 |
+
useConpty: true
|
| 769 |
+
})
|
| 770 |
+
} catch (err) {
|
| 771 |
+
const message = err && err.message ? err.message : String(err || 'Unknown PTY error')
|
| 772 |
+
sendToRenderer('proc-out', `\n[ERROR] Failed to start PTY: ${message}\n`)
|
| 773 |
+
sendToRenderer('proc-done', 1)
|
| 774 |
+
writeAudit('run_command_error', { cmd: normalizedCmd, cwd: normalizedCwd, error: message })
|
| 775 |
+
return { ok: false, error: message }
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
currentProc = proc
|
| 779 |
+
currentProcKind = 'pty'
|
| 780 |
+
|
| 781 |
+
const normalizedStreamMode = String(streamMode || 'realtime').toLowerCase() === 'stable'
|
| 782 |
+
? 'stable'
|
| 783 |
+
: 'realtime'
|
| 784 |
+
const stableFlushMs = 30
|
| 785 |
+
|
| 786 |
+
function streamOutput(chunk) {
|
| 787 |
+
const text = Buffer.isBuffer(chunk) ? chunk.toString('utf8') : String(chunk || '')
|
| 788 |
+
if (!text) return
|
| 789 |
+
sendToRenderer('proc-out', text)
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
let outputBuffer = ''
|
| 793 |
+
let flushTimer = null
|
| 794 |
+
|
| 795 |
+
function flushBufferedOutput() {
|
| 796 |
+
if (outputBuffer.length > 0) {
|
| 797 |
+
sendToRenderer('proc-out', outputBuffer)
|
| 798 |
+
outputBuffer = ''
|
| 799 |
+
}
|
| 800 |
+
flushTimer = null
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
function queueStableOutput(chunk) {
|
| 804 |
+
const text = Buffer.isBuffer(chunk) ? chunk.toString('utf8') : String(chunk || '')
|
| 805 |
+
if (!text) return
|
| 806 |
+
outputBuffer += text
|
| 807 |
+
if (!flushTimer) {
|
| 808 |
+
flushTimer = setTimeout(flushBufferedOutput, stableFlushMs)
|
| 809 |
+
}
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
proc.onData(normalizedStreamMode === 'stable' ? queueStableOutput : streamOutput)
|
| 813 |
+
|
| 814 |
+
proc.onExit(({ exitCode }) => {
|
| 815 |
+
if (flushTimer) {
|
| 816 |
+
clearTimeout(flushTimer)
|
| 817 |
+
flushTimer = null
|
| 818 |
+
}
|
| 819 |
+
if (normalizedStreamMode === 'stable') {
|
| 820 |
+
flushBufferedOutput()
|
| 821 |
+
}
|
| 822 |
+
currentProc = null
|
| 823 |
+
currentProcKind = null
|
| 824 |
+
writeAudit('run_command_done', { cmd: normalizedCmd, cwd: normalizedCwd, code: exitCode, streamMode: normalizedStreamMode })
|
| 825 |
+
setImmediate(() => sendToRenderer('proc-done', exitCode ?? 0))
|
| 826 |
+
})
|
| 827 |
+
|
| 828 |
+
return { ok: true, pid: proc.pid }
|
| 829 |
+
})
|
| 830 |
+
|
| 831 |
+
// ── IPC: kill current process ─────────────────────────────────────────────────
|
| 832 |
+
ipcMain.handle('kill-proc', () => {
|
| 833 |
+
if (!currentProc) return false
|
| 834 |
+
killCurrentProc()
|
| 835 |
+
sendToRenderer('proc-done', -1)
|
| 836 |
+
return true
|
| 837 |
+
})
|
| 838 |
+
|
| 839 |
+
ipcMain.handle('resize-proc-pty', (_, size) => {
|
| 840 |
+
if (!currentProc || currentProcKind !== 'pty' || typeof currentProc.resize !== 'function') {
|
| 841 |
+
return false
|
| 842 |
+
}
|
| 843 |
+
const cols = Number(size && size.cols)
|
| 844 |
+
const rows = Number(size && size.rows)
|
| 845 |
+
if (!Number.isFinite(cols) || !Number.isFinite(rows)) return false
|
| 846 |
+
|
| 847 |
+
const safeCols = Math.max(20, Math.floor(cols))
|
| 848 |
+
const safeRows = Math.max(5, Math.floor(rows))
|
| 849 |
+
try {
|
| 850 |
+
currentProc.resize(safeCols, safeRows)
|
| 851 |
+
return true
|
| 852 |
+
} catch {
|
| 853 |
+
return false
|
| 854 |
+
}
|
| 855 |
+
})
|
| 856 |
+
|
| 857 |
+
ipcMain.handle('open-external', (_, url) => {
|
| 858 |
+
const checked = sanitizeExternalUrl(url)
|
| 859 |
+
if (!checked.ok) {
|
| 860 |
+
writeAudit('blocked_open_external', { reason: checked.error, requested: String(url || '') })
|
| 861 |
+
return false
|
| 862 |
+
}
|
| 863 |
+
writeAudit('open_external', { host: checked.host })
|
| 864 |
+
shell.openExternal(checked.url)
|
| 865 |
+
return true
|
| 866 |
+
})
|
| 867 |
+
|
| 868 |
+
ipcMain.handle('r2-get-config-status', () => {
|
| 869 |
+
if (!isEncryptionReady()) {
|
| 870 |
+
return { ok: false, error: 'OS encryption is unavailable' }
|
| 871 |
+
}
|
| 872 |
+
try {
|
| 873 |
+
const cfg = loadSecureR2Config()
|
| 874 |
+
if (!cfg) return { ok: true, hasConfig: false }
|
| 875 |
+
return {
|
| 876 |
+
ok: true,
|
| 877 |
+
hasConfig: true,
|
| 878 |
+
accountIdMasked: maskMiddle(cfg.accountId, 4, 4),
|
| 879 |
+
bucket: cfg.bucket,
|
| 880 |
+
accessKeyMasked: maskMiddle(cfg.accessKeyId, 4, 4),
|
| 881 |
+
}
|
| 882 |
+
} catch (e) {
|
| 883 |
+
return { ok: false, error: e.message }
|
| 884 |
+
}
|
| 885 |
+
})
|
| 886 |
+
|
| 887 |
+
ipcMain.handle('r2-save-config', (_, cfg) => {
|
| 888 |
+
if (!isEncryptionReady()) {
|
| 889 |
+
return { ok: false, error: 'OS encryption is unavailable' }
|
| 890 |
+
}
|
| 891 |
+
const required = ['accountId', 'bucket', 'accessKeyId', 'secretAccessKey']
|
| 892 |
+
for (const k of required) {
|
| 893 |
+
if (!cfg || !String(cfg[k] || '').trim()) {
|
| 894 |
+
return { ok: false, error: `Missing ${k}` }
|
| 895 |
+
}
|
| 896 |
+
}
|
| 897 |
+
try {
|
| 898 |
+
const normalized = {
|
| 899 |
+
accountId: normalizeCredential(cfg.accountId),
|
| 900 |
+
bucket: normalizeCredential(cfg.bucket),
|
| 901 |
+
accessKeyId: normalizeCredential(cfg.accessKeyId),
|
| 902 |
+
secretAccessKey: normalizeCredential(cfg.secretAccessKey),
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
saveSecureR2Config({
|
| 906 |
+
accountId: normalized.accountId,
|
| 907 |
+
bucket: normalized.bucket,
|
| 908 |
+
accessKeyId: normalized.accessKeyId,
|
| 909 |
+
secretAccessKey: normalized.secretAccessKey,
|
| 910 |
+
})
|
| 911 |
+
return { ok: true }
|
| 912 |
+
} catch (e) {
|
| 913 |
+
return { ok: false, error: e.message }
|
| 914 |
+
}
|
| 915 |
+
})
|
| 916 |
+
|
| 917 |
+
ipcMain.handle('r2-test-config', (_, cfg) => {
|
| 918 |
+
const required = ['accountId', 'bucket', 'accessKeyId', 'secretAccessKey']
|
| 919 |
+
for (const k of required) {
|
| 920 |
+
if (!cfg || !String(cfg[k] || '').trim()) {
|
| 921 |
+
return { ok: false, error: `Missing ${k}` }
|
| 922 |
+
}
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
const normalized = {
|
| 926 |
+
accountId: normalizeCredential(cfg.accountId),
|
| 927 |
+
bucket: normalizeCredential(cfg.bucket),
|
| 928 |
+
accessKeyId: normalizeCredential(cfg.accessKeyId),
|
| 929 |
+
secretAccessKey: normalizeCredential(cfg.secretAccessKey),
|
| 930 |
+
}
|
| 931 |
+
return testR2Config(normalized)
|
| 932 |
+
})
|
| 933 |
+
|
| 934 |
+
ipcMain.handle('r2-clear-config', () => {
|
| 935 |
+
try {
|
| 936 |
+
if (fs.existsSync(secureConfigPath)) {
|
| 937 |
+
fs.unlinkSync(secureConfigPath)
|
| 938 |
+
}
|
| 939 |
+
writeAudit('r2_logout', { projectRoot })
|
| 940 |
+
return { ok: true }
|
| 941 |
+
} catch (e) {
|
| 942 |
+
return { ok: false, error: e.message }
|
| 943 |
+
}
|
| 944 |
+
})
|
| 945 |
+
|
| 946 |
+
ipcMain.handle('r2-suggest-target', () => {
|
| 947 |
+
try {
|
| 948 |
+
const cfg = loadSecureR2Config()
|
| 949 |
+
if (!cfg) return { ok: false, error: 'R2 is not configured yet' }
|
| 950 |
+
|
| 951 |
+
const root = getEffectiveProjectRoot()
|
| 952 |
+
const pkgPath = path.join(root, 'package.json')
|
| 953 |
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
| 954 |
+
const appBase = deriveAppBase(pkg.name)
|
| 955 |
+
const folders = listR2Folders(cfg)
|
| 956 |
+
const target = chooseR2Target(folders, appBase)
|
| 957 |
+
return { ok: true, target, appBase, folders, bucket: cfg.bucket }
|
| 958 |
+
} catch (e) {
|
| 959 |
+
return { ok: false, error: e.message }
|
| 960 |
+
}
|
| 961 |
+
})
|
| 962 |
+
|
| 963 |
+
ipcMain.handle('r2-upload-dist', (_, { target }) => {
|
| 964 |
+
try {
|
| 965 |
+
const root = getEffectiveProjectRoot()
|
| 966 |
+
const cfg = loadSecureR2Config()
|
| 967 |
+
if (!cfg) {
|
| 968 |
+
sendToRenderer('proc-out', '\n[ERROR] R2 is not configured yet\n')
|
| 969 |
+
sendToRenderer('proc-done', 1)
|
| 970 |
+
return { ok: false, error: 'R2 is not configured yet' }
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
const distPath = path.join(root, 'dist')
|
| 974 |
+
if (!fs.existsSync(distPath)) {
|
| 975 |
+
sendToRenderer('proc-out', '\n[ERROR] dist folder not found. Build first.\n')
|
| 976 |
+
sendToRenderer('proc-done', 1)
|
| 977 |
+
return { ok: false, error: 'dist folder not found' }
|
| 978 |
+
}
|
| 979 |
+
|
| 980 |
+
const pkgPath = path.join(root, 'package.json')
|
| 981 |
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
| 982 |
+
const appBase = deriveAppBase(pkg.name)
|
| 983 |
+
const targetFolder = String(target || appBase).trim() || appBase
|
| 984 |
+
|
| 985 |
+
killCurrentProc()
|
| 986 |
+
|
| 987 |
+
const endpoint = `https://${cfg.accountId}.r2.cloudflarestorage.com`
|
| 988 |
+
const candidates = listR2UploadCandidates(distPath)
|
| 989 |
+
const totalCandidates = candidates.length
|
| 990 |
+
|
| 991 |
+
if (totalCandidates === 0) {
|
| 992 |
+
sendToRenderer('proc-out', '\n[ERROR] No uploadable files found in dist (.exe, .msi, .AppImage)\n')
|
| 993 |
+
sendToRenderer('proc-done', 1)
|
| 994 |
+
return { ok: false, error: 'No uploadable files found in dist' }
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
const args = [
|
| 998 |
+
's3', 'sync', 'dist', `s3://${cfg.bucket}/${targetFolder}/`,
|
| 999 |
+
'--endpoint-url', endpoint,
|
| 1000 |
+
'--exclude', '*',
|
| 1001 |
+
'--include', '*.exe',
|
| 1002 |
+
'--include', '*.msi',
|
| 1003 |
+
'--include', '*.AppImage',
|
| 1004 |
+
'--exclude', 'win-unpacked/*',
|
| 1005 |
+
'--exclude', 'linux-unpacked/*',
|
| 1006 |
+
'--exclude', 'mac/*',
|
| 1007 |
+
'--exclude', '__pycache__/*'
|
| 1008 |
+
]
|
| 1009 |
+
|
| 1010 |
+
const proc = spawn(normalizeExecName('aws'), args, {
|
| 1011 |
+
cwd: root,
|
| 1012 |
+
shell: false,
|
| 1013 |
+
windowsHide: true,
|
| 1014 |
+
env: {
|
| 1015 |
+
...process.env,
|
| 1016 |
+
AWS_ACCESS_KEY_ID: cfg.accessKeyId,
|
| 1017 |
+
AWS_SECRET_ACCESS_KEY: cfg.secretAccessKey,
|
| 1018 |
+
AWS_DEFAULT_REGION: 'auto'
|
| 1019 |
+
}
|
| 1020 |
+
})
|
| 1021 |
+
|
| 1022 |
+
currentProc = proc
|
| 1023 |
+
currentProcKind = 'spawn'
|
| 1024 |
+
proc.stdout.setEncoding('utf8')
|
| 1025 |
+
proc.stderr.setEncoding('utf8')
|
| 1026 |
+
|
| 1027 |
+
sendToRenderer('proc-out', `\n[INFO] Uploading to s3://${cfg.bucket}/${targetFolder}/\n`)
|
| 1028 |
+
sendToRenderer('proc-out', `[INFO] Found ${totalCandidates} file(s):\n`)
|
| 1029 |
+
const preview = candidates.slice(0, 12)
|
| 1030 |
+
for (const f of preview) {
|
| 1031 |
+
sendToRenderer('proc-out', ` - ${f.rel}\n`)
|
| 1032 |
+
}
|
| 1033 |
+
if (totalCandidates > preview.length) {
|
| 1034 |
+
sendToRenderer('proc-out', ` ... and ${totalCandidates - preview.length} more\n`)
|
| 1035 |
+
}
|
| 1036 |
+
sendToRenderer('proc-out', '[INFO] Upload progress: 0%\n')
|
| 1037 |
+
writeAudit('r2_upload_start', { bucket: cfg.bucket, target: targetFolder, projectRoot: root, totalCandidates })
|
| 1038 |
+
|
| 1039 |
+
let uploadedCount = 0
|
| 1040 |
+
const uploadedSet = new Set()
|
| 1041 |
+
let stdoutBuffer = ''
|
| 1042 |
+
let stderrBuffer = ''
|
| 1043 |
+
|
| 1044 |
+
function reportProgressLine(line) {
|
| 1045 |
+
const m = line.match(/upload:\s+(.+?)\s+to\s+s3:\/\//i)
|
| 1046 |
+
if (!m || !m[1]) return false
|
| 1047 |
+
|
| 1048 |
+
const rawPath = String(m[1]).trim().replace(/\\/g, '/')
|
| 1049 |
+
const rel = rawPath.replace(/^dist\//i, '')
|
| 1050 |
+
if (uploadedSet.has(rel)) return true
|
| 1051 |
+
|
| 1052 |
+
uploadedSet.add(rel)
|
| 1053 |
+
uploadedCount += 1
|
| 1054 |
+
|
| 1055 |
+
const pct = Math.max(0, Math.min(100, Math.round((uploadedCount / totalCandidates) * 100)))
|
| 1056 |
+
sendToRenderer('proc-out', `[INFO] [R2 ${uploadedCount}/${totalCandidates} ${pct}%] Uploaded: ${rel}\n`)
|
| 1057 |
+
return true
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
function flushChunk(bufferRef, chunk) {
|
| 1061 |
+
const combined = bufferRef.value + String(chunk || '')
|
| 1062 |
+
const parts = combined.split(/\r?\n/)
|
| 1063 |
+
bufferRef.value = parts.pop() || ''
|
| 1064 |
+
for (const line of parts) {
|
| 1065 |
+
if (!line) continue
|
| 1066 |
+
if (reportProgressLine(line)) continue
|
| 1067 |
+
sendToRenderer('proc-out', `${line}\n`)
|
| 1068 |
+
}
|
| 1069 |
+
}
|
| 1070 |
+
|
| 1071 |
+
proc.stdout.on('data', (d) => flushChunk({ get value() { return stdoutBuffer }, set value(v) { stdoutBuffer = v } }, d))
|
| 1072 |
+
proc.stderr.on('data', (d) => flushChunk({ get value() { return stderrBuffer }, set value(v) { stderrBuffer = v } }, d))
|
| 1073 |
+
|
| 1074 |
+
let closeCode = null
|
| 1075 |
+
let stdoutDone = false
|
| 1076 |
+
let stderrDone = false
|
| 1077 |
+
|
| 1078 |
+
function tryFinish() {
|
| 1079 |
+
if (closeCode !== null && stdoutDone && stderrDone) {
|
| 1080 |
+
if (stdoutBuffer.trim()) {
|
| 1081 |
+
if (!reportProgressLine(stdoutBuffer.trim())) sendToRenderer('proc-out', `${stdoutBuffer.trim()}\n`)
|
| 1082 |
+
stdoutBuffer = ''
|
| 1083 |
+
}
|
| 1084 |
+
if (stderrBuffer.trim()) {
|
| 1085 |
+
if (!reportProgressLine(stderrBuffer.trim())) sendToRenderer('proc-out', `${stderrBuffer.trim()}\n`)
|
| 1086 |
+
stderrBuffer = ''
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
if (closeCode === 0) {
|
| 1090 |
+
const pct = Math.max(0, Math.min(100, Math.round((uploadedCount / totalCandidates) * 100)))
|
| 1091 |
+
sendToRenderer('proc-out', `[INFO] R2 upload completed: uploaded ${uploadedCount}/${totalCandidates} file(s) (${pct}%).\n`)
|
| 1092 |
+
if (uploadedCount < totalCandidates) {
|
| 1093 |
+
sendToRenderer('proc-out', '[INFO] Some files may already be up-to-date on R2 and were skipped by sync.\n')
|
| 1094 |
+
}
|
| 1095 |
+
}
|
| 1096 |
+
|
| 1097 |
+
currentProc = null
|
| 1098 |
+
currentProcKind = null
|
| 1099 |
+
writeAudit('r2_upload_done', { bucket: cfg.bucket, target: targetFolder, code: closeCode, uploadedCount, totalCandidates })
|
| 1100 |
+
setImmediate(() => sendToRenderer('proc-done', closeCode))
|
| 1101 |
+
}
|
| 1102 |
+
}
|
| 1103 |
+
|
| 1104 |
+
proc.stdout.on('end', () => { stdoutDone = true; tryFinish() })
|
| 1105 |
+
proc.stderr.on('end', () => { stderrDone = true; tryFinish() })
|
| 1106 |
+
proc.on('close', (code) => { closeCode = code ?? 0; tryFinish() })
|
| 1107 |
+
proc.on('error', (err) => {
|
| 1108 |
+
sendToRenderer('proc-out', `\n[ERROR] ${err.message}\n`)
|
| 1109 |
+
sendToRenderer('proc-done', 1)
|
| 1110 |
+
writeAudit('r2_upload_error', { message: err.message, bucket: cfg.bucket, target: targetFolder })
|
| 1111 |
+
currentProc = null
|
| 1112 |
+
currentProcKind = null
|
| 1113 |
+
})
|
| 1114 |
+
|
| 1115 |
+
return { ok: true, target: targetFolder, bucket: cfg.bucket, pid: proc.pid }
|
| 1116 |
+
} catch (e) {
|
| 1117 |
+
sendToRenderer('proc-out', `\n[ERROR] ${e.message}\n`)
|
| 1118 |
+
sendToRenderer('proc-done', 1)
|
| 1119 |
+
return { ok: false, error: e.message }
|
| 1120 |
+
}
|
| 1121 |
+
})
|
| 1122 |
+
|
package-lock.json
CHANGED
|
@@ -8,7 +8,10 @@
|
|
| 8 |
"name": "@chahuadev/dev-launcher",
|
| 9 |
"version": "1.0.0",
|
| 10 |
"dependencies": {
|
| 11 |
-
"
|
|
|
|
|
|
|
|
|
|
| 12 |
},
|
| 13 |
"devDependencies": {
|
| 14 |
"electron": "^41.0.3",
|
|
@@ -970,6 +973,21 @@
|
|
| 970 |
"node": ">=10.0.0"
|
| 971 |
}
|
| 972 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 973 |
"node_modules/7zip-bin": {
|
| 974 |
"version": "5.2.0",
|
| 975 |
"resolved": "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.2.0.tgz",
|
|
@@ -4578,6 +4596,22 @@
|
|
| 4578 |
"node": ">=10"
|
| 4579 |
}
|
| 4580 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4581 |
"node_modules/nopt": {
|
| 4582 |
"version": "8.1.0",
|
| 4583 |
"resolved": "https://registry.npmjs.org/nopt/-/nopt-8.1.0.tgz",
|
|
|
|
| 8 |
"name": "@chahuadev/dev-launcher",
|
| 9 |
"version": "1.0.0",
|
| 10 |
"dependencies": {
|
| 11 |
+
"@xterm/addon-fit": "^0.11.0",
|
| 12 |
+
"@xterm/xterm": "^6.0.0",
|
| 13 |
+
"bytenode": "^1.5.7",
|
| 14 |
+
"node-pty": "^1.1.0"
|
| 15 |
},
|
| 16 |
"devDependencies": {
|
| 17 |
"electron": "^41.0.3",
|
|
|
|
| 973 |
"node": ">=10.0.0"
|
| 974 |
}
|
| 975 |
},
|
| 976 |
+
"node_modules/@xterm/addon-fit": {
|
| 977 |
+
"version": "0.11.0",
|
| 978 |
+
"resolved": "https://registry.npmjs.org/@xterm/addon-fit/-/addon-fit-0.11.0.tgz",
|
| 979 |
+
"integrity": "sha512-jYcgT6xtVYhnhgxh3QgYDnnNMYTcf8ElbxxFzX0IZo+vabQqSPAjC3c1wJrKB5E19VwQei89QCiZZP86DCPF7g==",
|
| 980 |
+
"license": "MIT"
|
| 981 |
+
},
|
| 982 |
+
"node_modules/@xterm/xterm": {
|
| 983 |
+
"version": "6.0.0",
|
| 984 |
+
"resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-6.0.0.tgz",
|
| 985 |
+
"integrity": "sha512-TQwDdQGtwwDt+2cgKDLn0IRaSxYu1tSUjgKarSDkUM0ZNiSRXFpjxEsvc/Zgc5kq5omJ+V0a8/kIM2WD3sMOYg==",
|
| 986 |
+
"license": "MIT",
|
| 987 |
+
"workspaces": [
|
| 988 |
+
"addons/*"
|
| 989 |
+
]
|
| 990 |
+
},
|
| 991 |
"node_modules/7zip-bin": {
|
| 992 |
"version": "5.2.0",
|
| 993 |
"resolved": "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.2.0.tgz",
|
|
|
|
| 4596 |
"node": ">=10"
|
| 4597 |
}
|
| 4598 |
},
|
| 4599 |
+
"node_modules/node-pty": {
|
| 4600 |
+
"version": "1.1.0",
|
| 4601 |
+
"resolved": "https://registry.npmjs.org/node-pty/-/node-pty-1.1.0.tgz",
|
| 4602 |
+
"integrity": "sha512-20JqtutY6JPXTUnL0ij1uad7Qe1baT46lyolh2sSENDd4sTzKZ4nmAFkeAARDKwmlLjPx6XKRlwRUxwjOy+lUg==",
|
| 4603 |
+
"hasInstallScript": true,
|
| 4604 |
+
"license": "MIT",
|
| 4605 |
+
"dependencies": {
|
| 4606 |
+
"node-addon-api": "^7.1.0"
|
| 4607 |
+
}
|
| 4608 |
+
},
|
| 4609 |
+
"node_modules/node-pty/node_modules/node-addon-api": {
|
| 4610 |
+
"version": "7.1.1",
|
| 4611 |
+
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz",
|
| 4612 |
+
"integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==",
|
| 4613 |
+
"license": "MIT"
|
| 4614 |
+
},
|
| 4615 |
"node_modules/nopt": {
|
| 4616 |
"version": "8.1.0",
|
| 4617 |
"resolved": "https://registry.npmjs.org/nopt/-/nopt-8.1.0.tgz",
|
package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
"build": "electron-builder --win",
|
| 11 |
"build-win": "electron-builder --win",
|
| 12 |
"build-exe": "electron-builder --win portable --x64",
|
| 13 |
-
"build-v8": "
|
| 14 |
"build-nsis": "electron-builder --win nsis --x64",
|
| 15 |
"build-msi": "electron-builder --win msi --x64",
|
| 16 |
"build:linux": "electron-builder --linux AppImage --x64 --publish never",
|
|
@@ -22,16 +22,17 @@
|
|
| 22 |
"javascript-obfuscator": "^5.3.0"
|
| 23 |
},
|
| 24 |
"build": {
|
| 25 |
-
"beforePack": "scripts/before-pack-obfuscate.js",
|
| 26 |
"appId": "com.chahuadev.devlauncher",
|
| 27 |
"productName": "Dev Launcher",
|
| 28 |
"icon": "icons/icon.png",
|
|
|
|
| 29 |
"directories": {
|
| 30 |
"output": "dist"
|
| 31 |
},
|
| 32 |
"files": [
|
| 33 |
"main.js",
|
| 34 |
"preload.js",
|
|
|
|
| 35 |
"index.html",
|
| 36 |
"splash.html",
|
| 37 |
"build-linux-wsl.sh",
|
|
@@ -58,13 +59,17 @@
|
|
| 58 |
"linux": {
|
| 59 |
"target": [
|
| 60 |
"AppImage"
|
| 61 |
-
]
|
|
|
|
| 62 |
},
|
| 63 |
"portable": {
|
| 64 |
"requestExecutionLevel": "user"
|
| 65 |
}
|
| 66 |
},
|
| 67 |
"dependencies": {
|
| 68 |
-
"
|
|
|
|
|
|
|
|
|
|
| 69 |
}
|
| 70 |
}
|
|
|
|
| 10 |
"build": "electron-builder --win",
|
| 11 |
"build-win": "electron-builder --win",
|
| 12 |
"build-exe": "electron-builder --win portable --x64",
|
| 13 |
+
"build-v8": "node scripts/build-v8-bytecode.js",
|
| 14 |
"build-nsis": "electron-builder --win nsis --x64",
|
| 15 |
"build-msi": "electron-builder --win msi --x64",
|
| 16 |
"build:linux": "electron-builder --linux AppImage --x64 --publish never",
|
|
|
|
| 22 |
"javascript-obfuscator": "^5.3.0"
|
| 23 |
},
|
| 24 |
"build": {
|
|
|
|
| 25 |
"appId": "com.chahuadev.devlauncher",
|
| 26 |
"productName": "Dev Launcher",
|
| 27 |
"icon": "icons/icon.png",
|
| 28 |
+
"npmRebuild": false,
|
| 29 |
"directories": {
|
| 30 |
"output": "dist"
|
| 31 |
},
|
| 32 |
"files": [
|
| 33 |
"main.js",
|
| 34 |
"preload.js",
|
| 35 |
+
"*.jsc",
|
| 36 |
"index.html",
|
| 37 |
"splash.html",
|
| 38 |
"build-linux-wsl.sh",
|
|
|
|
| 59 |
"linux": {
|
| 60 |
"target": [
|
| 61 |
"AppImage"
|
| 62 |
+
],
|
| 63 |
+
"artifactName": "dev-launcher.AppImage"
|
| 64 |
},
|
| 65 |
"portable": {
|
| 66 |
"requestExecutionLevel": "user"
|
| 67 |
}
|
| 68 |
},
|
| 69 |
"dependencies": {
|
| 70 |
+
"@xterm/addon-fit": "^0.11.0",
|
| 71 |
+
"@xterm/xterm": "^6.0.0",
|
| 72 |
+
"bytenode": "^1.5.7",
|
| 73 |
+
"node-pty": "^1.1.0"
|
| 74 |
}
|
| 75 |
}
|
packages/@chahuadev/dev-launcher/README.md
CHANGED
|
@@ -1,44 +1,232 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
```bash
|
| 10 |
npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 11 |
```
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
```bash
|
| 16 |
sudo npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 17 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
```bash
|
| 22 |
-
|
| 23 |
```
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
## Configure download source
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
```bash
|
| 36 |
-
|
| 37 |
```
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
```bash
|
| 42 |
-
|
| 43 |
-
npm publish --access public
|
| 44 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- code-analysis
|
| 7 |
+
- static-analysis
|
| 8 |
+
- javascript
|
| 9 |
+
- electron
|
| 10 |
+
- emoji-cleaner
|
| 11 |
+
- junk-sweeper
|
| 12 |
+
- plugin-management
|
| 13 |
+
- desktop-app
|
| 14 |
+
- electron-app
|
| 15 |
+
- security
|
| 16 |
+
---
|
| 17 |
+
<div align="center">
|
| 18 |
+
<p align="center">
|
| 19 |
+
<img src="https://huggingface.co/datasets/chahuadev/chahuadev-png/resolve/main/chahuadev-dev-launcher.png" width="700" alt="Junk Sweeper — Main Dashboard">
|
| 20 |
+
</p>
|
| 21 |
|
| 22 |
+
<p align="center">
|
| 23 |
+
<a href="https://www.npmjs.com/package/@chahuadev/junk-sweeper-app"><img src="https://img.shields.io/npm/v/@chahuadev/dev-launcher?style=for-the-badge&color=blue" alt="NPM Version"></a>
|
| 24 |
+
<a href="https://www.npmjs.com/package/@chahuadev/dev-launcher"><img src="https://img.shields.io/npm/dt/@chahuadev/dev-launcher?style=for-the-badge&color=success" alt="NPM Downloads"></a>
|
| 25 |
+
<a href="https://huggingface.co/datasets/chahuadev/chahuadev-dev-launcher"><img src="https://img.shields.io/badge/%20HuggingFace-Dataset-yellow?style=for-the-badge" alt="HuggingFace Dataset"></a>
|
| 26 |
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Non--Commercial-blue?style=for-the-badge" alt="Non-Commercial License"></a>
|
| 27 |
+
<img src="https://img.shields.io/badge/Electron-40+-47848F?style=for-the-badge&logo=electron&logoColor=white" alt="Electron 40+">
|
| 28 |
+
<img src="https://img.shields.io/badge/Node.js-%E2%89%A522.0.0-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js 22">
|
| 29 |
+
<img src="https://img.shields.io/badge/Platform-Windows-0078D4?style=for-the-badge&logo=windows&logoColor=white" alt="Windows">
|
| 30 |
+
<img src="https://img.shields.io/badge/Analysis-Read--Only%20%E2%9C%93-blue?style=for-the-badge" alt="Read-Only Analysis">
|
| 31 |
+
<img src="https://img.shields.io/badge/Security-10--Layer%20Gateway-red?style=for-the-badge&logo=shield&logoColor=white" alt="7-Layer Security">
|
| 32 |
+
</p>
|
| 33 |
|
| 34 |
+
# Chahuadev Dev Launcher
|
| 35 |
|
| 36 |
+
Portable desktop command runner for development projects.
|
| 37 |
+
|
| 38 |
+
## Purpose
|
| 39 |
+
|
| 40 |
+
- Drop `dev-launcher.exe` inside a project folder.
|
| 41 |
+
- Auto-detect project type from `package.json`.
|
| 42 |
+
- Run grouped commands from one UI.
|
| 43 |
+
- Manage Cloudflare R2 upload flow for build artifacts.
|
| 44 |
+
|
| 45 |
+
## Repository layout
|
| 46 |
+
|
| 47 |
+
- `main.js`, `preload.js`, `index.html`, `web/`: Electron runtime + UI
|
| 48 |
+
- `build-desktop.bat`, `build-linux-wsl.sh`: local build scripts
|
| 49 |
+
- `dist/`: desktop build outputs
|
| 50 |
+
- `packages/`: npm publish package workspace
|
| 51 |
+
|
| 52 |
+
## NPM publish package
|
| 53 |
+
|
| 54 |
+
The npm-uploadable package lives in:
|
| 55 |
+
|
| 56 |
+
- `packages/@chahuadev/dev-launcher/`
|
| 57 |
+
|
| 58 |
+
This package is designed to:
|
| 59 |
+
|
| 60 |
+
1. Download platform binary at install time (`postinstall`)
|
| 61 |
+
2. Expose launcher CLI command (`dev-launcher`)
|
| 62 |
+
3. Run downloaded binary from `bin/`
|
| 63 |
+
|
| 64 |
+
See package docs here:
|
| 65 |
+
|
| 66 |
+
- `packages/README.md`
|
| 67 |
+
- `packages/@chahuadev/dev-launcher/README.md`
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## NPM Install Commands (Published Package)
|
| 71 |
+
|
| 72 |
+
Global install on Windows:
|
| 73 |
|
| 74 |
```bash
|
| 75 |
npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 76 |
```
|
| 77 |
|
| 78 |
+
Global install on Linux:
|
| 79 |
|
| 80 |
```bash
|
| 81 |
sudo npm install -g @chahuadev/dev-launcher --foreground-scripts --force
|
| 82 |
```
|
| 83 |
+
## Home Overview (Detailed)
|
| 84 |
+
|
| 85 |
+
Dev Launcher focuses on a practical project-local flow:
|
| 86 |
+
|
| 87 |
+
- Place the launcher in a project root.
|
| 88 |
+
- Detect project type automatically from `package.json`.
|
| 89 |
+
- Render grouped commands in the left panel.
|
| 90 |
+
- Stream complete process output in the terminal panel.
|
| 91 |
+
|
| 92 |
+
Recent major additions reflected in Home:
|
| 93 |
+
|
| 94 |
+
- Simplified R2 flow with login/logout and gated actions.
|
| 95 |
+
- Safer command execution and external URL controls.
|
| 96 |
+
- Improved build support, including V8 command path and Linux WSL fallback.
|
| 97 |
+
- Better command output visibility with progress-oriented terminal messages.
|
| 98 |
|
| 99 |
+
## Features Snapshot
|
| 100 |
+
|
| 101 |
+
- Auto project detection for Expo, React Native, Electron, Next.js, Vite, and plain npm projects.
|
| 102 |
+
- One-click command groups for Metro, Gradle, ADB, Electron build scripts, and package scripts.
|
| 103 |
+
- Real-time stdout/stderr streaming with ANSI color support.
|
| 104 |
+
- Process-tree kill behavior for long-running child processes.
|
| 105 |
+
- R2 configuration, target suggestion, and upload workflow in-app.
|
| 106 |
+
|
| 107 |
+
## Security Snapshot
|
| 108 |
+
|
| 109 |
+
- Context isolation enabled.
|
| 110 |
+
- Node integration disabled in renderer.
|
| 111 |
+
- Narrow IPC bridge via preload APIs.
|
| 112 |
+
- External URL allowlist enforcement.
|
| 113 |
+
- Command allowlist enforcement before spawn.
|
| 114 |
+
- Request/navigation/popup restrictions in production mode.
|
| 115 |
+
- Audit logging with sensitive field redaction.
|
| 116 |
+
|
| 117 |
+
## NPM Commands (Repository Source)
|
| 118 |
+
|
| 119 |
+
Install dependencies:
|
| 120 |
|
| 121 |
```bash
|
| 122 |
+
npm install
|
| 123 |
```
|
| 124 |
|
| 125 |
+
Run locally:
|
| 126 |
|
| 127 |
+
```bash
|
| 128 |
+
npm run start
|
| 129 |
+
```
|
|
|
|
|
|
|
| 130 |
|
| 131 |
+
Development run:
|
| 132 |
|
| 133 |
```bash
|
| 134 |
+
npm run dev
|
| 135 |
```
|
| 136 |
|
| 137 |
+
Build commands:
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
npm run build
|
| 141 |
+
npm run build-win
|
| 142 |
+
npm run build-exe
|
| 143 |
+
npm run build-v8
|
| 144 |
+
npm run build-nsis
|
| 145 |
+
npm run build-msi
|
| 146 |
+
npm run build:linux
|
| 147 |
+
npm run build:linux:wsl
|
| 148 |
+
```
|
| 149 |
+
Run launcher command:
|
| 150 |
|
| 151 |
```bash
|
| 152 |
+
dev-launcher
|
|
|
|
| 153 |
```
|
| 154 |
+
|
| 155 |
+
## Home Content Expansion
|
| 156 |
+
|
| 157 |
+
The Home page currently presents this product definition:
|
| 158 |
+
|
| 159 |
+
- Open Source and Free Forever.
|
| 160 |
+
- Portable command runner for project-local workflows.
|
| 161 |
+
- Auto-detection from `package.json` with no manual project setup.
|
| 162 |
+
|
| 163 |
+
Home stat strip values:
|
| 164 |
+
|
| 165 |
+
- Project Types: 6
|
| 166 |
+
- Terminal Output Coverage: 100%
|
| 167 |
+
- Distribution Form: 1 portable executable
|
| 168 |
+
- Configuration Required: Zero for baseline command usage
|
| 169 |
+
|
| 170 |
+
## Home "What We Added" Details
|
| 171 |
+
|
| 172 |
+
- Workflow: project-local runner model, no browse/open project switching dependency.
|
| 173 |
+
- Security: stricter command allowlist and external URL host allowlist enforcement.
|
| 174 |
+
- R2 UX: single login/logout flow with operation gating.
|
| 175 |
+
- Build: V8 build path exposure and Linux WSL resilience improvements.
|
| 176 |
+
|
| 177 |
+
## Home Feature Cards (Detailed)
|
| 178 |
+
|
| 179 |
+
- Auto Project Detection
|
| 180 |
+
- Detects framework/runtime profile from dependency graph and scripts.
|
| 181 |
+
- One-Click Commands
|
| 182 |
+
- Grouped left-panel actions for Expo, Gradle, ADB, Electron, and NPM scripts.
|
| 183 |
+
- Full Terminal Output
|
| 184 |
+
- Streams command output in real time, including stderr, without hidden buffering loss.
|
| 185 |
+
- Portable Single EXE
|
| 186 |
+
- Designed for drop-in usage directly in target project folder.
|
| 187 |
+
- Command Group Generator
|
| 188 |
+
- Generates command sets from project type and script inventory.
|
| 189 |
+
- Process Tree Kill
|
| 190 |
+
- Terminates parent and child command processes to prevent orphan runners.
|
| 191 |
+
|
| 192 |
+
## Home Flow Section (Step-by-Step)
|
| 193 |
+
|
| 194 |
+
1. Place executable in the project root (next to `package.json`).
|
| 195 |
+
2. Launch app and allow automatic project detection.
|
| 196 |
+
3. Select and execute command from grouped command panel.
|
| 197 |
+
4. Monitor full output stream in the terminal pane.
|
| 198 |
+
|
| 199 |
+
## Home Compatibility Matrix (Expanded)
|
| 200 |
+
|
| 201 |
+
- Expo / React Native
|
| 202 |
+
- Typical commands: `expo start`, `expo run:android`, `expo prebuild`
|
| 203 |
+
- Android / Gradle
|
| 204 |
+
- Typical commands: `installDebug`, `assembleRelease`, `clean`
|
| 205 |
+
- Electron
|
| 206 |
+
- Typical commands: `npm run build`, `npm run build-win`, `npm run build-nsis`, `npm run dist`
|
| 207 |
+
- Next.js
|
| 208 |
+
- Typical commands: `npm run dev`, `npm run build`, `npm run start`, `npm run lint`
|
| 209 |
+
- Vite
|
| 210 |
+
- Typical commands: `npm run dev`, `npm run build`, `npm run preview`
|
| 211 |
+
- NPM Scripts
|
| 212 |
+
- Additional scripts surfaced automatically from project `package.json`
|
| 213 |
+
- ADB Utilities
|
| 214 |
+
- Typical commands: `adb devices`, `adb logcat`, `adb reverse tcp:8081 tcp:8081`
|
| 215 |
+
|
| 216 |
+
## Home Security Cards (Expanded)
|
| 217 |
+
|
| 218 |
+
- Context Isolation enabled for renderer boundary hardening.
|
| 219 |
+
- Node Integration disabled in renderer to reduce direct OS/runtime surface.
|
| 220 |
+
- Main-process-only sensitive logic for command construction and execution.
|
| 221 |
+
- Narrow preload bridge with explicit IPC methods.
|
| 222 |
+
- External access constrained by protocol and host policy.
|
| 223 |
+
- Strict shell policy and no inline handler dependency in host shell UI.
|
| 224 |
+
- Popup/navigation/request guard behavior in production.
|
| 225 |
+
- Controlled process spawn model with allowlist checks.
|
| 226 |
+
- Build-time credential hygiene for saved R2 config lifecycle.
|
| 227 |
+
|
| 228 |
+
## Notes For Teams
|
| 229 |
+
|
| 230 |
+
- Home page documentation should be treated as the UX-level contract.
|
| 231 |
+
- README is the implementation-facing mirror of that contract.
|
| 232 |
+
- When Home sections change, update this README section set to match.
|
preload.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
| 1 |
-
'use strict'
|
| 2 |
-
|
| 3 |
-
const { contextBridge, ipcRenderer } = require('electron')
|
| 4 |
-
|
| 5 |
-
contextBridge.exposeInMainWorld('api', {
|
| 6 |
-
getProject: () => ipcRenderer.invoke('get-project'),
|
| 7 |
-
runCmd: (opts) => ipcRenderer.invoke('run-cmd', opts),
|
| 8 |
-
killProc: () => ipcRenderer.invoke('kill-proc'),
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { contextBridge, ipcRenderer } = require('electron')
|
| 4 |
+
|
| 5 |
+
contextBridge.exposeInMainWorld('api', {
|
| 6 |
+
getProject: () => ipcRenderer.invoke('get-project'),
|
| 7 |
+
runCmd: (opts) => ipcRenderer.invoke('run-cmd', opts),
|
| 8 |
+
killProc: () => ipcRenderer.invoke('kill-proc'),
|
| 9 |
+
resizeProcPty: (size) => ipcRenderer.invoke('resize-proc-pty', size),
|
| 10 |
+
openExternal: (url) => ipcRenderer.invoke('open-external', url),
|
| 11 |
+
r2GetConfigStatus: () => ipcRenderer.invoke('r2-get-config-status'),
|
| 12 |
+
r2SaveConfig: (cfg) => ipcRenderer.invoke('r2-save-config', cfg),
|
| 13 |
+
r2TestConfig: (cfg) => ipcRenderer.invoke('r2-test-config', cfg),
|
| 14 |
+
r2ClearConfig: () => ipcRenderer.invoke('r2-clear-config'),
|
| 15 |
+
r2SuggestTarget: () => ipcRenderer.invoke('r2-suggest-target'),
|
| 16 |
+
r2UploadDist: (o) => ipcRenderer.invoke('r2-upload-dist', o),
|
| 17 |
+
|
| 18 |
+
onOutput: (cb) => ipcRenderer.on('proc-out', (_, data) => cb(data)),
|
| 19 |
+
onDone: (cb) => ipcRenderer.on('proc-done', (_, code) => cb(code)),
|
| 20 |
+
onProjectChanged: (cb) => ipcRenderer.on('project-root-changed', (_, data) => cb(data)),
|
| 21 |
+
offAll: () => {
|
| 22 |
+
ipcRenderer.removeAllListeners('proc-out')
|
| 23 |
+
ipcRenderer.removeAllListeners('proc-done')
|
| 24 |
+
ipcRenderer.removeAllListeners('project-root-changed')
|
| 25 |
+
}
|
| 26 |
+
})
|
scripts/before-pack-obfuscate.js
CHANGED
|
@@ -58,7 +58,27 @@ function obfuscateOne(absPath) {
|
|
| 58 |
return true
|
| 59 |
}
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
async function compileRootToBytecode(appDir, relPath) {
|
|
|
|
|
|
|
|
|
|
| 62 |
const jsPath = path.join(appDir, relPath)
|
| 63 |
if (!fs.existsSync(jsPath)) return false
|
| 64 |
|
|
@@ -72,12 +92,12 @@ async function compileRootToBytecode(appDir, relPath) {
|
|
| 72 |
compileAsModule: true
|
| 73 |
})
|
| 74 |
|
|
|
|
|
|
|
| 75 |
const loader = [
|
| 76 |
"'use strict'",
|
| 77 |
"require('bytenode')",
|
| 78 |
-
|
| 79 |
-
? `module.exports = require('./${parsed.name}.jsc')`
|
| 80 |
-
: `require('./${parsed.name}.jsc')`,
|
| 81 |
''
|
| 82 |
].join('\n')
|
| 83 |
|
|
@@ -91,9 +111,26 @@ module.exports = async (context) => {
|
|
| 91 |
return
|
| 92 |
}
|
| 93 |
|
| 94 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
const targets = []
|
| 98 |
|
| 99 |
if (enableBytecode) {
|
|
|
|
| 58 |
return true
|
| 59 |
}
|
| 60 |
|
| 61 |
+
// Workspace source root — two levels up from scripts/
|
| 62 |
+
const WORKSPACE_ROOT = path.resolve(__dirname, '..')
|
| 63 |
+
|
| 64 |
+
function assertNotSourceDir(appDir) {
|
| 65 |
+
const resolved = path.resolve(appDir)
|
| 66 |
+
if (
|
| 67 |
+
resolved === WORKSPACE_ROOT ||
|
| 68 |
+
resolved.startsWith(WORKSPACE_ROOT + path.sep)
|
| 69 |
+
) {
|
| 70 |
+
throw new Error(
|
| 71 |
+
`[bytecode] SAFETY GUARD: appDir "${resolved}" is inside the workspace source!\n` +
|
| 72 |
+
`Aborting to prevent source file corruption.\n` +
|
| 73 |
+
`appDir must be an electron-builder staging (temp) directory.`
|
| 74 |
+
)
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
async function compileRootToBytecode(appDir, relPath) {
|
| 79 |
+
// Safety: must never operate on workspace source files
|
| 80 |
+
assertNotSourceDir(appDir)
|
| 81 |
+
|
| 82 |
const jsPath = path.join(appDir, relPath)
|
| 83 |
if (!fs.existsSync(jsPath)) return false
|
| 84 |
|
|
|
|
| 92 |
compileAsModule: true
|
| 93 |
})
|
| 94 |
|
| 95 |
+
// Both main.js and preload.js are Electron entry points (not require()'d by anyone).
|
| 96 |
+
// The correct loader is just require() — NOT module.exports = require().
|
| 97 |
const loader = [
|
| 98 |
"'use strict'",
|
| 99 |
"require('bytenode')",
|
| 100 |
+
`require('./${parsed.name}.jsc')`,
|
|
|
|
|
|
|
| 101 |
''
|
| 102 |
].join('\n')
|
| 103 |
|
|
|
|
| 111 |
return
|
| 112 |
}
|
| 113 |
|
| 114 |
+
const bytecodeRequested = process.env.ENABLE_BYTECODE === '1'
|
| 115 |
+
const bytecodeAllowed = process.env.ALLOW_V8_BYTECODE === '1'
|
| 116 |
+
const enableBytecode = bytecodeRequested && bytecodeAllowed
|
| 117 |
+
|
| 118 |
+
if (bytecodeRequested && !bytecodeAllowed) {
|
| 119 |
+
console.log('[bytecode] requested but blocked (set ALLOW_V8_BYTECODE=1 to enable)')
|
| 120 |
+
}
|
| 121 |
|
| 122 |
+
// electron-builder v26+ exposes appOutDir in BeforePackContext.
|
| 123 |
+
// We only proceed when a reliable appDir is provided to avoid touching workspace source files.
|
| 124 |
+
if (!context || !context.appDir) {
|
| 125 |
+
console.log('[obfuscation] skipped: context.appDir is missing (builder context format changed)')
|
| 126 |
+
return
|
| 127 |
+
}
|
| 128 |
+
const appDir = context.appDir
|
| 129 |
+
|
| 130 |
+
// Safety: double-check appDir is NOT inside the workspace source
|
| 131 |
+
if (enableBytecode) {
|
| 132 |
+
assertNotSourceDir(appDir)
|
| 133 |
+
}
|
| 134 |
const targets = []
|
| 135 |
|
| 136 |
if (enableBytecode) {
|
scripts/build-v8-bytecode.js
CHANGED
|
@@ -1,30 +1,136 @@
|
|
| 1 |
'use strict'
|
| 2 |
|
|
|
|
|
|
|
| 3 |
const { spawn } = require('child_process')
|
|
|
|
| 4 |
|
| 5 |
-
const
|
| 6 |
-
const
|
| 7 |
-
const
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
.
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
})
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
process.exit(1)
|
| 30 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
'use strict'
|
| 2 |
|
| 3 |
+
const fs = require('fs')
|
| 4 |
+
const path = require('path')
|
| 5 |
const { spawn } = require('child_process')
|
| 6 |
+
const bytenode = require('bytenode')
|
| 7 |
|
| 8 |
+
const FILES_TO_COMPILE = ['main.js', 'preload.js']
|
| 9 |
+
const backups = new Map()
|
| 10 |
+
const generatedJsc = new Set()
|
| 11 |
+
let restoring = false
|
| 12 |
+
|
| 13 |
+
async function backupAndCompile() {
|
| 14 |
+
for (const file of FILES_TO_COMPILE) {
|
| 15 |
+
const absPath = path.join(process.cwd(), file)
|
| 16 |
+
if (!fs.existsSync(absPath)) continue
|
| 17 |
+
|
| 18 |
+
const backupPath = `${absPath}.backup`
|
| 19 |
+
fs.copyFileSync(absPath, backupPath)
|
| 20 |
+
backups.set(absPath, backupPath)
|
| 21 |
+
|
| 22 |
+
const parsed = path.parse(absPath)
|
| 23 |
+
const jscPath = path.join(parsed.dir, `${parsed.name}.jsc`)
|
| 24 |
+
const existedBefore = fs.existsSync(jscPath)
|
| 25 |
+
|
| 26 |
+
await bytenode.compileFile({
|
| 27 |
+
filename: absPath,
|
| 28 |
+
output: jscPath,
|
| 29 |
+
electron: true,
|
| 30 |
+
compileAsModule: true
|
| 31 |
+
})
|
| 32 |
+
|
| 33 |
+
if (!existedBefore) {
|
| 34 |
+
generatedJsc.add(jscPath)
|
| 35 |
+
}
|
| 36 |
+
console.log(`[V8 Builder] Compiled ${file} -> ${path.basename(jscPath)}`)
|
| 37 |
+
|
| 38 |
+
const relBase = path.parse(file).name
|
| 39 |
+
const requireLine = file === 'main.js'
|
| 40 |
+
? `module.exports = require('./${relBase}.jsc')`
|
| 41 |
+
: `require('./${relBase}.jsc')`
|
| 42 |
+
const loaderCode = [
|
| 43 |
+
"'use strict'",
|
| 44 |
+
"require('bytenode')",
|
| 45 |
+
requireLine,
|
| 46 |
+
''
|
| 47 |
+
].join('\n')
|
| 48 |
+
|
| 49 |
+
fs.writeFileSync(absPath, loaderCode, 'utf8')
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function restoreFiles() {
|
| 54 |
+
if (restoring) return
|
| 55 |
+
restoring = true
|
| 56 |
+
|
| 57 |
+
console.log('\n[V8 Builder] Restoring original source files...')
|
| 58 |
+
|
| 59 |
+
for (const [absPath, backupPath] of backups) {
|
| 60 |
+
try {
|
| 61 |
+
if (fs.existsSync(backupPath)) {
|
| 62 |
+
fs.copyFileSync(backupPath, absPath)
|
| 63 |
+
fs.unlinkSync(backupPath)
|
| 64 |
+
console.log(`[V8 Builder] Restored ${path.basename(absPath)}`)
|
| 65 |
+
}
|
| 66 |
+
} catch (err) {
|
| 67 |
+
console.error(`[V8 Builder] restore failed for ${path.basename(absPath)}: ${err.message}`)
|
| 68 |
+
}
|
| 69 |
}
|
| 70 |
+
|
| 71 |
+
for (const jscPath of generatedJsc) {
|
| 72 |
+
try {
|
| 73 |
+
if (fs.existsSync(jscPath)) {
|
| 74 |
+
fs.unlinkSync(jscPath)
|
| 75 |
+
}
|
| 76 |
+
} catch (err) {
|
| 77 |
+
console.error(`[V8 Builder] cleanup failed for ${path.basename(jscPath)}: ${err.message}`)
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
process.on('SIGINT', () => {
|
| 83 |
+
restoreFiles()
|
| 84 |
+
process.exit(1)
|
| 85 |
})
|
| 86 |
|
| 87 |
+
process.on('uncaughtException', (err) => {
|
| 88 |
+
console.error(err)
|
| 89 |
+
restoreFiles()
|
| 90 |
process.exit(1)
|
| 91 |
})
|
| 92 |
+
|
| 93 |
+
async function run() {
|
| 94 |
+
try {
|
| 95 |
+
console.log('=== Starting V8 Compilation and Build ===')
|
| 96 |
+
await backupAndCompile()
|
| 97 |
+
|
| 98 |
+
const builderCli = require.resolve('electron-builder/out/cli/cli.js')
|
| 99 |
+
const extraArgs = process.argv.slice(2)
|
| 100 |
+
const args = [
|
| 101 |
+
builderCli,
|
| 102 |
+
'--win',
|
| 103 |
+
'portable',
|
| 104 |
+
'--x64',
|
| 105 |
+
'--config.compression=maximum',
|
| 106 |
+
'--config.npmRebuild=false',
|
| 107 |
+
...extraArgs
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
const child = spawn(process.execPath, args, {
|
| 111 |
+
stdio: 'inherit',
|
| 112 |
+
windowsHide: true,
|
| 113 |
+
shell: false,
|
| 114 |
+
env: {
|
| 115 |
+
...process.env
|
| 116 |
+
}
|
| 117 |
+
})
|
| 118 |
+
|
| 119 |
+
child.on('exit', (code) => {
|
| 120 |
+
restoreFiles()
|
| 121 |
+
process.exit(code ?? 1)
|
| 122 |
+
})
|
| 123 |
+
|
| 124 |
+
child.on('error', (err) => {
|
| 125 |
+
console.error(`[V8 Builder] failed: ${err.message}`)
|
| 126 |
+
restoreFiles()
|
| 127 |
+
process.exit(1)
|
| 128 |
+
})
|
| 129 |
+
} catch (err) {
|
| 130 |
+
console.error(`[V8 Builder] prebuild failed: ${err.message}`)
|
| 131 |
+
restoreFiles()
|
| 132 |
+
process.exit(1)
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
run()
|
web/renderer.js
CHANGED
|
@@ -20,6 +20,15 @@ function showPage(name) {
|
|
| 20 |
document.getElementById('tab-home').classList.toggle('active', name === 'home')
|
| 21 |
document.getElementById('tab-run').classList.toggle('active', name === 'run')
|
| 22 |
document.getElementById('tab-r2').classList.toggle('active', name === 'r2')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
// iframe pages call these parent functions
|
|
@@ -51,9 +60,133 @@ const elPath = document.getElementById('project-path')
|
|
| 51 |
const elBadge = document.getElementById('type-badge')
|
| 52 |
const elKill = document.getElementById('btn-kill')
|
| 53 |
const elClear = document.getElementById('btn-clear')
|
|
|
|
| 54 |
const elDot = document.getElementById('status-dot')
|
| 55 |
const elStatus = document.getElementById('status-text')
|
| 56 |
const elRunning = document.getElementById('running-label')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
const r2ConfigBackdrop = document.getElementById('r2-config-backdrop')
|
| 59 |
const r2UploadBackdrop = document.getElementById('r2-upload-backdrop')
|
|
@@ -122,7 +255,6 @@ async function saveR2FromModal() {
|
|
| 122 |
return
|
| 123 |
}
|
| 124 |
|
| 125 |
-
appendOutput('\n\x1b[32m✔ R2 config saved\x1b[0m\n')
|
| 126 |
closeModal(r2ConfigBackdrop)
|
| 127 |
}
|
| 128 |
|
|
@@ -146,7 +278,6 @@ async function clearSavedR2Config() {
|
|
| 146 |
document.getElementById('r2-access-hint').textContent = ''
|
| 147 |
|
| 148 |
setTone(st, 'info', 'Saved config cleared.')
|
| 149 |
-
appendOutput('\n\x1b[33m• Cleared saved R2 config\x1b[0m\n')
|
| 150 |
}
|
| 151 |
|
| 152 |
async function uploadDistToR2() {
|
|
@@ -195,57 +326,33 @@ async function runR2UploadFromModal() {
|
|
| 195 |
elDot.className = 'running'
|
| 196 |
elStatus.textContent = 'Uploading R2'
|
| 197 |
elRunning.textContent = `dist -> ${target}`
|
| 198 |
-
termHeader(`aws s3 sync dist s3://.../${target}/`)
|
| 199 |
-
|
| 200 |
const res = await api.r2UploadDist({ target })
|
| 201 |
-
if (!res.ok) {
|
| 202 |
-
appendOutput(`\n\x1b[31m✖ ${res.error}\x1b[0m\n`)
|
| 203 |
-
}
|
| 204 |
}
|
| 205 |
|
| 206 |
// ── ANSI → HTML ───────────────────────────────────────────────────────────────
|
| 207 |
-
function ansiToHtml(raw) {
|
| 208 |
-
let s = raw
|
| 209 |
-
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
| 210 |
-
|
| 211 |
-
const fg = {
|
| 212 |
-
30: 'ansi-c30', 31: 'ansi-c31', 32: 'ansi-c32', 33: 'ansi-c33',
|
| 213 |
-
34: 'ansi-c34', 35: 'ansi-c35', 36: 'ansi-c36', 37: 'ansi-c37',
|
| 214 |
-
90: 'ansi-c90', 91: 'ansi-c91', 92: 'ansi-c92', 93: 'ansi-c93',
|
| 215 |
-
94: 'ansi-c94', 95: 'ansi-c95', 96: 'ansi-c96', 97: 'ansi-c97'
|
| 216 |
-
}
|
| 217 |
-
Object.entries(fg).forEach(([code, klass]) => {
|
| 218 |
-
s = s.replace(new RegExp(`\\x1b\\[${code}m`, 'g'), `<span class="${klass}">`)
|
| 219 |
-
})
|
| 220 |
-
s = s.replace(/\x1b\[1m/g, '<span class="ansi-bold">')
|
| 221 |
-
.replace(/\x1b\[0?m/g, '</span>')
|
| 222 |
-
.replace(/\x1b\[[0-9;]*[A-Za-z]/g, '') // strip remaining
|
| 223 |
-
|
| 224 |
-
// Color plain-text markers when command output has no ANSI colors.
|
| 225 |
-
s = s
|
| 226 |
-
.replace(/\[ERROR\]/g, '<span class="term-error">[ERROR]</span>')
|
| 227 |
-
.replace(/\[WARN\]/g, '<span class="term-warn">[WARN]</span>')
|
| 228 |
-
.replace(/\[INFO\]/g, '<span class="term-info">[INFO]</span>')
|
| 229 |
-
.replace(/\[STEP\s+([0-9]+)\]/g, '<span class="term-info">[STEP $1]</span>')
|
| 230 |
-
.replace(/\[DOWNLOAD\s+([0-9]+)\]/g, '<span class="term-warn">[DOWNLOAD $1]</span>')
|
| 231 |
-
.replace(/\[PROGRESS\s+([0-9]{1,3})%\]/g, '<span class="term-ok">[PROGRESS $1%]</span>')
|
| 232 |
-
.replace(/\[SUMMARY\]/g, '<span class="term-ok">[SUMMARY]</span>')
|
| 233 |
-
.replace(/Done \(exit 0\)/g, '<span class="term-ok">Done (exit 0)</span>')
|
| 234 |
-
.replace(/Exit code:\s*([0-9-]+)/g, 'Exit code: <span class="term-error">$1</span>')
|
| 235 |
-
return s
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
// ── Terminal output ───────────────────────────────────────────────────────────
|
| 239 |
function appendOutput(text) {
|
| 240 |
-
const
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
elOutput.scrollTop = elOutput.scrollHeight
|
| 245 |
}
|
| 246 |
|
| 247 |
function termHeader(label) {
|
| 248 |
-
appendOutput(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
}
|
| 250 |
|
| 251 |
function isBuildLikeCommandRenderer(cmdDef) {
|
|
@@ -274,8 +381,96 @@ function clearR2UiValues() {
|
|
| 274 |
if (list) list.innerHTML = ''
|
| 275 |
}
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
// ── Render command groups ─────────────────────────────────────────────────────
|
| 278 |
-
function renderGroups(groups) {
|
| 279 |
elGroups.innerHTML = ''
|
| 280 |
groups.forEach(group => {
|
| 281 |
const div = document.createElement('div')
|
|
@@ -294,7 +489,9 @@ function renderGroups(groups) {
|
|
| 294 |
const btn = document.createElement('button')
|
| 295 |
btn.className = 'cmd-btn'
|
| 296 |
btn.textContent = cmdDef.label
|
| 297 |
-
|
|
|
|
|
|
|
| 298 |
btn.addEventListener('click', () => runCommand(btn, cmdDef))
|
| 299 |
div.appendChild(btn)
|
| 300 |
})
|
|
@@ -310,7 +507,6 @@ async function runCommand(btn, cmdDef) {
|
|
| 310 |
if (isBuildLikeCommandRenderer(cmdDef)) {
|
| 311 |
await api.r2ClearConfig()
|
| 312 |
clearR2UiValues()
|
| 313 |
-
appendOutput('\n\x1b[33m[INFO]\x1b[0m Cleared R2 login/config before build\n')
|
| 314 |
}
|
| 315 |
|
| 316 |
if (runningBtn) {
|
|
@@ -327,9 +523,28 @@ async function runCommand(btn, cmdDef) {
|
|
| 327 |
elStatus.textContent = 'Running'
|
| 328 |
elRunning.textContent = btn.textContent
|
| 329 |
|
| 330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
}
|
| 334 |
|
| 335 |
// ── Load project ──────────────────────────────────────────────────────────────
|
|
@@ -360,11 +575,7 @@ async function loadProject() {
|
|
| 360 |
|
| 361 |
document.title = `Dev Launcher — ${projectName || projectRoot}`
|
| 362 |
|
| 363 |
-
renderGroups(groups)
|
| 364 |
-
|
| 365 |
-
appendOutput(`\x1b[32m✔ Loaded:\x1b[0m ${projectName || 'project'} (${typeInfo.label})\n`)
|
| 366 |
-
appendOutput(` Path: ${projectRoot}\n`)
|
| 367 |
-
if (groups.some(g => g.label.includes('Gradle'))) appendOutput(' Android folder detected ✓\n')
|
| 368 |
}
|
| 369 |
|
| 370 |
// ── Events ────────────────────────────────────────────────────────────────────
|
|
@@ -391,9 +602,21 @@ elKill.addEventListener('click', async () => {
|
|
| 391 |
})
|
| 392 |
|
| 393 |
elClear.addEventListener('click', () => {
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
})
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
// ── IPC listeners ─────────────────────────────────────────────────────────────
|
| 398 |
api.onOutput((data) => appendOutput(data))
|
| 399 |
|
|
@@ -408,12 +631,13 @@ api.onDone((code) => {
|
|
| 408 |
runningBtn.classList.add(code === 0 ? 'done-ok' : 'done-err')
|
| 409 |
runningBtn = null
|
| 410 |
}
|
|
|
|
| 411 |
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
: `\n\x1b[31m✖ Exit code: ${code}\x1b[0m\n`
|
| 415 |
-
)
|
| 416 |
})
|
| 417 |
|
| 418 |
// ── Init ──────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
| 419 |
loadProject()
|
|
|
|
| 20 |
document.getElementById('tab-home').classList.toggle('active', name === 'home')
|
| 21 |
document.getElementById('tab-run').classList.toggle('active', name === 'run')
|
| 22 |
document.getElementById('tab-r2').classList.toggle('active', name === 'r2')
|
| 23 |
+
|
| 24 |
+
if (name === 'run' && term && fitAddon) {
|
| 25 |
+
requestAnimationFrame(() => {
|
| 26 |
+
setTimeout(() => {
|
| 27 |
+
fitAddon.fit()
|
| 28 |
+
notifyPtyResize()
|
| 29 |
+
}, 20)
|
| 30 |
+
})
|
| 31 |
+
}
|
| 32 |
}
|
| 33 |
|
| 34 |
// iframe pages call these parent functions
|
|
|
|
| 60 |
const elBadge = document.getElementById('type-badge')
|
| 61 |
const elKill = document.getElementById('btn-kill')
|
| 62 |
const elClear = document.getElementById('btn-clear')
|
| 63 |
+
const elStreamMode = document.getElementById('stream-mode')
|
| 64 |
const elDot = document.getElementById('status-dot')
|
| 65 |
const elStatus = document.getElementById('status-text')
|
| 66 |
const elRunning = document.getElementById('running-label')
|
| 67 |
+
let term = null
|
| 68 |
+
let fitAddon = null
|
| 69 |
+
let resizeObserver = null
|
| 70 |
+
|
| 71 |
+
function isTermNearBottom() {
|
| 72 |
+
if (!term || !term.buffer || !term.buffer.active) return true
|
| 73 |
+
const b = term.buffer.active
|
| 74 |
+
return b.viewportY >= b.baseY
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function normalizeForReadableTerminal(raw) {
|
| 78 |
+
return String(raw || '')
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function colorizeForDisplay(raw) {
|
| 82 |
+
return String(raw || '')
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function initTerminal() {
|
| 86 |
+
if (!elOutput || !window.Terminal) return
|
| 87 |
+
|
| 88 |
+
const FitAddonCtor = (window.FitAddon && window.FitAddon.FitAddon) ? window.FitAddon.FitAddon : null
|
| 89 |
+
term = new window.Terminal({
|
| 90 |
+
cursorBlink: false,
|
| 91 |
+
disableStdin: true,
|
| 92 |
+
convertEol: false,
|
| 93 |
+
scrollback: 100000,
|
| 94 |
+
fontFamily: 'Cascadia Code, Consolas, monospace',
|
| 95 |
+
fontSize: 12,
|
| 96 |
+
theme: {
|
| 97 |
+
background: '#080812',
|
| 98 |
+
foreground: '#e6e8ff',
|
| 99 |
+
red: '#ff6b6b',
|
| 100 |
+
green: '#37d67a',
|
| 101 |
+
yellow: '#ffd166',
|
| 102 |
+
blue: '#6ea8ff',
|
| 103 |
+
magenta: '#d291ff',
|
| 104 |
+
cyan: '#5fe3ff',
|
| 105 |
+
white: '#f4f6ff',
|
| 106 |
+
brightRed: '#ff8a8a',
|
| 107 |
+
brightGreen: '#69f0a6',
|
| 108 |
+
brightYellow: '#ffe08a',
|
| 109 |
+
brightBlue: '#9fc0ff',
|
| 110 |
+
brightMagenta: '#e3b7ff',
|
| 111 |
+
brightCyan: '#99f0ff'
|
| 112 |
+
}
|
| 113 |
+
})
|
| 114 |
+
|
| 115 |
+
if (FitAddonCtor) {
|
| 116 |
+
fitAddon = new FitAddonCtor()
|
| 117 |
+
term.loadAddon(fitAddon)
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
term.open(elOutput)
|
| 121 |
+
if (fitAddon) fitAddon.fit()
|
| 122 |
+
notifyPtyResize()
|
| 123 |
+
|
| 124 |
+
if (typeof ResizeObserver !== 'undefined') {
|
| 125 |
+
resizeObserver = new ResizeObserver(() => {
|
| 126 |
+
if (fitAddon) fitAddon.fit()
|
| 127 |
+
notifyPtyResize()
|
| 128 |
+
})
|
| 129 |
+
resizeObserver.observe(elOutput)
|
| 130 |
+
} else {
|
| 131 |
+
window.addEventListener('resize', () => {
|
| 132 |
+
if (fitAddon) fitAddon.fit()
|
| 133 |
+
notifyPtyResize()
|
| 134 |
+
})
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function notifyPtyResize() {
|
| 139 |
+
if (!term || !api || typeof api.resizeProcPty !== 'function') return
|
| 140 |
+
const cols = Number(term.cols || 0)
|
| 141 |
+
const rows = Number(term.rows || 0)
|
| 142 |
+
if (!cols || !rows) return
|
| 143 |
+
api.resizeProcPty({ cols, rows })
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
async function copyTermSelection() {
|
| 147 |
+
if (!term) return false
|
| 148 |
+
const selected = term.getSelection()
|
| 149 |
+
if (!selected) return false
|
| 150 |
+
try {
|
| 151 |
+
await navigator.clipboard.writeText(selected)
|
| 152 |
+
return true
|
| 153 |
+
} catch {
|
| 154 |
+
return false
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
function installTerminalShortcuts() {
|
| 159 |
+
document.addEventListener('keydown', async (e) => {
|
| 160 |
+
const isCtrlOrMeta = e.ctrlKey || e.metaKey
|
| 161 |
+
if (!isCtrlOrMeta) return
|
| 162 |
+
|
| 163 |
+
const key = String(e.key || '').toLowerCase()
|
| 164 |
+
|
| 165 |
+
// Ctrl/Cmd + A => select all terminal output
|
| 166 |
+
if (key === 'a') {
|
| 167 |
+
if (!term) return
|
| 168 |
+
e.preventDefault()
|
| 169 |
+
term.selectAll()
|
| 170 |
+
return
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// Ctrl/Cmd + C (and Ctrl/Cmd + Shift + C) => copy selected terminal text
|
| 174 |
+
if (key === 'c') {
|
| 175 |
+
if (!term || !term.hasSelection()) return
|
| 176 |
+
e.preventDefault()
|
| 177 |
+
await copyTermSelection()
|
| 178 |
+
term.clearSelection()
|
| 179 |
+
return
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// Ctrl/Cmd + L => clear terminal
|
| 183 |
+
if (key === 'l') {
|
| 184 |
+
if (!term) return
|
| 185 |
+
e.preventDefault()
|
| 186 |
+
term.reset()
|
| 187 |
+
}
|
| 188 |
+
})
|
| 189 |
+
}
|
| 190 |
|
| 191 |
const r2ConfigBackdrop = document.getElementById('r2-config-backdrop')
|
| 192 |
const r2UploadBackdrop = document.getElementById('r2-upload-backdrop')
|
|
|
|
| 255 |
return
|
| 256 |
}
|
| 257 |
|
|
|
|
| 258 |
closeModal(r2ConfigBackdrop)
|
| 259 |
}
|
| 260 |
|
|
|
|
| 278 |
document.getElementById('r2-access-hint').textContent = ''
|
| 279 |
|
| 280 |
setTone(st, 'info', 'Saved config cleared.')
|
|
|
|
| 281 |
}
|
| 282 |
|
| 283 |
async function uploadDistToR2() {
|
|
|
|
| 326 |
elDot.className = 'running'
|
| 327 |
elStatus.textContent = 'Uploading R2'
|
| 328 |
elRunning.textContent = `dist -> ${target}`
|
|
|
|
|
|
|
| 329 |
const res = await api.r2UploadDist({ target })
|
|
|
|
|
|
|
|
|
|
| 330 |
}
|
| 331 |
|
| 332 |
// ── ANSI → HTML ───────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
// ── Terminal output ───────────────────────────────────────────────────────────
|
| 334 |
function appendOutput(text) {
|
| 335 |
+
const raw = normalizeForReadableTerminal(text)
|
| 336 |
+
if (!raw) return
|
| 337 |
+
|
| 338 |
+
if (term) {
|
| 339 |
+
const shouldFollow = isTermNearBottom()
|
| 340 |
+
term.write(colorizeForDisplay(raw))
|
| 341 |
+
if (shouldFollow) term.scrollToBottom()
|
| 342 |
+
return
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
elOutput.appendChild(document.createTextNode(raw))
|
| 346 |
elOutput.scrollTop = elOutput.scrollHeight
|
| 347 |
}
|
| 348 |
|
| 349 |
function termHeader(label) {
|
| 350 |
+
appendOutput('\n▶ ' + label + '\n' + '─'.repeat(60) + '\n')
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
function getSelectedStreamMode() {
|
| 354 |
+
const mode = String(elStreamMode?.value || 'realtime').toLowerCase()
|
| 355 |
+
return mode === 'stable' ? 'stable' : 'realtime'
|
| 356 |
}
|
| 357 |
|
| 358 |
function isBuildLikeCommandRenderer(cmdDef) {
|
|
|
|
| 381 |
if (list) list.innerHTML = ''
|
| 382 |
}
|
| 383 |
|
| 384 |
+
function buildCommandHint(cmdDef, group, typeInfo) {
|
| 385 |
+
const label = String(cmdDef?.label || '').toLowerCase()
|
| 386 |
+
const cmdLine = [cmdDef.cmd, ...(cmdDef.args || [])].join(' ')
|
| 387 |
+
const projectType = String(typeInfo?.label || 'Project').trim()
|
| 388 |
+
const projectTypeLower = projectType.toLowerCase()
|
| 389 |
+
|
| 390 |
+
const lines = []
|
| 391 |
+
|
| 392 |
+
if (/expo start/.test(label)) {
|
| 393 |
+
lines.push('Step 1: Start Expo development server.')
|
| 394 |
+
lines.push('Use this first for local mobile development.')
|
| 395 |
+
} else if (/expo run:android/.test(label)) {
|
| 396 |
+
lines.push('Step 2: Build and run the app on Android device/emulator.')
|
| 397 |
+
lines.push('Use after Expo server is ready.')
|
| 398 |
+
} else if (/expo prebuild/.test(label)) {
|
| 399 |
+
lines.push('Prepare native Android project files from Expo config.')
|
| 400 |
+
lines.push('Use when native config changed or Android folder is missing.')
|
| 401 |
+
} else if (/installdebug/.test(label)) {
|
| 402 |
+
lines.push('Install debug APK to connected Android device/emulator.')
|
| 403 |
+
lines.push('Recommended after clean build or code changes.')
|
| 404 |
+
} else if (/assemblerelease|build[-\s]?exe|build[-\s]?win|build[-\s]?msi|build[-\s]?nsis|build[-\s]?linux|dist|pack/.test(label)) {
|
| 405 |
+
lines.push('Create a production build artifact.')
|
| 406 |
+
lines.push('Use when you want distributable output files.')
|
| 407 |
+
} else if (/assembledebug/.test(label)) {
|
| 408 |
+
lines.push('Compile a debug build without installing it.')
|
| 409 |
+
} else if (/clean\s*\+\s*install/.test(label)) {
|
| 410 |
+
lines.push('Step 1+2: Clean old build files, then install fresh debug app.')
|
| 411 |
+
lines.push('Good first fix when build output is inconsistent.')
|
| 412 |
+
} else if (/^clean$/.test(label)) {
|
| 413 |
+
lines.push('Step 1: Remove cached build artifacts.')
|
| 414 |
+
lines.push('Run before rebuild if Gradle behaves unexpectedly.')
|
| 415 |
+
} else if (/adb devices/.test(label)) {
|
| 416 |
+
lines.push('Check if Android devices/emulators are connected.')
|
| 417 |
+
lines.push('Run this before install commands.')
|
| 418 |
+
} else if (/adb logcat/.test(label)) {
|
| 419 |
+
lines.push('Open real-time Android logs for debugging.')
|
| 420 |
+
} else if (/adb reverse/.test(label)) {
|
| 421 |
+
lines.push('Forward Metro port to device (8081 -> 8081).')
|
| 422 |
+
lines.push('Use when device cannot reach local dev server.')
|
| 423 |
+
} else if (/npm install\s*--legacy-peer-deps/.test(label)) {
|
| 424 |
+
lines.push('Install dependencies with legacy peer dependency resolution.')
|
| 425 |
+
lines.push('Use only when normal install fails due to peer conflicts.')
|
| 426 |
+
} else if (/npm install/.test(label)) {
|
| 427 |
+
lines.push('Step 1: Install project dependencies.')
|
| 428 |
+
} else if (/npm ci/.test(label)) {
|
| 429 |
+
lines.push('Install dependencies from lockfile for clean reproducible setup.')
|
| 430 |
+
} else if (/npm run dev/.test(label)) {
|
| 431 |
+
lines.push('Start development mode (hot reload/watch if supported).')
|
| 432 |
+
} else if (/npm run start/.test(label)) {
|
| 433 |
+
lines.push('Start app in normal run mode.')
|
| 434 |
+
} else if (/npm run android/.test(label)) {
|
| 435 |
+
lines.push('Run Android target from package scripts.')
|
| 436 |
+
} else if (/npm run ios/.test(label)) {
|
| 437 |
+
lines.push('Run iOS target from package scripts.')
|
| 438 |
+
} else if (/npm run web/.test(label)) {
|
| 439 |
+
lines.push('Run web target from package scripts.')
|
| 440 |
+
} else if (/npm run build/.test(label)) {
|
| 441 |
+
lines.push('Build production assets for this project.')
|
| 442 |
+
} else if (/npm run preview/.test(label)) {
|
| 443 |
+
lines.push('Preview the production build locally.')
|
| 444 |
+
} else if (/npm run lint/.test(label)) {
|
| 445 |
+
lines.push('Run lint checks to catch code issues.')
|
| 446 |
+
} else if (/npm run test/.test(label)) {
|
| 447 |
+
lines.push('Run test suite for this project.')
|
| 448 |
+
} else {
|
| 449 |
+
lines.push('Run this command for the current project.')
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
let flow = ''
|
| 453 |
+
if (projectTypeLower.includes('expo') || projectTypeLower.includes('react native')) {
|
| 454 |
+
flow = 'Recommended order: npm install -> expo start -> expo run:android (or installDebug).'
|
| 455 |
+
} else if (projectTypeLower.includes('electron')) {
|
| 456 |
+
flow = 'Recommended order: npm install -> npm run dev (or start) -> npm run build-exe/build-win for release.'
|
| 457 |
+
} else if (projectTypeLower.includes('next.js') || projectTypeLower.includes('next')) {
|
| 458 |
+
flow = 'Recommended order: npm install -> npm run dev -> npm run build -> npm run start.'
|
| 459 |
+
} else if (projectTypeLower.includes('vite')) {
|
| 460 |
+
flow = 'Recommended order: npm install -> npm run dev -> npm run build -> npm run preview.'
|
| 461 |
+
} else {
|
| 462 |
+
flow = 'Recommended order: npm install -> npm run dev/start -> npm run build (when ready to release).'
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
lines.push(`Project type: ${projectType}.`)
|
| 466 |
+
lines.push(flow)
|
| 467 |
+
lines.push(`Group: ${group.label}.`)
|
| 468 |
+
lines.push(`Command: ${cmdLine}.`)
|
| 469 |
+
return lines.join('\n')
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
// ── Render command groups ─────────────────────────────────────────────────────
|
| 473 |
+
function renderGroups(groups, typeInfo) {
|
| 474 |
elGroups.innerHTML = ''
|
| 475 |
groups.forEach(group => {
|
| 476 |
const div = document.createElement('div')
|
|
|
|
| 489 |
const btn = document.createElement('button')
|
| 490 |
btn.className = 'cmd-btn'
|
| 491 |
btn.textContent = cmdDef.label
|
| 492 |
+
const hint = buildCommandHint(cmdDef, group, typeInfo)
|
| 493 |
+
btn.title = hint
|
| 494 |
+
btn.setAttribute('aria-label', hint)
|
| 495 |
btn.addEventListener('click', () => runCommand(btn, cmdDef))
|
| 496 |
div.appendChild(btn)
|
| 497 |
})
|
|
|
|
| 507 |
if (isBuildLikeCommandRenderer(cmdDef)) {
|
| 508 |
await api.r2ClearConfig()
|
| 509 |
clearR2UiValues()
|
|
|
|
| 510 |
}
|
| 511 |
|
| 512 |
if (runningBtn) {
|
|
|
|
| 523 |
elStatus.textContent = 'Running'
|
| 524 |
elRunning.textContent = btn.textContent
|
| 525 |
|
| 526 |
+
const streamMode = getSelectedStreamMode()
|
| 527 |
+
elRunning.textContent = `${btn.textContent} [${streamMode}]`
|
| 528 |
+
|
| 529 |
+
// Wait a moment for the Run page layout to settle before fitting and running.
|
| 530 |
+
setTimeout(async () => {
|
| 531 |
+
if (fitAddon) fitAddon.fit()
|
| 532 |
+
notifyPtyResize()
|
| 533 |
|
| 534 |
+
const realCols = term ? (term.cols || 120) : 120
|
| 535 |
+
const realRows = term ? (term.rows || 30) : 30
|
| 536 |
+
|
| 537 |
+
if (term) term.reset()
|
| 538 |
+
|
| 539 |
+
await api.runCmd({
|
| 540 |
+
cmd: cmdDef.cmd,
|
| 541 |
+
args: cmdDef.args,
|
| 542 |
+
cwd: cmdDef.cwd,
|
| 543 |
+
streamMode,
|
| 544 |
+
cols: realCols,
|
| 545 |
+
rows: realRows,
|
| 546 |
+
})
|
| 547 |
+
}, 50)
|
| 548 |
}
|
| 549 |
|
| 550 |
// ── Load project ──────────────────────────────────────────────────────────────
|
|
|
|
| 575 |
|
| 576 |
document.title = `Dev Launcher — ${projectName || projectRoot}`
|
| 577 |
|
| 578 |
+
renderGroups(groups, typeInfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
}
|
| 580 |
|
| 581 |
// ── Events ────────────────────────────────────────────────────────────────────
|
|
|
|
| 602 |
})
|
| 603 |
|
| 604 |
elClear.addEventListener('click', () => {
|
| 605 |
+
if (term) {
|
| 606 |
+
term.reset()
|
| 607 |
+
} else {
|
| 608 |
+
elOutput.innerHTML = ''
|
| 609 |
+
}
|
| 610 |
})
|
| 611 |
|
| 612 |
+
if (elStreamMode) {
|
| 613 |
+
const saved = String(localStorage.getItem('streamMode') || '').toLowerCase()
|
| 614 |
+
elStreamMode.value = saved === 'stable' ? 'stable' : 'realtime'
|
| 615 |
+
elStreamMode.addEventListener('change', () => {
|
| 616 |
+
localStorage.setItem('streamMode', getSelectedStreamMode())
|
| 617 |
+
})
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
// ── IPC listeners ─────────────────────────────────────────────────────────────
|
| 621 |
api.onOutput((data) => appendOutput(data))
|
| 622 |
|
|
|
|
| 631 |
runningBtn.classList.add(code === 0 ? 'done-ok' : 'done-err')
|
| 632 |
runningBtn = null
|
| 633 |
}
|
| 634 |
+
})
|
| 635 |
|
| 636 |
+
api.onProjectChanged(() => {
|
| 637 |
+
loadProject()
|
|
|
|
|
|
|
| 638 |
})
|
| 639 |
|
| 640 |
// ── Init ──────────────────────────────────────────────────────────────────────
|
| 641 |
+
initTerminal()
|
| 642 |
+
installTerminalShortcuts()
|
| 643 |
loadProject()
|
web/styles.css
CHANGED
|
@@ -264,20 +264,25 @@ body {
|
|
| 264 |
flex-direction: column;
|
| 265 |
overflow: hidden;
|
| 266 |
background: #080812;
|
|
|
|
| 267 |
}
|
| 268 |
#term-output {
|
| 269 |
flex: 1;
|
| 270 |
-
overflow
|
| 271 |
-
padding: 10px 14px;
|
| 272 |
font-family: 'Cascadia Code', 'Consolas', monospace;
|
| 273 |
font-size: 12px;
|
| 274 |
line-height: 1.55;
|
| 275 |
white-space: pre-wrap;
|
| 276 |
word-break: break-all;
|
| 277 |
color: #c0c0d8;
|
|
|
|
| 278 |
}
|
| 279 |
#term-output::-webkit-scrollbar { width: 6px; }
|
| 280 |
#term-output::-webkit-scrollbar-thumb { background: #2a2a4a; border-radius: 3px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
.term-line { display: block; }
|
| 282 |
.t-prompt { color: var(--accent); font-weight: 600; }
|
| 283 |
|
|
@@ -345,6 +350,33 @@ body {
|
|
| 345 |
}
|
| 346 |
#btn-clear:hover { color: var(--text); }
|
| 347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
#status-dot {
|
| 349 |
width: 8px; height: 8px;
|
| 350 |
border-radius: 50%;
|
|
|
|
| 264 |
flex-direction: column;
|
| 265 |
overflow: hidden;
|
| 266 |
background: #080812;
|
| 267 |
+
padding: 10px 14px;
|
| 268 |
}
|
| 269 |
#term-output {
|
| 270 |
flex: 1;
|
| 271 |
+
overflow: hidden;
|
|
|
|
| 272 |
font-family: 'Cascadia Code', 'Consolas', monospace;
|
| 273 |
font-size: 12px;
|
| 274 |
line-height: 1.55;
|
| 275 |
white-space: pre-wrap;
|
| 276 |
word-break: break-all;
|
| 277 |
color: #c0c0d8;
|
| 278 |
+
user-select: text;
|
| 279 |
}
|
| 280 |
#term-output::-webkit-scrollbar { width: 6px; }
|
| 281 |
#term-output::-webkit-scrollbar-thumb { background: #2a2a4a; border-radius: 3px; }
|
| 282 |
+
.xterm, .xterm * {
|
| 283 |
+
user-select: text !important;
|
| 284 |
+
-webkit-user-select: text !important;
|
| 285 |
+
}
|
| 286 |
.term-line { display: block; }
|
| 287 |
.t-prompt { color: var(--accent); font-weight: 600; }
|
| 288 |
|
|
|
|
| 350 |
}
|
| 351 |
#btn-clear:hover { color: var(--text); }
|
| 352 |
|
| 353 |
+
#stream-mode-wrap {
|
| 354 |
+
display: inline-flex;
|
| 355 |
+
align-items: center;
|
| 356 |
+
gap: 6px;
|
| 357 |
+
padding: 2px 7px;
|
| 358 |
+
border: 1px solid var(--border);
|
| 359 |
+
border-radius: 6px;
|
| 360 |
+
background: rgba(18, 21, 46, 0.72);
|
| 361 |
+
}
|
| 362 |
+
#stream-mode-wrap label {
|
| 363 |
+
color: var(--muted);
|
| 364 |
+
font-size: 11px;
|
| 365 |
+
}
|
| 366 |
+
#stream-mode {
|
| 367 |
+
background: transparent;
|
| 368 |
+
color: var(--text);
|
| 369 |
+
border: none;
|
| 370 |
+
outline: none;
|
| 371 |
+
font-size: 12px;
|
| 372 |
+
font-family: inherit;
|
| 373 |
+
cursor: pointer;
|
| 374 |
+
}
|
| 375 |
+
#stream-mode option {
|
| 376 |
+
background: #12152e;
|
| 377 |
+
color: var(--text);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
#status-dot {
|
| 381 |
width: 8px; height: 8px;
|
| 382 |
border-radius: 50%;
|