3.6 KiB
3.6 KiB
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 on rows whose text contains any of the target keywords.
- 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. OptionalafterPack.jsfor 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 only — array
TARGET_KEYWORDS. Row is disconnected ifrow.innerTextcontains any keyword. - Config check: In renderer.js,
ensureConfigThenSessions()runs on config.html load; sets#linesperpageto 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_logQueueand exposes__ptw_flushLogs()/__ptw_getSessions(). Renderer polls viawebview.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
- Open inject.js.
- Add the string to the TARGET_KEYWORDS array.
- Save; rebuild if distributing exe (
npm run dist).
Changing config or startup flow
- Config URL / field / submit: renderer.js (
ensureConfigThenSessionsand the injected script string). - Sessions URL: renderer.js (
SESSION_URL) and index.html (webview initialsrcis config; renderer switches to sessions after config check).
Build and run
- Run:
npm installthennpm start(or Start PTW Auto-Disconnect.vbs). - Build:
npm run dist→ installer + portable exe + win-unpacked. Optional:npm run dist:portableto also create the zip.
Keep this file updated when you change architecture, key file roles, or conventions so the “AI DNA” stays accurate.