lightman-agent 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightman-agent",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "LIGHTMAN Agent - System-level daemon for museum display machines",
5
5
  "private": false,
6
6
  "type": "module",
@@ -13,10 +13,11 @@ REM 5. Launches Chrome fullscreen
13
13
  REM 6. If Chrome crashes, relaunches in 3 seconds (infinite loop)
14
14
  REM ================================================================
15
15
 
16
- set INSTALL_DIR=C:\Program Files\Lightman\Agent
17
- set CONFIG_FILE=%INSTALL_DIR%\agent.config.json
18
- set CHROME_DATA=C:\ProgramData\Lightman\chrome-kiosk
19
- set LOG_FILE=C:\ProgramData\Lightman\logs\shell.log
16
+ set INSTALL_DIR=C:\Program Files\Lightman\Agent
17
+ set CONFIG_FILE=%INSTALL_DIR%\agent.config.json
18
+ set URL_SIDECAR=C:\ProgramData\Lightman\kiosk-url.txt
19
+ set CHROME_DATA=C:\ProgramData\Lightman\chrome-kiosk
20
+ set LOG_FILE=C:\ProgramData\Lightman\logs\shell.log
20
21
 
21
22
  REM Ensure directories exist
22
23
  if not exist "C:\ProgramData\Lightman\logs" mkdir "C:\ProgramData\Lightman\logs"
@@ -59,14 +60,23 @@ if exist "%CONFIG_FILE%" (
59
60
 
60
61
  :use_fallbacks
61
62
 
62
- REM Build URL from slug (ALWAYS from config, never from sidecar)
63
- if not "%DEVICE_SLUG%"=="" (
64
- set URL=http://localhost:3403/display/%DEVICE_SLUG%
65
- echo [%date% %time%] Slug: %DEVICE_SLUG% >> "%LOG_FILE%"
66
- ) else (
67
- set URL=http://localhost:3403/display
68
- echo [%date% %time%] WARNING: No slug in config! >> "%LOG_FILE%"
69
- )
63
+ REM Build URL from slug (ALWAYS from config, never from sidecar)
64
+ if not "%DEVICE_SLUG%"=="" (
65
+ set URL=http://localhost:3403/display/%DEVICE_SLUG%
66
+ echo [%date% %time%] Slug: %DEVICE_SLUG% >> "%LOG_FILE%"
67
+ ) else (
68
+ set URL=http://localhost:3403/display
69
+ echo [%date% %time%] WARNING: No slug in config! >> "%LOG_FILE%"
70
+ )
71
+
72
+ REM If agent wrote a URL sidecar (includes deviceId/apiKey), prefer it.
73
+ if exist "%URL_SIDECAR%" (
74
+ for /f "usebackq delims=" %%u in ("%URL_SIDECAR%") do set SIDE_URL=%%u
75
+ if not "%SIDE_URL%"=="" (
76
+ set URL=%SIDE_URL%
77
+ echo [%date% %time%] Using sidecar URL >> "%LOG_FILE%"
78
+ )
79
+ )
70
80
 
71
81
  REM Fallback browser
72
82
  if "%BROWSER%"=="" (
@@ -108,15 +118,22 @@ echo [%date% %time%] Agent ready >> "%LOG_FILE%"
108
118
  REM ----------------------------------------------------------------
109
119
  REM Infinite Chrome loop
110
120
  REM ----------------------------------------------------------------
111
- :loop
112
- REM Re-read slug from config on every loop iteration
113
- REM This way if someone changes agent.config.json, the next
114
- REM Chrome restart picks up the new slug automatically.
115
- if exist "%CONFIG_FILE%" (
116
- for /f "delims=" %%a in ('node -e "try{console.log(JSON.parse(require('fs').readFileSync(String.raw`%CONFIG_FILE%`,'utf8')).deviceSlug)}catch(e){console.log('')}" 2^>nul') do (
117
- if not "%%a"=="" set URL=http://localhost:3403/display/%%a
118
- )
119
- )
121
+ :loop
122
+ REM Prefer sidecar URL for auth params/device routing; fallback to slug URL.
123
+ set SIDE_URL=
124
+ if exist "%URL_SIDECAR%" (
125
+ for /f "usebackq delims=" %%u in ("%URL_SIDECAR%") do set SIDE_URL=%%u
126
+ )
127
+ if not "%SIDE_URL%"=="" (
128
+ set URL=%SIDE_URL%
129
+ ) else (
130
+ REM Re-read slug from config on every loop iteration.
131
+ if exist "%CONFIG_FILE%" (
132
+ for /f "delims=" %%a in ('node -e "try{console.log(JSON.parse(require('fs').readFileSync(String.raw`%CONFIG_FILE%`,'utf8')).deviceSlug)}catch(e){console.log('')}" 2^>nul') do (
133
+ if not "%%a"=="" set URL=http://localhost:3403/display/%%a
134
+ )
135
+ )
136
+ )
120
137
 
121
138
  echo [%date% %time%] Launching Chrome: %URL% >> "%LOG_FILE%"
122
139
 
@@ -169,17 +169,19 @@ export class KioskManager {
169
169
  // Shell Mode Methods
170
170
  // =====================================================================
171
171
 
172
- private async shellLaunch(targetUrl: string): Promise<KioskStatus> {
173
- this.currentUrl = targetUrl;
174
-
175
- // Shell mode: Chrome is managed by lightman-shell.bat.
176
- // Shell reads slug from agent.config.json directly.
177
- // Agent NEVER kills Chrome on startup - only on explicit navigate().
178
- if (this.isChromeRunning()) {
179
- this.logger.info('Shell mode: Chrome already running. Not touching it.');
180
- } else {
181
- this.logger.info('Shell mode: Chrome not running. Shell BAT will launch it.');
182
- }
172
+ private async shellLaunch(targetUrl: string): Promise<KioskStatus> {
173
+ this.currentUrl = targetUrl;
174
+ // Keep shell sidecar updated so shell BAT can launch with auth query params.
175
+ this.writeUrlSidecar(targetUrl);
176
+
177
+ // Shell mode: Chrome is managed by lightman-shell.bat.
178
+ // Shell prefers sidecar URL (if present), then falls back to slug in config.
179
+ if (this.isChromeRunning()) {
180
+ this.logger.info('Shell mode: Chrome already running. Restarting once to apply sidecar URL.');
181
+ this.killAllChrome();
182
+ } else {
183
+ this.logger.info('Shell mode: Chrome not running. Shell BAT will launch it.');
184
+ }
183
185
 
184
186
  this.startedAt = this.startedAt || Date.now();
185
187
  return this.getStatus();