@yeaft/webchat-agent 0.0.6 → 0.0.8

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/package.json +1 -1
  2. package/service.js +47 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/service.js CHANGED
@@ -406,13 +406,35 @@ function winInstall(config) {
406
406
  try { execSync(`schtasks /delete /tn "${WIN_TASK_NAME}" /f 2>nul`, { stdio: 'pipe' }); } catch {}
407
407
 
408
408
  // Create scheduled task that runs at logon
409
- execSync(
410
- `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl highest /f`,
411
- { stdio: 'pipe' }
412
- );
409
+ // Try schtasks first (highest → limited), fall back to Startup folder
410
+ let usedStartupFolder = false;
411
+ try {
412
+ execSync(
413
+ `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl highest /f`,
414
+ { stdio: 'pipe' }
415
+ );
416
+ } catch {
417
+ try {
418
+ execSync(
419
+ `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl limited /f`,
420
+ { stdio: 'pipe' }
421
+ );
422
+ } catch {
423
+ // schtasks not available (no admin) — use Startup folder
424
+ const startupDir = join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
425
+ const startupVbs = join(startupDir, `${WIN_TASK_NAME}.vbs`);
426
+ writeFileSync(startupVbs, vbsContent);
427
+ usedStartupFolder = true;
428
+ console.log(' (Using Startup folder for auto-start — no admin required)');
429
+ }
430
+ }
413
431
 
414
432
  // Also start it now
415
- execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
433
+ if (usedStartupFolder) {
434
+ spawn('wscript.exe', [vbsPath], { detached: true, stdio: 'ignore' }).unref();
435
+ } else {
436
+ execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
437
+ }
416
438
 
417
439
  console.log('Service installed and started.');
418
440
  console.log(`\nManage with:`);
@@ -430,6 +452,9 @@ function winUninstall() {
430
452
  const batPath = getWinBatPath();
431
453
  if (existsSync(vbsPath)) unlinkSync(vbsPath);
432
454
  if (existsSync(batPath)) unlinkSync(batPath);
455
+ // Clean up Startup folder shortcut
456
+ const startupVbs = join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', `${WIN_TASK_NAME}.vbs`);
457
+ if (existsSync(startupVbs)) unlinkSync(startupVbs);
433
458
  console.log('Service uninstalled.');
434
459
  }
435
460
 
@@ -438,8 +463,15 @@ function winStart() {
438
463
  execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
439
464
  console.log('Service started.');
440
465
  } catch {
441
- console.error('Service not installed. Run "yeaft-agent install" first.');
442
- process.exit(1);
466
+ // No schtasks try direct launch via VBS
467
+ const vbsPath = getWinWrapperPath();
468
+ if (existsSync(vbsPath)) {
469
+ spawn('wscript.exe', [vbsPath], { detached: true, stdio: 'ignore' }).unref();
470
+ console.log('Service started.');
471
+ } else {
472
+ console.error('Service not installed. Run "yeaft-agent install" first.');
473
+ process.exit(1);
474
+ }
443
475
  }
444
476
  }
445
477
 
@@ -486,7 +518,14 @@ function winStatus() {
486
518
  console.log(`Task name: ${WIN_TASK_NAME}`);
487
519
  }
488
520
  } catch {
489
- console.log('Service is not installed.');
521
+ // Check Startup folder fallback
522
+ const startupVbs = join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', `${WIN_TASK_NAME}.vbs`);
523
+ if (existsSync(startupVbs)) {
524
+ console.log('Service installed via Startup folder (no admin).');
525
+ console.log(`Startup script: ${startupVbs}`);
526
+ } else {
527
+ console.log('Service is not installed.');
528
+ }
490
529
  }
491
530
  }
492
531