Files
Start-PTW-Auto-Disconnect/AI_DNA.md
T

56 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AI DNA — Project overview for AI and maintainers
Short reference so an AI or new dev can understand and modify this project without guessing.
## What this app is
- **Electron** desktop app (Windows). One window; no browser opened.
- Connects to **localhost:1947** sessions/config pages in a **hidden webview**.
- **On startup:** Loads config page → ensures “Table Rows per Page” = 100 → submits if changed → loads sessions page.
- **When Monitor ON:** Every 60s reloads sessions page; scans table rows; **clicks Disconnect** when **Product** contains **PTW70** and **Feature** matches **TARGET_KEYWORDS** (substring) or modules **19**/**9** (exact).
- **UI:** Left = “Logged in” (by user); Right = “Activity log”; bottom = Monitor ON/OFF + Clear. Uses **powerSaveBlocker** so Windows/display don’t sleep while the app runs.
## Tech stack
- **Runtime:** Node.js + Electron (main process + one renderer, no Node in renderer).
- **Front-end:** Vanilla JS + one HTML file + inline CSS. No React/Vue/framework.
- **Build:** electron-builder (NSIS installer + portable exe + win-unpacked). `asar: false`. Optional `afterPack.js` for ffmpeg placement.
## Key files (don’t guess — use these)
| File | Role |
|------|------|
| **main.js** | Electron main: create window, load index.html, enable webview, powerSaveBlocker. |
| **index.html** | Single UI: webview (hidden), two panels (Logged in left, Activity log right), buttons, status. |
| **renderer.js** | Renderer logic: load config first then sessions, inject scripts, poll for logs/sessions, toggle Monitor, 60s reload. |
| **inject.js** | Injected into the **sessions** page (webview). Defines `__ptw_getSessions()`, `__ptw_flushLogs()`, `__ptw_setRunning()`, and the **TARGET_KEYWORDS** + scan/Disconnect logic. Not used on config page. |
| **preload.js** | Minimal; no Node exposed to renderer. |
| **afterPack.js** | Copies ffmpeg.dll to app root if needed for portable build. |
| **package.json** | Scripts: `start`, `dist`, `dist:portable`. Build: win targets, extraFiles for ffmpeg, afterPack. |
## Important conventions
- **Keywords:** Edit **inject.js** — `TARGET_KEYWORDS` (Feature substring) and `TARGET_FEATURE_IDS`. Disconnect only if Product contains `PTW70` and Feature matches (see `matchesPtw70FeatureKeyword` / `matchesFeatureId`).
- **Config check:** In **renderer.js**, `ensureConfigThenSessions()` runs on config.html load; sets `#linesperpage` to 100 and clicks Submit if needed, then navigates webview to sessions.
- **URLs:** Config = `http://localhost:1947/_int_/config.html`, Sessions = `http://localhost:1947/_int_/sessions.html`. Defined in renderer.js.
- **Log/sessions bridge:** Inject script pushes to `__ptw_logQueue` and exposes `__ptw_flushLogs()` / `__ptw_getSessions()`. Renderer polls via `webview.executeJavaScript()` and updates DOM.
- **Persistence:** Monitor ON/OFF and activity log entries in renderer **localStorage** (keys in renderer.js). No backend.
## Adding a new disconnect keyword
1. Open **inject.js**.
2. Add the string to the **TARGET_KEYWORDS** array.
3. Save; rebuild if distributing exe (`npm run dist`).
## Changing config or startup flow
- Config URL / field / submit: **renderer.js** (`ensureConfigThenSessions` and the injected script string).
- Sessions URL: **renderer.js** (`SESSION_URL`) and **index.html** (webview initial `src` is config; renderer switches to sessions after config check).
## Build and run
- **Run:** `npm install` then `npm start` (or **Start PTW Auto-Disconnect.vbs**).
- **Build:** `npm run dist` → installer + portable exe + win-unpacked. Optional: `npm run dist:portable` to also create the zip.
Keep this file updated when you change architecture, key file roles, or conventions so the “AI DNA” stays accurate.