Add files via upload
This commit is contained in:
12 files changed
+4682
No files matched your search
@@ -0,0 +1,55 @@
|
|||||||
|
# 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`. 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** only — array `TARGET_KEYWORDS`. Row is disconnected if `row.innerText` contains any keyword.
|
||||||
|
- **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.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 PTW Auto-Disconnect contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# PTW Auto-Disconnect
|
||||||
|
|
||||||
|
Standalone desktop app that monitors your PTW sessions page and automatically disconnects sessions matching certain product/feature keywords. Runs in a small window **without opening Chrome**.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Auto-disconnect** — When Monitor is ON, scans the sessions table and clicks Disconnect on rows containing any of the target keywords.
|
||||||
|
- **Logged in** — Left panel shows who is logged in, grouped by user, with product/feature per session.
|
||||||
|
- **Activity log** — Right panel shows timestamps and disconnect/refresh events.
|
||||||
|
- **Config on startup** — On launch, checks `http://localhost:1947/_int_/config.html` and ensures **Table Rows per Page** is set to **100** (and submits if changed).
|
||||||
|
- **Stay awake** — While the app is running, prevents Windows from sleeping and the display from turning off.
|
||||||
|
- **One-click run** — Double-click **Start PTW Auto-Disconnect.vbs** (or the built exe) to run without opening a terminal.
|
||||||
|
|
||||||
|
## Target keywords (disconnect when present)
|
||||||
|
|
||||||
|
- PTW_DATAEXCHANGE
|
||||||
|
- PTW_ARC_FLASH
|
||||||
|
- PTW_DEVEVAL
|
||||||
|
- PTW_AFAULT
|
||||||
|
- PTW_DAPPER
|
||||||
|
- PTW_COOREVAL
|
||||||
|
- PTW_CAPTOR
|
||||||
|
- PTW_IEC_FAULT
|
||||||
|
- PTW_IEC61363
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- **To run from source:** Node.js (LTS) and `npm install`.
|
||||||
|
- **Sessions server:** The app expects the sessions page at `http://localhost:1947/_int_/sessions.html` (and config at `http://localhost:1947/_int_/config.html`). Start your server first.
|
||||||
|
|
||||||
|
## Run from source
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
Or double-click **Start PTW Auto-Disconnect.vbs** (no terminal window).
|
||||||
|
|
||||||
|
## Build executables
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dist
|
||||||
|
```
|
||||||
|
|
||||||
|
Output in **`dist`**:
|
||||||
|
|
||||||
|
| Output | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| **PTW Auto-Disconnect Setup 2.1.0.exe** | Windows installer |
|
||||||
|
| **PTW Auto-Disconnect 2.1.0.exe** | Portable single exe (no install) |
|
||||||
|
| **win-unpacked/** | No-install folder; run **PTW Auto-Disconnect.exe** from inside (avoids ffmpeg path issues on some systems) |
|
||||||
|
|
||||||
|
Optional: build and create a zip of the no-install folder:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dist:portable
|
||||||
|
```
|
||||||
|
|
||||||
|
Then use **`dist\PTW Auto-Disconnect-no-install.zip`** — unzip anywhere and run the exe from the extracted folder.
|
||||||
|
|
||||||
|
## Running on a new PC
|
||||||
|
|
||||||
|
- **From source:** Install Node.js, copy the project, run `npm install`, then `npm start` or the VBS launcher.
|
||||||
|
- **Built exe/installer:** Copy the installer or the **win-unpacked** folder (or the portable exe). No Node.js required.
|
||||||
|
|
||||||
|
## Behavior summary
|
||||||
|
|
||||||
|
- **Monitor ON/OFF** — Toggle monitoring; when ON, the sessions page is reloaded every 60 seconds and matching rows are disconnected.
|
||||||
|
- **Clear** — Clears the activity log display (persisted logs are cleared).
|
||||||
|
- **Config check** — On startup the app loads the config page, sets rows per page to 100 if needed, submits, then opens the sessions page. The activity log shows: *Config: rows per page already 100* or *Config: rows per page set to 100* (or a message if the input was not found).
|
||||||
|
- The sessions page is loaded in a hidden webview; only the compact GUI (panels + buttons) is visible.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
See [LICENSE](LICENSE).
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Set sh = CreateObject("WScript.Shell")
|
||||||
|
sh.CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
|
||||||
|
sh.Run "cmd /c npm start", 0, False
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure ffmpeg.dll is next to the exe (appOutDir) so the portable exe finds it.
|
||||||
|
* extraFiles may place it in resources/app; copy to root if needed.
|
||||||
|
*/
|
||||||
|
module.exports = async function (context) {
|
||||||
|
if (context.electronPlatformName !== 'win32') return;
|
||||||
|
|
||||||
|
const appOutDir = context.appOutDir;
|
||||||
|
const rootFfmpeg = path.join(appOutDir, 'ffmpeg.dll');
|
||||||
|
const appFfmpeg = path.join(appOutDir, 'resources', 'app', 'ffmpeg.dll');
|
||||||
|
|
||||||
|
if (fs.existsSync(rootFfmpeg)) return; // already in place
|
||||||
|
|
||||||
|
if (fs.existsSync(appFfmpeg)) {
|
||||||
|
fs.copyFileSync(appFfmpeg, rootFfmpeg);
|
||||||
|
}
|
||||||
|
};
|
||||||
+122
@@ -0,0 +1,122 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; frame-src 'self' http: https:; connect-src 'self' http://localhost:*">
|
||||||
|
<title>PTW Auto-Disconnect</title>
|
||||||
|
<style>
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
font-family: sans-serif;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 10px;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
.webview-wrap {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.webview-wrap webview {
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
}
|
||||||
|
.panels {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
gap: 10px;
|
||||||
|
min-height: 0;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
.section-title { font-size: 11px; font-weight: bold; color: #aaa; margin-bottom: 4px; flex-shrink: 0; }
|
||||||
|
#sessionsBox {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
background: rgba(0,0,0,0.6);
|
||||||
|
color: #c0c0c0;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 1px solid #444;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
#sessionsBox .sess-user-block { margin-bottom: 6px; }
|
||||||
|
#sessionsBox .sess-user-name { color: #7eb8da; font-weight: bold; padding: 2px 0 1px 0; border-bottom: 1px solid rgba(255,255,255,0.15); }
|
||||||
|
#sessionsBox .sess-row { padding: 1px 0 1px 10px; font-size: 9px; color: #b5b5b5; }
|
||||||
|
#sessionsBox .sess-product { color: #b5b5b5; }
|
||||||
|
#sessionsBox .empty { color: #777; font-style: italic; }
|
||||||
|
#logBox {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
background: rgba(0,0,0,0.85);
|
||||||
|
color: #00ff00;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 1px solid #444;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
#logBox .empty { color: #777; font-style: italic; }
|
||||||
|
#logBox .entry { border-bottom: 1px solid rgba(255,255,255,0.1); padding: 2px 0; }
|
||||||
|
.controls { display: flex; gap: 8px; flex-shrink: 0; }
|
||||||
|
.controls button {
|
||||||
|
padding: 8px 15px;
|
||||||
|
color: white;
|
||||||
|
border: 1px solid white;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 20px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: bold;
|
||||||
|
background: #333;
|
||||||
|
}
|
||||||
|
.controls button.toggle-on { background: #28a745; }
|
||||||
|
.controls button.toggle-off { background: #dc3545; }
|
||||||
|
.controls button.clear-btn { background: #6c757d; }
|
||||||
|
.status { font-size: 10px; color: #888; margin-top: 6px; flex-shrink: 0; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="webview-wrap">
|
||||||
|
<webview id="wv" src="http://localhost:1947/_int_/config.html" partition="persist:ptw"></webview>
|
||||||
|
</div>
|
||||||
|
<div class="panels">
|
||||||
|
<div class="panel">
|
||||||
|
<div class="section-title">Logged in</div>
|
||||||
|
<div id="sessionsBox"><div class="empty">Loading...</div></div>
|
||||||
|
</div>
|
||||||
|
<div class="panel">
|
||||||
|
<div class="section-title">Activity log</div>
|
||||||
|
<div id="logBox"><div class="empty">Connecting...</div></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<button id="toggleBtn" class="toggle-on">MONITOR: ON</button>
|
||||||
|
<button id="clearBtn" class="clear-btn">Clear</button>
|
||||||
|
</div>
|
||||||
|
<div class="status" id="status">Connected to sessions page</div>
|
||||||
|
<script src="renderer.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// Injected into the webview (sessions page). Runs in that page's context.
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const TARGET_KEYWORDS = [
|
||||||
|
'PTW_DATAEXCHANGE', 'PTW_ARC_FLASH', 'PTW_DEVEVAL', 'PTW_AFAULT',
|
||||||
|
'PTW_DAPPER', 'PTW_COOREVAL', 'PTW_CAPTOR', 'PTW_IEC_FAULT', 'PTW_IEC61363'
|
||||||
|
];
|
||||||
|
|
||||||
|
window.__ptw_logQueue = window.__ptw_logQueue || [];
|
||||||
|
window.__ptw_running = window.__ptw_running !== false;
|
||||||
|
|
||||||
|
function addLog(msg) {
|
||||||
|
const t = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||||
|
window.__ptw_logQueue.push(`[${t}] ${msg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function scanAndDisconnect() {
|
||||||
|
if (!window.__ptw_running) return;
|
||||||
|
const rows = document.querySelectorAll('#mydata table.list tr');
|
||||||
|
rows.forEach(function (row) {
|
||||||
|
const rowText = row.innerText;
|
||||||
|
const hasMatch = TARGET_KEYWORDS.some(function (k) { return rowText.indexOf(k) !== -1; });
|
||||||
|
if (hasMatch) {
|
||||||
|
const disconnectLink = row.querySelector('a.sbutton');
|
||||||
|
if (disconnectLink && disconnectLink.textContent.indexOf('Disconnect') !== -1) {
|
||||||
|
const itemName = (rowText.split('\t')[0] || '').trim() || 'Item';
|
||||||
|
addLog('OUT: ' + itemName);
|
||||||
|
disconnectLink.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__ptw_flushLogs = function () {
|
||||||
|
const q = window.__ptw_logQueue.slice();
|
||||||
|
window.__ptw_logQueue = [];
|
||||||
|
return q;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.__ptw_setRunning = function (v) { window.__ptw_running = !!v; };
|
||||||
|
window.__ptw_getRunning = function () { return window.__ptw_running; };
|
||||||
|
|
||||||
|
/** Returns list of { user, product, feature, machine, loginTime } from #mydata table.list */
|
||||||
|
window.__ptw_getSessions = function () {
|
||||||
|
var out = [];
|
||||||
|
var rows = document.querySelectorAll('#mydata table.list tr');
|
||||||
|
for (var i = 0; i < rows.length; i++) {
|
||||||
|
if (rows[i].classList && rows[i].classList.contains('tableheader')) continue;
|
||||||
|
var cells = rows[i].querySelectorAll('td');
|
||||||
|
if (cells.length < 9) continue;
|
||||||
|
var product = (cells[3] && cells[3].innerText) ? cells[3].innerText.replace(/\s+/g, ' ').trim() : '';
|
||||||
|
var feature = (cells[4] && cells[4].innerText) ? cells[4].innerText.replace(/\s+/g, ' ').trim() : '';
|
||||||
|
var user = (cells[6] && cells[6].innerText) ? cells[6].innerText.trim() : '';
|
||||||
|
var machine = (cells[7] && cells[7].innerText) ? cells[7].innerText.trim() : '';
|
||||||
|
var loginTime = (cells[8] && cells[8].innerText) ? cells[8].innerText.trim() : '';
|
||||||
|
out.push({ user: user, product: product, feature: feature, machine: machine, loginTime: loginTime });
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
var targetNode = document.getElementById('mydata') || document.body;
|
||||||
|
var observer = new MutationObserver(function () { scanAndDisconnect(); });
|
||||||
|
observer.observe(targetNode, { childList: true, subtree: true });
|
||||||
|
addLog('Refreshed');
|
||||||
|
scanAndDisconnect();
|
||||||
|
})();
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
const { app, BrowserWindow, powerSaveBlocker } = require('electron');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function createWindow() {
|
||||||
|
// Keep system and display from sleeping while the app is running
|
||||||
|
powerSaveBlocker.start('prevent-app-suspension');
|
||||||
|
powerSaveBlocker.start('prevent-display-sleep');
|
||||||
|
const win = new BrowserWindow({
|
||||||
|
width: 320,
|
||||||
|
height: 420,
|
||||||
|
minWidth: 280,
|
||||||
|
minHeight: 320,
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
|
contextIsolation: true,
|
||||||
|
nodeIntegration: false,
|
||||||
|
webviewTag: true,
|
||||||
|
},
|
||||||
|
title: 'PTW Auto-Disconnect',
|
||||||
|
show: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
win.once('ready-to-show', () => win.show());
|
||||||
|
win.loadFile('index.html');
|
||||||
|
}
|
||||||
|
|
||||||
|
app.whenReady().then(createWindow);
|
||||||
|
app.on('window-all-closed', () => app.quit());
|
||||||
Generated
+4069
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "ptw-auto-disconnect",
|
||||||
|
"version": "2.1.0",
|
||||||
|
"description": "PTW Auto-Disconnect – compact GUI, no browser window",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron .",
|
||||||
|
"pack": "electron-builder --dir",
|
||||||
|
"dist": "electron-builder",
|
||||||
|
"dist:portable": "npm run dist && powershell -Command \"Compress-Archive -Path 'dist\\win-unpacked\\*' -DestinationPath 'dist\\PTW Auto-Disconnect-no-install.zip' -Force\""
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"appId": "com.ptw.autodisconnect",
|
||||||
|
"productName": "PTW Auto-Disconnect",
|
||||||
|
"directories": { "output": "dist" },
|
||||||
|
"asar": false,
|
||||||
|
"afterPack": "afterPack.js",
|
||||||
|
"win": {
|
||||||
|
"target": ["nsis", "dir", "portable"],
|
||||||
|
"signAndEditExecutable": false,
|
||||||
|
"extraFiles": [
|
||||||
|
{ "from": "node_modules/electron/dist/ffmpeg.dll", "to": "." }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"electron": "^28.0.0",
|
||||||
|
"electron-builder": "^24.9.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// Preload: main window uses no Node APIs; GUI is self-contained in renderer.
|
||||||
+190
@@ -0,0 +1,190 @@
|
|||||||
|
(function () {
|
||||||
|
const CONFIG_URL = 'http://localhost:1947/_int_/config.html';
|
||||||
|
const SESSION_URL = 'http://localhost:1947/_int_/sessions.html';
|
||||||
|
const STORAGE_RUNNING = 'ptw_monitor_running';
|
||||||
|
const STORAGE_LOGS = 'ptw_persistent_logs';
|
||||||
|
const MAX_LOGS = 30;
|
||||||
|
const POLL_MS = 500;
|
||||||
|
const RELOAD_MS = 60000;
|
||||||
|
|
||||||
|
const wv = document.getElementById('wv');
|
||||||
|
const sessionsBox = document.getElementById('sessionsBox');
|
||||||
|
const logBox = document.getElementById('logBox');
|
||||||
|
const toggleBtn = document.getElementById('toggleBtn');
|
||||||
|
const clearBtn = document.getElementById('clearBtn');
|
||||||
|
const statusEl = document.getElementById('status');
|
||||||
|
|
||||||
|
let isRunning = localStorage.getItem(STORAGE_RUNNING) !== 'false';
|
||||||
|
let savedLogs = JSON.parse(localStorage.getItem(STORAGE_LOGS) || '[]');
|
||||||
|
let injectCode = null;
|
||||||
|
let reloadTimer = null;
|
||||||
|
|
||||||
|
function renderSessions(list) {
|
||||||
|
if (!list || list.length === 0) {
|
||||||
|
sessionsBox.innerHTML = "<div class='empty'>No sessions</div>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var byUser = {};
|
||||||
|
list.forEach(function (s) {
|
||||||
|
var u = s.user && s.user.trim() ? s.user.trim() : '(no user)';
|
||||||
|
if (!byUser[u]) byUser[u] = [];
|
||||||
|
byUser[u].push(s);
|
||||||
|
});
|
||||||
|
var users = Object.keys(byUser).sort();
|
||||||
|
var html = [];
|
||||||
|
users.forEach(function (user) {
|
||||||
|
var safeUser = escapeHtml(user);
|
||||||
|
html.push("<div class='sess-user-block'><div class='sess-user-name'>" + safeUser + "</div>");
|
||||||
|
byUser[user].forEach(function (s) {
|
||||||
|
var product = escapeHtml(s.product || '');
|
||||||
|
var feature = escapeHtml(s.feature || '');
|
||||||
|
var detail = (product + (product && feature ? " · " : "") + feature).trim();
|
||||||
|
html.push("<div class='sess-row'>" + (detail ? "<span class='sess-product'>" + detail + "</span>" : "—") + "</div>");
|
||||||
|
});
|
||||||
|
html.push("</div>");
|
||||||
|
});
|
||||||
|
sessionsBox.innerHTML = html.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLogs() {
|
||||||
|
if (savedLogs.length === 0) {
|
||||||
|
logBox.innerHTML = "<div class='empty'>No activity...</div>";
|
||||||
|
} else {
|
||||||
|
logBox.innerHTML = savedLogs.map(function (log) {
|
||||||
|
return "<div class='entry'>" + escapeHtml(log) + '</div>';
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
logBox.scrollTop = logBox.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(s) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = s;
|
||||||
|
return div.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLog(msg) {
|
||||||
|
savedLogs.push(msg);
|
||||||
|
if (savedLogs.length > MAX_LOGS) savedLogs.shift();
|
||||||
|
try { localStorage.setItem(STORAGE_LOGS, JSON.stringify(savedLogs)); } catch (e) {}
|
||||||
|
renderLogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateToggleButton() {
|
||||||
|
toggleBtn.textContent = isRunning ? 'MONITOR: ON' : 'MONITOR: OFF';
|
||||||
|
toggleBtn.className = isRunning ? 'toggle-on' : 'toggle-off';
|
||||||
|
}
|
||||||
|
|
||||||
|
function runInWebview(fn) {
|
||||||
|
if (!wv || !wv.executeJavaScript) return Promise.resolve();
|
||||||
|
try {
|
||||||
|
return wv.executeJavaScript(fn);
|
||||||
|
} catch (e) {
|
||||||
|
return Promise.reject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function injectScript() {
|
||||||
|
if (!injectCode) return Promise.resolve();
|
||||||
|
return runInWebview(injectCode).catch(function (err) {
|
||||||
|
console.warn('Inject failed', err);
|
||||||
|
statusEl.textContent = 'Page may block scripts; check console.';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function startReloadTimer() {
|
||||||
|
stopReloadTimer();
|
||||||
|
if (!isRunning) return;
|
||||||
|
reloadTimer = setInterval(function () {
|
||||||
|
if (!isRunning) return;
|
||||||
|
wv.reload();
|
||||||
|
}, RELOAD_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopReloadTimer() {
|
||||||
|
if (reloadTimer) {
|
||||||
|
clearInterval(reloadTimer);
|
||||||
|
reloadTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureConfigThenSessions() {
|
||||||
|
var url = wv.getURL() || '';
|
||||||
|
if (url.indexOf('config.html') === -1) return;
|
||||||
|
statusEl.textContent = 'Checking config (rows per page)...';
|
||||||
|
runInWebview(
|
||||||
|
"(function(){ var el = document.getElementById('linesperpage'); if (!el) return { submitted: false, status: 'notfound' }; if (el.value === '100') return { submitted: false, status: 'already100' }; el.value = '100'; var btn = document.querySelector('a.confbutton[href*=\"doSubmitConfigUrl\"]'); if (btn) btn.click(); return { submitted: true, status: 'set' }; })()"
|
||||||
|
).then(function (result) {
|
||||||
|
if (result && result.status === 'already100') addLog('Config: rows per page already 100');
|
||||||
|
else if (result && result.submitted) addLog('Config: rows per page set to 100');
|
||||||
|
else if (result && result.status === 'notfound') addLog('Config: rows-per-page input not found');
|
||||||
|
var delay = (result && result.submitted) ? 2500 : 600;
|
||||||
|
setTimeout(function () {
|
||||||
|
wv.src = SESSION_URL;
|
||||||
|
}, delay);
|
||||||
|
}).catch(function () {
|
||||||
|
setTimeout(function () { wv.src = SESSION_URL; }, 500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
wv.addEventListener('did-finish-load', function () {
|
||||||
|
var url = wv.getURL() || '';
|
||||||
|
if (url.indexOf('config.html') !== -1) {
|
||||||
|
ensureConfigThenSessions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (url.indexOf('sessions.html') === -1) return;
|
||||||
|
statusEl.textContent = 'Connected: ' + SESSION_URL;
|
||||||
|
injectScript().then(function () {
|
||||||
|
return runInWebview("window.__ptw_setRunning(" + isRunning + ")");
|
||||||
|
}).then(function () {
|
||||||
|
if (isRunning) addLog('Refreshed');
|
||||||
|
}).catch(function () {});
|
||||||
|
});
|
||||||
|
|
||||||
|
wv.addEventListener('did-fail-load', function (e) {
|
||||||
|
if (e.errorCode !== -3) statusEl.textContent = 'Load failed: ' + (e.errorDescription || 'check if server is running');
|
||||||
|
});
|
||||||
|
|
||||||
|
setInterval(function () {
|
||||||
|
runInWebview("(window.__ptw_flushLogs && window.__ptw_flushLogs()) || []").then(function (logs) {
|
||||||
|
if (Array.isArray(logs) && logs.length) logs.forEach(addLog);
|
||||||
|
}).catch(function () {});
|
||||||
|
runInWebview("(window.__ptw_getSessions && window.__ptw_getSessions()) || []").then(function (sessions) {
|
||||||
|
if (Array.isArray(sessions)) renderSessions(sessions);
|
||||||
|
}).catch(function () {});
|
||||||
|
}, POLL_MS);
|
||||||
|
|
||||||
|
toggleBtn.addEventListener('click', function () {
|
||||||
|
isRunning = !isRunning;
|
||||||
|
try { localStorage.setItem(STORAGE_RUNNING, isRunning); } catch (e) {}
|
||||||
|
updateToggleButton();
|
||||||
|
addLog(isRunning ? 'Resumed' : 'Paused');
|
||||||
|
runInWebview("window.__ptw_setRunning(" + isRunning + ")").catch(function () {});
|
||||||
|
if (isRunning) {
|
||||||
|
wv.reload();
|
||||||
|
startReloadTimer();
|
||||||
|
} else {
|
||||||
|
stopReloadTimer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
clearBtn.addEventListener('click', function () {
|
||||||
|
savedLogs = [];
|
||||||
|
try { localStorage.removeItem(STORAGE_LOGS); } catch (e) {}
|
||||||
|
renderLogs();
|
||||||
|
});
|
||||||
|
|
||||||
|
clearBtn.classList.add('clear-btn');
|
||||||
|
updateToggleButton();
|
||||||
|
renderLogs();
|
||||||
|
|
||||||
|
if (isRunning) startReloadTimer();
|
||||||
|
|
||||||
|
fetch('inject.js').then(function (r) { return r.text(); }).then(function (code) {
|
||||||
|
injectCode = code;
|
||||||
|
if (wv.getURL() && wv.getURL().indexOf('localhost') !== -1) injectScript();
|
||||||
|
}).catch(function () {
|
||||||
|
statusEl.textContent = 'Could not load inject.js';
|
||||||
|
});
|
||||||
|
})();
|
||||||
Reference in new issue
Block a user