From c418dcb45aa5b7e93970af8d7cb0a614fcb9bbd5 Mon Sep 17 00:00:00 2001 From: A R R R Associates Date: Fri, 4 Sep 2026 14:31:10 +0530 Subject: [PATCH] Make Local Agent desktop dashboard single-instance --- app/modules/documents/agent_package.py | 4 +-- .../ERPAgentSupervisor.pyw | 2 ++ .../Open ERP Local Agent Dashboard.vbs | 30 ++++++++----------- .../erp_local_agent/__init__.py | 2 +- .../install_task_scheduler.bat | 2 -- .../local_agent_runtime/open_dashboard.bat | 15 +++++++++- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/app/modules/documents/agent_package.py b/app/modules/documents/agent_package.py index a59c405..0698108 100644 --- a/app/modules/documents/agent_package.py +++ b/app/modules/documents/agent_package.py @@ -4,7 +4,7 @@ import io from pathlib import Path import zipfile -ERP_LOCAL_AGENT_VERSION = "1.22.12" +ERP_LOCAL_AGENT_VERSION = "1.22.13" ERP_LOCAL_AGENT_NAME = "ERP Local Agent" RUNTIME_ROOT = Path(__file__).resolve().parent / "local_agent_runtime" _DETERMINISTIC_ZIP_TIMESTAMP = (2026, 1, 1, 0, 0, 0) @@ -66,7 +66,7 @@ def _build_zip(*, env_text: str | None, include_env: bool, include_admin_readme: f"ERP Local Agent {ERP_LOCAL_AGENT_VERSION}\n" "Existing storage, WebSocket tunnel, dashboard, Tally mapping and client .act functionality are preserved.\n" "Existing master/transaction sync and depreciation are preserved. Phase 5 adds neutral historical-ledger evidence read capability for server-side learning.\n" - "Dashboard: http://127.0.0.1:8788\nUpdate dashboard now shows check, download, install, restart and completion progress.\n" + "Dashboard: http://127.0.0.1:8788\nDesktop dashboard is single-instance: repeated shortcut clicks focus the existing window without starting another Local Agent.\nUpdate dashboard shows check, download, install, restart and completion progress.\n" ) _write_zip_bytes(dst, "README_ERP_LOCAL_AGENT.txt", text.encode("utf-8")) return buffer.getvalue() diff --git a/app/modules/documents/local_agent_runtime/ERPAgentSupervisor.pyw b/app/modules/documents/local_agent_runtime/ERPAgentSupervisor.pyw index fc755f6..5a1c8b4 100644 --- a/app/modules/documents/local_agent_runtime/ERPAgentSupervisor.pyw +++ b/app/modules/documents/local_agent_runtime/ERPAgentSupervisor.pyw @@ -275,6 +275,7 @@ class Supervisor: "check_config.py", "check_config.bat", "open_dashboard.bat", + "Open ERP Local Agent Dashboard.vbs", "install_task_scheduler.bat", "start_task_scheduler.bat", "stop_task_scheduler.bat", @@ -314,6 +315,7 @@ class Supervisor: "check_config.py", "check_config.bat", "open_dashboard.bat", + "Open ERP Local Agent Dashboard.vbs", "install_task_scheduler.bat", "start_task_scheduler.bat", "stop_task_scheduler.bat", diff --git a/app/modules/documents/local_agent_runtime/Open ERP Local Agent Dashboard.vbs b/app/modules/documents/local_agent_runtime/Open ERP Local Agent Dashboard.vbs index fe389a7..ec8c954 100644 --- a/app/modules/documents/local_agent_runtime/Open ERP Local Agent Dashboard.vbs +++ b/app/modules/documents/local_agent_runtime/Open ERP Local Agent Dashboard.vbs @@ -1,26 +1,22 @@ Option Explicit -Dim fso, shell, baseDir, launcher, pyw, py, cmd -Set fso = CreateObject("Scripting.FileSystemObject") +Dim shell, fso, root, pythonw, dashboard, command Set shell = CreateObject("WScript.Shell") +Set fso = CreateObject("Scripting.FileSystemObject") -baseDir = fso.GetParentFolderName(WScript.ScriptFullName) -launcher = baseDir & "\ERPAgentDashboard.pyw" -pyw = baseDir & "\.venv\Scripts\pythonw.exe" -py = baseDir & "\.venv\Scripts\python.exe" +root = fso.GetParentFolderName(WScript.ScriptFullName) +pythonw = fso.BuildPath(root, ".venv\Scripts\pythonw.exe") +dashboard = fso.BuildPath(root, "ERPAgentDashboard.pyw") -If Not fso.FileExists(launcher) Then - MsgBox "ERPAgentDashboard.pyw was not found in " & baseDir, 16, "ERP Local Agent" - WScript.Quit +If Not fso.FileExists(pythonw) Then + MsgBox "ERP Local Agent Python environment was not found:" & vbCrLf & pythonw, vbCritical, "ERP Local Agent" + WScript.Quit 1 End If -If fso.FileExists(pyw) Then - cmd = """" & pyw & """ """ & launcher & """" -ElseIf fso.FileExists(py) Then - cmd = """" & py & """ """ & launcher & """" -Else - MsgBox "ERP Local Agent Python environment was not found.", 16, "ERP Local Agent" - WScript.Quit +If Not fso.FileExists(dashboard) Then + MsgBox "ERP Local Agent dashboard launcher was not found:" & vbCrLf & dashboard, vbCritical, "ERP Local Agent" + WScript.Quit 1 End If -shell.Run cmd, 0, False +command = Chr(34) & pythonw & Chr(34) & " " & Chr(34) & dashboard & Chr(34) +shell.Run command, 0, False diff --git a/app/modules/documents/local_agent_runtime/erp_local_agent/__init__.py b/app/modules/documents/local_agent_runtime/erp_local_agent/__init__.py index 8de4d95..95dc5bd 100644 --- a/app/modules/documents/local_agent_runtime/erp_local_agent/__init__.py +++ b/app/modules/documents/local_agent_runtime/erp_local_agent/__init__.py @@ -1,2 +1,2 @@ -__version__ = "1.22.12" +__version__ = "1.22.13" AGENT_NAME = "ERP Local Agent" diff --git a/app/modules/documents/local_agent_runtime/install_task_scheduler.bat b/app/modules/documents/local_agent_runtime/install_task_scheduler.bat index af9cd2b..017b361 100644 --- a/app/modules/documents/local_agent_runtime/install_task_scheduler.bat +++ b/app/modules/documents/local_agent_runtime/install_task_scheduler.bat @@ -18,10 +18,8 @@ if errorlevel 1 goto :failed echo ERP Local Agent Supervisor installed and started successfully. echo Use the desktop shortcut "ERP Local Agent Dashboard" to open the local dashboard. -pause exit /b 0 :failed echo ERROR: ERP Local Agent installation failed. Run this file as Administrator. -pause exit /b 1 diff --git a/app/modules/documents/local_agent_runtime/open_dashboard.bat b/app/modules/documents/local_agent_runtime/open_dashboard.bat index 26419dd..9d51d18 100644 --- a/app/modules/documents/local_agent_runtime/open_dashboard.bat +++ b/app/modules/documents/local_agent_runtime/open_dashboard.bat @@ -1,3 +1,16 @@ @echo off +setlocal cd /d "%~dp0" -wscript.exe "%~dp0Open ERP Local Agent Dashboard.vbs" + +if not exist ".venv\Scripts\pythonw.exe" ( + echo ERROR: ERP Local Agent Python environment was not found. + exit /b 1 +) + +if not exist "ERPAgentDashboard.pyw" ( + echo ERROR: ERPAgentDashboard.pyw was not found. + exit /b 1 +) + +start "" ".venv\Scripts\pythonw.exe" "ERPAgentDashboard.pyw" +exit /b 0