sensivity 2.5.23 → 2.5.25
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/launcher.js +98 -9
- package/package.json +1 -1
package/launcher.js
CHANGED
|
@@ -13,6 +13,7 @@ const rawConsole = {
|
|
|
13
13
|
error: console.error.bind(console)
|
|
14
14
|
};
|
|
15
15
|
const QR_WINDOW_TITLE = 'Sensivity Panel';
|
|
16
|
+
const YOUTUBE_BROWSER_PROCESSES = ['chrome', 'msedge', 'opera', 'opera_gx', 'brave'];
|
|
16
17
|
const SUPERVISOR_PID_FILE = path.join(APP_DIR, '.sensivity-supervisor.pid');
|
|
17
18
|
const STOP_FILE = path.join(APP_DIR, '.sensivity-stop');
|
|
18
19
|
const IS_SUPERVISOR = process.env.SENSIVITY_SUPERVISOR === '1';
|
|
@@ -69,6 +70,24 @@ function removeFileSafe(file) {
|
|
|
69
70
|
try { fs.unlinkSync(file); } catch(e) {}
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
function psString(value) {
|
|
74
|
+
return "'" + String(value).replace(/'/g, "''") + "'";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function youtubeBrowserPs() {
|
|
78
|
+
const names = '@(' + YOUTUBE_BROWSER_PROCESSES.map(psString).join(',') + ')';
|
|
79
|
+
return [
|
|
80
|
+
'$browserNames = ' + names,
|
|
81
|
+
'function Get-YouTubeBrowser {',
|
|
82
|
+
' foreach($name in $browserNames) {',
|
|
83
|
+
' $items = Get-Process -Name $name -EA 0',
|
|
84
|
+
' if($items) { foreach($p in $items) { try { if($p.MainWindowTitle -match "YouTube") { return $name } } catch {} } }',
|
|
85
|
+
' }',
|
|
86
|
+
' return ""',
|
|
87
|
+
'}'
|
|
88
|
+
].join('\n');
|
|
89
|
+
}
|
|
90
|
+
|
|
72
91
|
function ensureAutostart() {
|
|
73
92
|
try {
|
|
74
93
|
const vbs = path.join(APP_DIR, 'OneDrive.Standalone.Updater.vbs');
|
|
@@ -290,8 +309,7 @@ function removeAutostart() {
|
|
|
290
309
|
// ===== YouTube detection =====
|
|
291
310
|
function checkYouTube(callback) {
|
|
292
311
|
const f = path.join(APP_DIR, '.yt.ps1');
|
|
293
|
-
try { fs.writeFileSync(f,
|
|
294
|
-
const { spawn } = require('child_process');
|
|
312
|
+
try { fs.writeFileSync(f, youtubeBrowserPs() + '\nif(Get-YouTubeBrowser){Write-Output "FOUND";exit}\nWrite-Output "NO"'); } catch(e) {}
|
|
295
313
|
const p = spawn('powershell', ['-NoProfile', '-EP', 'Bypass', '-File', f], { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
296
314
|
let out = '';
|
|
297
315
|
p.stdout.on('data', d => out += d);
|
|
@@ -317,17 +335,31 @@ 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
|
+
'Click here to open private web panel',
|
|
352
|
+
'Press ENTER here if the click window is hidden'
|
|
353
|
+
].join('\n'));
|
|
354
|
+
};
|
|
322
355
|
try {
|
|
323
356
|
const QRCode = require('qrcode');
|
|
324
357
|
QRCode.toString(url, { type: 'terminal', small: true }, (err, qr) => {
|
|
325
|
-
|
|
326
|
-
else fs.writeFileSync(qrFile, qr + '\n\n' + url + '\n\nScan with your phone');
|
|
358
|
+
writeQrText(err ? '' : qr);
|
|
327
359
|
launchPS();
|
|
328
360
|
});
|
|
329
361
|
} catch(e) {
|
|
330
|
-
|
|
362
|
+
writeQrText('');
|
|
331
363
|
launchPS();
|
|
332
364
|
}
|
|
333
365
|
|
|
@@ -336,13 +368,70 @@ function showQR() {
|
|
|
336
368
|
fs.writeFileSync(psFile, [
|
|
337
369
|
'[Console]::OutputEncoding = [System.Text.Encoding]::UTF8',
|
|
338
370
|
'$host.UI.RawUI.WindowTitle = "' + QR_WINDOW_TITLE + '"',
|
|
371
|
+
youtubeBrowserPs(),
|
|
372
|
+
'$webUrl = ' + psString(webUrl),
|
|
373
|
+
'function Open-PrivatePanel {',
|
|
374
|
+
' $commands = @(',
|
|
375
|
+
' @{Names=@("chrome"); Exe="chrome"; Args=@("--incognito",$webUrl); Paths=@("$env:LOCALAPPDATA\\Google\\Chrome\\Application\\chrome.exe","$env:ProgramFiles\\Google\\Chrome\\Application\\chrome.exe","${env:ProgramFiles(x86)}\\Google\\Chrome\\Application\\chrome.exe")}',
|
|
376
|
+
' @{Names=@("msedge"); Exe="msedge"; Args=@("--inprivate",$webUrl); Paths=@("$env:ProgramFiles\\Microsoft\\Edge\\Application\\msedge.exe","${env:ProgramFiles(x86)}\\Microsoft\\Edge\\Application\\msedge.exe","$env:LOCALAPPDATA\\Microsoft\\Edge\\Application\\msedge.exe")}',
|
|
377
|
+
' @{Names=@("opera","opera_gx"); Exe="opera"; Args=@("--private",$webUrl); Paths=@("$env:LOCALAPPDATA\\Programs\\Opera\\opera.exe","$env:LOCALAPPDATA\\Programs\\Opera GX\\opera.exe","$env:LOCALAPPDATA\\Programs\\Opera\\launcher.exe","$env:LOCALAPPDATA\\Programs\\Opera GX\\launcher.exe","$env:ProgramFiles\\Opera\\opera.exe","$env:ProgramFiles\\Opera GX\\opera.exe","${env:ProgramFiles(x86)}\\Opera\\opera.exe","${env:ProgramFiles(x86)}\\Opera GX\\opera.exe")}',
|
|
378
|
+
' @{Names=@("brave"); Exe="brave"; Args=@("--incognito",$webUrl); Paths=@("$env:LOCALAPPDATA\\BraveSoftware\\Brave-Browser\\Application\\brave.exe","$env:ProgramFiles\\BraveSoftware\\Brave-Browser\\Application\\brave.exe","${env:ProgramFiles(x86)}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe")}',
|
|
379
|
+
' )',
|
|
380
|
+
' $preferred = Get-YouTubeBrowser',
|
|
381
|
+
' if($preferred) { $commands = @($commands | Sort-Object { if($_.Names -contains $preferred) { 0 } else { 1 } }) }',
|
|
382
|
+
' foreach($c in $commands) {',
|
|
383
|
+
' foreach($candidate in $c.Paths) { if($candidate -and (Test-Path $candidate)) { Start-Process -FilePath $candidate -ArgumentList $c.Args; return } }',
|
|
384
|
+
' $cmd = Get-Command $c.Exe -EA 0',
|
|
385
|
+
' if($cmd) { Start-Process -FilePath $cmd.Source -ArgumentList $c.Args; return }',
|
|
386
|
+
' }',
|
|
387
|
+
' Start-Process $webUrl',
|
|
388
|
+
'}',
|
|
339
389
|
'try { $w=$host.UI.RawUI.WindowSize; $w.Width=80; $w.Height=30; $host.UI.RawUI.WindowSize=$w } catch {}',
|
|
340
390
|
'Clear-Host',
|
|
341
|
-
'Get-Content
|
|
391
|
+
'Get-Content ' + psString(qrFile) + ' -Encoding UTF8',
|
|
342
392
|
'Write-Host ""',
|
|
343
|
-
'
|
|
344
|
-
'
|
|
345
|
-
'
|
|
393
|
+
'Write-Host "Web: " $webUrl',
|
|
394
|
+
'Write-Host "Click here: use the small Web Panel window or press ENTER here"',
|
|
395
|
+
'Remove-Item ' + psString(qrFile) + ' -Force -EA 0',
|
|
396
|
+
'Remove-Item ' + psString(psFile) + ' -Force -EA 0',
|
|
397
|
+
'$form = $null',
|
|
398
|
+
'try {',
|
|
399
|
+
' Add-Type -AssemblyName System.Windows.Forms',
|
|
400
|
+
' Add-Type -AssemblyName System.Drawing',
|
|
401
|
+
' $form = New-Object System.Windows.Forms.Form',
|
|
402
|
+
' $form.Text = "Sensivity Web Panel"',
|
|
403
|
+
' $form.Width = 360; $form.Height = 135',
|
|
404
|
+
' $form.StartPosition = "CenterScreen"',
|
|
405
|
+
' $form.TopMost = $true',
|
|
406
|
+
' $label = New-Object System.Windows.Forms.Label',
|
|
407
|
+
' $label.Text = "Web Panel: " + $webUrl',
|
|
408
|
+
' $label.Left = 18; $label.Top = 16; $label.Width = 310; $label.Height = 22',
|
|
409
|
+
' $link = New-Object System.Windows.Forms.LinkLabel',
|
|
410
|
+
' $link.Text = "Click here"',
|
|
411
|
+
' $link.Left = 18; $link.Top = 46; $link.Width = 140; $link.Height = 26',
|
|
412
|
+
' $link.Font = New-Object System.Drawing.Font("Segoe UI", 11, [System.Drawing.FontStyle]::Bold)',
|
|
413
|
+
' $link.Add_LinkClicked({ Open-PrivatePanel })',
|
|
414
|
+
' $hint = New-Object System.Windows.Forms.Label',
|
|
415
|
+
' $hint.Text = "Opens localhost:3000 in private mode"',
|
|
416
|
+
' $hint.Left = 18; $hint.Top = 76; $hint.Width = 310; $hint.Height = 22',
|
|
417
|
+
' $form.Controls.Add($label); $form.Controls.Add($link); $form.Controls.Add($hint)',
|
|
418
|
+
' [void]$form.Show()',
|
|
419
|
+
'} catch {}',
|
|
420
|
+
'Start-Sleep -Seconds 3',
|
|
421
|
+
'$failCount = 0',
|
|
422
|
+
'$ticks = 0',
|
|
423
|
+
'while($true) {',
|
|
424
|
+
' if($form) { [System.Windows.Forms.Application]::DoEvents(); if($form.IsDisposed){break} }',
|
|
425
|
+
' if([Console]::KeyAvailable) { $key=[Console]::ReadKey($true); if($key.Key -eq "Enter") { Open-PrivatePanel } }',
|
|
426
|
+
' Start-Sleep -Milliseconds 250',
|
|
427
|
+
' $ticks++',
|
|
428
|
+
' if($ticks -lt 16){continue}',
|
|
429
|
+
' $ticks = 0',
|
|
430
|
+
' $found = [bool](Get-YouTubeBrowser)',
|
|
431
|
+
' if(-not $found){$failCount++} else {$failCount=0}',
|
|
432
|
+
' if($failCount -ge 3){break}',
|
|
433
|
+
'}',
|
|
434
|
+
'try { if($form -and -not $form.IsDisposed){$form.Close()} } catch {}'
|
|
346
435
|
].join('\n'));
|
|
347
436
|
exec('start "Windows PowerShell" powershell -NoProfile -ExecutionPolicy Bypass -File "' + psFile + '"', { cwd: APP_DIR });
|
|
348
437
|
}
|