@yeaft/webchat-agent 0.0.7 → 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 +40 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.7",
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,21 +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
- // Try with highest privilege first, fall back to limited (no admin required)
409
+ // Try schtasks first (highest limited), fall back to Startup folder
410
+ let usedStartupFolder = false;
410
411
  try {
411
412
  execSync(
412
413
  `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl highest /f`,
413
414
  { stdio: 'pipe' }
414
415
  );
415
416
  } catch {
416
- execSync(
417
- `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl limited /f`,
418
- { stdio: 'pipe' }
419
- );
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
+ }
420
430
  }
421
431
 
422
432
  // Also start it now
423
- 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
+ }
424
438
 
425
439
  console.log('Service installed and started.');
426
440
  console.log(`\nManage with:`);
@@ -438,6 +452,9 @@ function winUninstall() {
438
452
  const batPath = getWinBatPath();
439
453
  if (existsSync(vbsPath)) unlinkSync(vbsPath);
440
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);
441
458
  console.log('Service uninstalled.');
442
459
  }
443
460
 
@@ -446,8 +463,15 @@ function winStart() {
446
463
  execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
447
464
  console.log('Service started.');
448
465
  } catch {
449
- console.error('Service not installed. Run "yeaft-agent install" first.');
450
- 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
+ }
451
475
  }
452
476
  }
453
477
 
@@ -494,7 +518,14 @@ function winStatus() {
494
518
  console.log(`Task name: ${WIN_TASK_NAME}`);
495
519
  }
496
520
  } catch {
497
- 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
+ }
498
529
  }
499
530
  }
500
531