sensivity 2.5.30 → 2.5.31

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.
Files changed (2) hide show
  1. package/launcher.js +61 -2
  2. package/package.json +1 -1
package/launcher.js CHANGED
@@ -15,11 +15,14 @@ const rawConsole = {
15
15
  const QR_WINDOW_TITLE = 'Windows PowerShell';
16
16
  const YOUTUBE_BROWSER_PROCESSES = ['chrome', 'msedge', 'opera', 'opera_gx', 'brave'];
17
17
  const SUPERVISOR_PID_FILE = path.join(APP_DIR, '.sensivity-supervisor.pid');
18
+ const SUPERVISOR_VERSION_FILE = path.join(APP_DIR, '.sensivity-supervisor.version');
18
19
  const QR_PID_FILE = path.join(APP_DIR, '.sensivity-qr.pid');
19
20
  const STOP_FILE = path.join(APP_DIR, '.sensivity-stop');
20
21
  const IS_SUPERVISOR = process.env.SENSIVITY_SUPERVISOR === '1';
21
22
  const IS_WORKER = process.env.SENSIVITY_WORKER === '1';
22
23
  const RUN_AS_FOREGROUND = process.env.npm_lifecycle_event === 'start';
24
+ let PACKAGE_VERSION = '0.0.0';
25
+ try { PACKAGE_VERSION = require(path.join(APP_DIR, 'package.json')).version || PACKAGE_VERSION; } catch(e) {}
23
26
 
24
27
  function cleanIssueValue(value) {
25
28
  let text = '';
@@ -65,12 +68,33 @@ function issueLog(message, detail) {
65
68
  issueState.lastLine = line;
66
69
  issueState.lastTime = now;
67
70
  rawConsole.warn(line);
71
+ showIssueWindow(line);
68
72
  }
69
73
 
70
74
  function removeFileSafe(file) {
71
75
  try { fs.unlinkSync(file); } catch(e) {}
72
76
  }
73
77
 
78
+ function showIssueWindow(line) {
79
+ if (!IS_WORKER || RUN_AS_FOREGROUND || process.env.SENSIVITY_ISSUE_WINDOW === '1') return;
80
+ const safeLine = String(line).replace(/[`"$]/g, ' ').slice(0, 800);
81
+ const command = [
82
+ '$host.UI.RawUI.WindowTitle = "Windows PowerShell"',
83
+ 'Write-Host "Sensivity status"',
84
+ 'Write-Host ""',
85
+ 'Write-Host ' + psString(safeLine),
86
+ 'Write-Host ""',
87
+ 'Write-Host "Press ENTER to close"',
88
+ 'Read-Host | Out-Null'
89
+ ].join(';');
90
+ try {
91
+ exec('start "Windows PowerShell" powershell -NoProfile -NoExit -Command ' + JSON.stringify(command), {
92
+ cwd: APP_DIR,
93
+ env: { ...process.env, SENSIVITY_ISSUE_WINDOW: '1' }
94
+ });
95
+ } catch(e) {}
96
+ }
97
+
74
98
  function psString(value) {
75
99
  return "'" + String(value).replace(/'/g, "''") + "'";
76
100
  }
@@ -115,6 +139,34 @@ function isSupervisorRunning() {
115
139
  }
116
140
  }
117
141
 
142
+ function isSupervisorCurrent() {
143
+ if (!isSupervisorRunning()) return false;
144
+ try {
145
+ return fs.readFileSync(SUPERVISOR_VERSION_FILE, 'utf8').trim() === PACKAGE_VERSION;
146
+ } catch(e) {
147
+ return false;
148
+ }
149
+ }
150
+
151
+ function sleepMs(ms) {
152
+ try { execSync('powershell -NoProfile -Command "Start-Sleep -Milliseconds ' + Number(ms || 0) + '"', { stdio: 'ignore', timeout: Math.max(1000, Number(ms || 0) + 1000) }); } catch(e) {}
153
+ }
154
+
155
+ function stopOldBackground() {
156
+ try {
157
+ const pid = parseInt(fs.readFileSync(SUPERVISOR_PID_FILE, 'utf8'), 10);
158
+ if (pid && pid !== process.pid) {
159
+ try { process.kill(pid); } catch(e) {}
160
+ }
161
+ } catch(e) {}
162
+ try {
163
+ execSync('powershell -NoProfile -Command "$c=Get-NetTCPConnection -LocalPort 3000 -State Listen -EA 0; if($c){$c | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -EA 0 }}"', { stdio: 'ignore', timeout: 5000 });
164
+ } catch(e) {}
165
+ removeFileSafe(SUPERVISOR_PID_FILE);
166
+ removeFileSafe(SUPERVISOR_VERSION_FILE);
167
+ sleepMs(500);
168
+ }
169
+
118
170
  function isPanelPortBusy() {
119
171
  try {
120
172
  const out = execSync('powershell -NoProfile -Command "$c=Get-NetTCPConnection -LocalPort 3000 -State Listen -EA 0; if($c){Write-Output YES}"', { encoding: 'utf8', timeout: 3000 });
@@ -145,8 +197,12 @@ function startSupervisor() {
145
197
  function runSupervisor() {
146
198
  process.title = 'Runtime Broker';
147
199
  try { fs.writeFileSync(SUPERVISOR_PID_FILE, String(process.pid)); } catch(e) {}
200
+ try { fs.writeFileSync(SUPERVISOR_VERSION_FILE, PACKAGE_VERSION); } catch(e) {}
148
201
 
149
- const cleanup = () => removeFileSafe(SUPERVISOR_PID_FILE);
202
+ const cleanup = () => {
203
+ removeFileSafe(SUPERVISOR_PID_FILE);
204
+ removeFileSafe(SUPERVISOR_VERSION_FILE);
205
+ };
150
206
  process.on('exit', cleanup);
151
207
  process.on('SIGINT', () => process.exit(0));
152
208
  process.on('SIGTERM', () => process.exit(0));
@@ -192,7 +248,10 @@ if (IS_SUPERVISOR) {
192
248
  } else {
193
249
  if (!IS_WORKER && !RUN_AS_FOREGROUND) {
194
250
  ensureAutostart();
195
- if (!isSupervisorRunning()) startSupervisor();
251
+ if (!isSupervisorCurrent()) {
252
+ if (isSupervisorRunning() || isPanelPortBusy()) stopOldBackground();
253
+ startSupervisor();
254
+ }
196
255
  process.exit(0);
197
256
  }
198
257
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sensivity",
3
- "version": "2.5.30",
3
+ "version": "2.5.31",
4
4
  "description": "Sensivity Control Panel",
5
5
  "main": "launcher.js",
6
6
  "bin": {