@rehpic/vcli 0.1.0-beta.51.1 → 0.1.0-beta.52.1
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/dist/index.js +66 -81
- package/dist/index.js.map +1 -1
- package/dist/menubar.js +242 -0
- package/dist/menubar.js.map +1 -0
- package/package.json +4 -2
- package/scripts/postinstall.js +106 -0
package/dist/index.js
CHANGED
|
@@ -1114,6 +1114,11 @@ var LIVE_ACTIVITIES_CACHE = join(CONFIG_DIR, "live-activities.json");
|
|
|
1114
1114
|
var LAUNCHAGENT_DIR = join(homedir2(), "Library", "LaunchAgents");
|
|
1115
1115
|
var LAUNCHAGENT_PLIST = join(LAUNCHAGENT_DIR, "com.vector.bridge.plist");
|
|
1116
1116
|
var LAUNCHAGENT_LABEL = "com.vector.bridge";
|
|
1117
|
+
var LEGACY_MENUBAR_LAUNCHAGENT_LABEL = "com.vector.menubar";
|
|
1118
|
+
var LEGACY_MENUBAR_LAUNCHAGENT_PLIST = join(
|
|
1119
|
+
LAUNCHAGENT_DIR,
|
|
1120
|
+
`${LEGACY_MENUBAR_LAUNCHAGENT_LABEL}.plist`
|
|
1121
|
+
);
|
|
1117
1122
|
var HEARTBEAT_INTERVAL_MS = 3e4;
|
|
1118
1123
|
var COMMAND_POLL_INTERVAL_MS = 5e3;
|
|
1119
1124
|
var PROCESS_DISCOVERY_INTERVAL_MS = 6e4;
|
|
@@ -1403,40 +1408,10 @@ function installLaunchAgent(vcliPath) {
|
|
|
1403
1408
|
</dict>
|
|
1404
1409
|
</dict>
|
|
1405
1410
|
</plist>`;
|
|
1406
|
-
const menuBarCandidates = [
|
|
1407
|
-
join(CONFIG_DIR, "VectorMenuBar"),
|
|
1408
|
-
"/usr/local/bin/VectorMenuBar",
|
|
1409
|
-
join(homedir2(), ".local", "bin", "VectorMenuBar")
|
|
1410
|
-
];
|
|
1411
|
-
const menuBarBinary = menuBarCandidates.find((p) => existsSync(p));
|
|
1412
|
-
if (menuBarBinary) {
|
|
1413
|
-
const menuBarPlist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
1414
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
1415
|
-
<plist version="1.0">
|
|
1416
|
-
<dict>
|
|
1417
|
-
<key>Label</key>
|
|
1418
|
-
<string>com.vector.menubar</string>
|
|
1419
|
-
<key>ProgramArguments</key>
|
|
1420
|
-
<array>
|
|
1421
|
-
<string>${menuBarBinary}</string>
|
|
1422
|
-
</array>
|
|
1423
|
-
<key>RunAtLoad</key>
|
|
1424
|
-
<true/>
|
|
1425
|
-
<key>KeepAlive</key>
|
|
1426
|
-
<false/>
|
|
1427
|
-
</dict>
|
|
1428
|
-
</plist>`;
|
|
1429
|
-
const menuBarPlistPath = join(LAUNCHAGENT_DIR, "com.vector.menubar.plist");
|
|
1430
|
-
writeFileSync(menuBarPlistPath, menuBarPlist);
|
|
1431
|
-
try {
|
|
1432
|
-
execSync(`launchctl load ${menuBarPlistPath}`, { stdio: "pipe" });
|
|
1433
|
-
console.log("Menu bar helper installed.");
|
|
1434
|
-
} catch {
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
1411
|
if (!existsSync(LAUNCHAGENT_DIR)) {
|
|
1438
1412
|
mkdirSync(LAUNCHAGENT_DIR, { recursive: true });
|
|
1439
1413
|
}
|
|
1414
|
+
removeLegacyMenuBarLaunchAgent();
|
|
1440
1415
|
writeFileSync(LAUNCHAGENT_PLIST, plist);
|
|
1441
1416
|
console.log(`Installed LaunchAgent: ${LAUNCHAGENT_PLIST}`);
|
|
1442
1417
|
}
|
|
@@ -1460,72 +1435,82 @@ function unloadLaunchAgent() {
|
|
|
1460
1435
|
}
|
|
1461
1436
|
function uninstallLaunchAgent() {
|
|
1462
1437
|
unloadLaunchAgent();
|
|
1438
|
+
removeLegacyMenuBarLaunchAgent();
|
|
1463
1439
|
try {
|
|
1464
1440
|
unlinkSync(LAUNCHAGENT_PLIST);
|
|
1465
1441
|
console.log("LaunchAgent removed.");
|
|
1466
1442
|
} catch {
|
|
1467
1443
|
}
|
|
1468
1444
|
}
|
|
1469
|
-
var
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1445
|
+
var MENUBAR_PID_FILE = join(CONFIG_DIR, "menubar.pid");
|
|
1446
|
+
function removeLegacyMenuBarLaunchAgent() {
|
|
1447
|
+
if (platform() !== "darwin" || !existsSync(LEGACY_MENUBAR_LAUNCHAGENT_PLIST)) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1474
1450
|
try {
|
|
1475
|
-
execSync(
|
|
1451
|
+
execSync(`launchctl unload ${LEGACY_MENUBAR_LAUNCHAGENT_PLIST}`, {
|
|
1452
|
+
stdio: "pipe"
|
|
1453
|
+
});
|
|
1476
1454
|
} catch {
|
|
1477
|
-
return null;
|
|
1478
1455
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
"macos",
|
|
1483
|
-
"VectorMenuBar.swift"
|
|
1484
|
-
);
|
|
1485
|
-
let swiftSource;
|
|
1486
|
-
if (existsSync(localSource)) {
|
|
1487
|
-
swiftSource = localSource;
|
|
1488
|
-
} else {
|
|
1489
|
-
const downloadPath = join(CONFIG_DIR, "VectorMenuBar.swift");
|
|
1490
|
-
try {
|
|
1491
|
-
execSync(`curl -fsSL "${MENUBAR_SWIFT_URL}" -o "${downloadPath}"`, {
|
|
1492
|
-
stdio: "pipe",
|
|
1493
|
-
timeout: 15e3
|
|
1494
|
-
});
|
|
1495
|
-
swiftSource = downloadPath;
|
|
1496
|
-
} catch {
|
|
1497
|
-
return null;
|
|
1498
|
-
}
|
|
1456
|
+
try {
|
|
1457
|
+
unlinkSync(LEGACY_MENUBAR_LAUNCHAGENT_PLIST);
|
|
1458
|
+
} catch {
|
|
1499
1459
|
}
|
|
1460
|
+
}
|
|
1461
|
+
function findMenuBarScript() {
|
|
1462
|
+
const candidates = [
|
|
1463
|
+
join(import.meta.dirname ?? "", "menubar.js"),
|
|
1464
|
+
join(import.meta.dirname ?? "", "..", "dist", "menubar.js")
|
|
1465
|
+
];
|
|
1466
|
+
for (const p of candidates) {
|
|
1467
|
+
if (existsSync(p)) return p;
|
|
1468
|
+
}
|
|
1469
|
+
return null;
|
|
1470
|
+
}
|
|
1471
|
+
function isKnownMenuBarProcess(pid) {
|
|
1500
1472
|
try {
|
|
1501
|
-
execSync(
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
);
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1473
|
+
const command = execSync(`ps -p ${pid} -o args=`, {
|
|
1474
|
+
encoding: "utf-8",
|
|
1475
|
+
timeout: 3e3
|
|
1476
|
+
});
|
|
1477
|
+
return command.includes("menubar.js") || command.includes("menubar.ts") || command.includes("VectorMenuBar");
|
|
1478
|
+
} catch {
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
function killExistingMenuBar() {
|
|
1483
|
+
if (existsSync(MENUBAR_PID_FILE)) {
|
|
1484
|
+
try {
|
|
1485
|
+
const pid = Number(readFileSync(MENUBAR_PID_FILE, "utf-8").trim());
|
|
1486
|
+
if (Number.isFinite(pid) && pid > 0 && isKnownMenuBarProcess(pid)) {
|
|
1487
|
+
process.kill(pid, "SIGTERM");
|
|
1513
1488
|
}
|
|
1489
|
+
} catch {
|
|
1490
|
+
}
|
|
1491
|
+
try {
|
|
1492
|
+
unlinkSync(MENUBAR_PID_FILE);
|
|
1493
|
+
} catch {
|
|
1514
1494
|
}
|
|
1515
|
-
return MENUBAR_BINARY;
|
|
1516
|
-
} catch {
|
|
1517
|
-
return null;
|
|
1518
1495
|
}
|
|
1519
1496
|
}
|
|
1520
1497
|
async function launchMenuBar() {
|
|
1521
1498
|
if (platform() !== "darwin") return;
|
|
1522
|
-
|
|
1523
|
-
|
|
1499
|
+
removeLegacyMenuBarLaunchAgent();
|
|
1500
|
+
const script = findMenuBarScript();
|
|
1501
|
+
if (!script) return;
|
|
1502
|
+
killExistingMenuBar();
|
|
1524
1503
|
try {
|
|
1525
1504
|
const { spawn: spawnChild } = await import("child_process");
|
|
1526
|
-
const child = spawnChild(
|
|
1505
|
+
const child = spawnChild(process.execPath, [script], {
|
|
1506
|
+
detached: true,
|
|
1507
|
+
stdio: "ignore",
|
|
1508
|
+
env: { ...process.env }
|
|
1509
|
+
});
|
|
1527
1510
|
child.unref();
|
|
1528
|
-
|
|
1511
|
+
if (child.pid) {
|
|
1512
|
+
writeFileSync(MENUBAR_PID_FILE, String(child.pid));
|
|
1513
|
+
}
|
|
1529
1514
|
} catch {
|
|
1530
1515
|
}
|
|
1531
1516
|
}
|
|
@@ -1560,6 +1545,7 @@ function getBridgeStatus() {
|
|
|
1560
1545
|
return { configured: true, running, starting, pid, config };
|
|
1561
1546
|
}
|
|
1562
1547
|
function stopBridge() {
|
|
1548
|
+
killExistingMenuBar();
|
|
1563
1549
|
if (!existsSync(PID_FILE)) return false;
|
|
1564
1550
|
const pid = Number(readFileSync(PID_FILE, "utf-8").trim());
|
|
1565
1551
|
try {
|
|
@@ -3596,7 +3582,6 @@ serviceCommand.command("start").description("Start the bridge service via Launch
|
|
|
3596
3582
|
const vcliPath = process.argv[1] ?? "vcli";
|
|
3597
3583
|
installLaunchAgent(vcliPath);
|
|
3598
3584
|
loadLaunchAgent();
|
|
3599
|
-
await launchMenuBar();
|
|
3600
3585
|
s.stop("Bridge service started.");
|
|
3601
3586
|
} else {
|
|
3602
3587
|
console.log(
|
|
@@ -3620,6 +3605,9 @@ serviceCommand.command("run").description("Run the bridge service in the foregro
|
|
|
3620
3605
|
if (!user) throw new Error("Not logged in. Run `vcli auth login` first.");
|
|
3621
3606
|
config = await setupBridgeDevice(runtime.convexUrl, user._id);
|
|
3622
3607
|
}
|
|
3608
|
+
if (osPlatform() === "darwin") {
|
|
3609
|
+
await launchMenuBar();
|
|
3610
|
+
}
|
|
3623
3611
|
const bridge = new BridgeService(config);
|
|
3624
3612
|
await bridge.run();
|
|
3625
3613
|
});
|
|
@@ -3681,9 +3669,6 @@ serviceCommand.command("install").description("Install the bridge as a system se
|
|
|
3681
3669
|
s.start("Starting bridge service...");
|
|
3682
3670
|
loadLaunchAgent();
|
|
3683
3671
|
s.stop("Bridge service started");
|
|
3684
|
-
s.start("Launching menu bar...");
|
|
3685
|
-
await launchMenuBar();
|
|
3686
|
-
s.stop("Menu bar ready");
|
|
3687
3672
|
console.log("");
|
|
3688
3673
|
console.log(
|
|
3689
3674
|
"Bridge installed and running. Will start automatically on login."
|