lianrouter 2.2.2 → 2.3.0
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/cli.js +88 -30
- package/dist/tray.js +76 -31
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -17,11 +17,11 @@ var package_default;
|
|
|
17
17
|
var init_package = __esm(() => {
|
|
18
18
|
package_default = {
|
|
19
19
|
name: "lianrouter",
|
|
20
|
-
version: "2.
|
|
20
|
+
version: "2.3.0",
|
|
21
21
|
description: "LianRouter launcher: install, run and control the gateway from one command",
|
|
22
22
|
type: "module",
|
|
23
23
|
bin: {
|
|
24
|
-
lianrouter: "
|
|
24
|
+
lianrouter: "dist/cli.js"
|
|
25
25
|
},
|
|
26
26
|
engines: {
|
|
27
27
|
bun: ">=1.4.2"
|
|
@@ -228,22 +228,28 @@ function compareVersions(a, b) {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
// cli/update/extract.ts
|
|
231
|
+
import { existsSync, realpathSync } from "fs";
|
|
231
232
|
import { lstat, mkdir, readdir, rm as rm2 } from "fs/promises";
|
|
232
233
|
import { isAbsolute, join, normalize, resolve, sep } from "path";
|
|
233
234
|
function extractionArgv(kind, archivePath, stagingDir) {
|
|
234
235
|
const tar = Bun.which("tar");
|
|
235
236
|
const unzip = Bun.which("unzip");
|
|
237
|
+
const systemTar = process.platform === "win32" && existsSync("C:\\Windows\\System32\\tar.exe") ? "C:\\Windows\\System32\\tar.exe" : null;
|
|
238
|
+
const tarRealPath = tar !== null ? realpathSync(tar).toLowerCase() : "";
|
|
239
|
+
const isGitGnuTar = tarRealPath.includes("\\git") || tarRealPath.includes("/git/");
|
|
240
|
+
const resolvedTar = systemTar ?? tar;
|
|
241
|
+
const tarBase = resolvedTar === null ? null : systemTar === null && isGitGnuTar ? [resolvedTar, "--force-local"] : [resolvedTar];
|
|
236
242
|
switch (kind) {
|
|
237
243
|
case "zip": {
|
|
238
244
|
const preferTar = process.platform === "win32" || unzip === null;
|
|
239
|
-
if (preferTar &&
|
|
240
|
-
return [
|
|
245
|
+
if (preferTar && tarBase !== null) {
|
|
246
|
+
return [...tarBase, "-xf", archivePath, "-C", stagingDir];
|
|
241
247
|
}
|
|
242
248
|
if (unzip !== null) {
|
|
243
249
|
return [unzip, "-o", "-q", archivePath, "-d", stagingDir];
|
|
244
250
|
}
|
|
245
|
-
if (
|
|
246
|
-
return [
|
|
251
|
+
if (tarBase !== null) {
|
|
252
|
+
return [...tarBase, "-xf", archivePath, "-C", stagingDir];
|
|
247
253
|
}
|
|
248
254
|
throw new Error("cannot extract .zip: neither tar nor unzip is on PATH");
|
|
249
255
|
}
|
|
@@ -256,10 +262,10 @@ function extractionArgv(kind, archivePath, stagingDir) {
|
|
|
256
262
|
}
|
|
257
263
|
case "tar":
|
|
258
264
|
case "tgz": {
|
|
259
|
-
if (
|
|
265
|
+
if (tarBase === null) {
|
|
260
266
|
throw new Error(`cannot extract .${kind}: tar is not on PATH`);
|
|
261
267
|
}
|
|
262
|
-
return kind === "tgz" ? [
|
|
268
|
+
return kind === "tgz" ? [...tarBase, "-xzf", archivePath, "-C", stagingDir] : [...tarBase, "-xf", archivePath, "-C", stagingDir];
|
|
263
269
|
}
|
|
264
270
|
}
|
|
265
271
|
}
|
|
@@ -852,7 +858,7 @@ var init_engine = __esm(() => {
|
|
|
852
858
|
});
|
|
853
859
|
|
|
854
860
|
// cli/src/paths.ts
|
|
855
|
-
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
861
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync } from "fs";
|
|
856
862
|
import { homedir } from "os";
|
|
857
863
|
import { dirname as dirname2, join as join5, resolve as resolve3 } from "path";
|
|
858
864
|
function resolveInstallRoot(env = process.env, platform = process.platform) {
|
|
@@ -930,14 +936,14 @@ function resolveDevRepoRoot(startDir = import.meta.dir) {
|
|
|
930
936
|
}
|
|
931
937
|
}
|
|
932
938
|
function isRepoRoot(dir) {
|
|
933
|
-
if (!
|
|
939
|
+
if (!existsSync2(join5(dir, "src", "app.ts"))) {
|
|
934
940
|
return false;
|
|
935
941
|
}
|
|
936
|
-
if (!
|
|
942
|
+
if (!existsSync2(join5(dir, "src", "main.ts"))) {
|
|
937
943
|
return false;
|
|
938
944
|
}
|
|
939
945
|
const manifestPath = join5(dir, "package.json");
|
|
940
|
-
if (!
|
|
946
|
+
if (!existsSync2(manifestPath)) {
|
|
941
947
|
return false;
|
|
942
948
|
}
|
|
943
949
|
let parsed;
|
|
@@ -1584,7 +1590,7 @@ var init_app = __esm(async () => {
|
|
|
1584
1590
|
|
|
1585
1591
|
// cli/src/launcher.ts
|
|
1586
1592
|
init_version();
|
|
1587
|
-
import { existsSync as
|
|
1593
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1588
1594
|
import { join as join8 } from "path";
|
|
1589
1595
|
|
|
1590
1596
|
// cli/src/bootstrap.ts
|
|
@@ -1780,6 +1786,7 @@ import { mkdir as mkdir4, rename as rename2, rm as rm6, writeFile } from "fs/pro
|
|
|
1780
1786
|
import { dirname as dirname3 } from "path";
|
|
1781
1787
|
var CONTROL_TOKEN_HEADER = "x-lianrouter-control";
|
|
1782
1788
|
var LOOPBACK_ADDRESSES = ["127.0.0.1", "::1", "::ffff:127.0.0.1"];
|
|
1789
|
+
var OPEN_WEB_DEDUPE_MS = 3000;
|
|
1783
1790
|
|
|
1784
1791
|
class ControlServer {
|
|
1785
1792
|
options;
|
|
@@ -1791,6 +1798,8 @@ class ControlServer {
|
|
|
1791
1798
|
updateSnapshot = null;
|
|
1792
1799
|
updateProgress = null;
|
|
1793
1800
|
updateRunning = false;
|
|
1801
|
+
updateCheckInFlight;
|
|
1802
|
+
lastOpenWebAt;
|
|
1794
1803
|
constructor(options) {
|
|
1795
1804
|
this.options = options;
|
|
1796
1805
|
}
|
|
@@ -1869,6 +1878,24 @@ class ControlServer {
|
|
|
1869
1878
|
setUpdateRunning(running) {
|
|
1870
1879
|
this.updateRunning = running;
|
|
1871
1880
|
}
|
|
1881
|
+
checkUpdate() {
|
|
1882
|
+
const inFlight = this.updateCheckInFlight;
|
|
1883
|
+
if (inFlight !== undefined) {
|
|
1884
|
+
return inFlight;
|
|
1885
|
+
}
|
|
1886
|
+
const check = this.options.onCheckUpdate;
|
|
1887
|
+
if (check === undefined) {
|
|
1888
|
+
return Promise.reject(new Error("update checks are unavailable in this build"));
|
|
1889
|
+
}
|
|
1890
|
+
const pending = check().then((snapshot) => {
|
|
1891
|
+
this.publishUpdate(snapshot);
|
|
1892
|
+
return snapshot;
|
|
1893
|
+
}).finally(() => {
|
|
1894
|
+
this.updateCheckInFlight = undefined;
|
|
1895
|
+
});
|
|
1896
|
+
this.updateCheckInFlight = pending;
|
|
1897
|
+
return pending;
|
|
1898
|
+
}
|
|
1872
1899
|
get updateState() {
|
|
1873
1900
|
return {
|
|
1874
1901
|
snapshot: this.updateSnapshot,
|
|
@@ -1908,13 +1935,32 @@ class ControlServer {
|
|
|
1908
1935
|
return json(await this.options.supervisor.restart());
|
|
1909
1936
|
}
|
|
1910
1937
|
if (method === "POST" && pathname === "/open-web") {
|
|
1911
|
-
|
|
1938
|
+
const now = (this.options.now ?? Date.now)();
|
|
1939
|
+
if (this.lastOpenWebAt === undefined || now - this.lastOpenWebAt >= OPEN_WEB_DEDUPE_MS) {
|
|
1940
|
+
this.lastOpenWebAt = now;
|
|
1941
|
+
this.openUrl(this.options.consoleUrl);
|
|
1942
|
+
}
|
|
1912
1943
|
return json({ ok: true, url: this.options.consoleUrl });
|
|
1913
1944
|
}
|
|
1914
1945
|
if (method === "POST" && pathname === "/tray/hide") {
|
|
1915
1946
|
this.options.onTrayHide?.();
|
|
1916
1947
|
return json({ ok: true });
|
|
1917
1948
|
}
|
|
1949
|
+
if (method === "POST" && pathname === "/update/check") {
|
|
1950
|
+
const checkUpdate = this.options.onCheckUpdate;
|
|
1951
|
+
if (checkUpdate === undefined) {
|
|
1952
|
+
return json({ error: "update checks are unavailable in this build" }, 501);
|
|
1953
|
+
}
|
|
1954
|
+
if (this.updateRunning) {
|
|
1955
|
+
return json({ error: "an update is already running" }, 409);
|
|
1956
|
+
}
|
|
1957
|
+
try {
|
|
1958
|
+
return json(await this.checkUpdate());
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1961
|
+
return json({ error: `update check failed: ${message}` }, 502);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1918
1964
|
if (method === "POST" && pathname === "/update/start") {
|
|
1919
1965
|
const startUpdate = this.options.startUpdate;
|
|
1920
1966
|
if (startUpdate === undefined) {
|
|
@@ -2634,7 +2680,7 @@ class GatewaySupervisor {
|
|
|
2634
2680
|
// cli/src/install-config.ts
|
|
2635
2681
|
init_paths();
|
|
2636
2682
|
import { randomBytes } from "crypto";
|
|
2637
|
-
import { existsSync as
|
|
2683
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
2638
2684
|
var ALWAYS_REQUIRED = ["DATABASE_URL", "LIANROUTER_ENCRYPTION_KEY"];
|
|
2639
2685
|
function parseEnvFile(text) {
|
|
2640
2686
|
const values = {};
|
|
@@ -2664,7 +2710,7 @@ function parseEnvFile(text) {
|
|
|
2664
2710
|
}
|
|
2665
2711
|
function resolveGatewayConfig(installRoot, shellEnv = process.env) {
|
|
2666
2712
|
const path = resolveConfigFile(installRoot);
|
|
2667
|
-
const present =
|
|
2713
|
+
const present = existsSync3(path);
|
|
2668
2714
|
const fileValues = present ? parseEnvFile(readFileSync2(path, "utf8")) : {};
|
|
2669
2715
|
const env = {};
|
|
2670
2716
|
for (const [key, value] of Object.entries(fileValues)) {
|
|
@@ -2898,11 +2944,11 @@ async function checkLauncherVersion(options) {
|
|
|
2898
2944
|
|
|
2899
2945
|
// cli/src/tray-launcher.ts
|
|
2900
2946
|
init_paths();
|
|
2901
|
-
import { existsSync as
|
|
2947
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2902
2948
|
import { readFile as readFile2, rm as rm8, writeFile as writeFile3 } from "fs/promises";
|
|
2903
2949
|
import { join as join7 } from "path";
|
|
2904
2950
|
function resolveTrayEntry(options) {
|
|
2905
|
-
return trayEntryCandidates(options).find((candidate) =>
|
|
2951
|
+
return trayEntryCandidates(options).find((candidate) => existsSync4(candidate));
|
|
2906
2952
|
}
|
|
2907
2953
|
function trayEntryCandidates(options) {
|
|
2908
2954
|
const bundleDir = options.bundleDir ?? import.meta.dir;
|
|
@@ -3146,7 +3192,7 @@ function readPortEnv() {
|
|
|
3146
3192
|
}
|
|
3147
3193
|
function resolveRuntime() {
|
|
3148
3194
|
const repoRoot = resolveDevRepoRoot();
|
|
3149
|
-
if (repoRoot !== undefined &&
|
|
3195
|
+
if (repoRoot !== undefined && existsSync5(join8(repoRoot, "src", "app.ts"))) {
|
|
3150
3196
|
return {
|
|
3151
3197
|
installRoot: resolveInstallRoot(),
|
|
3152
3198
|
cwd: repoRoot,
|
|
@@ -3158,7 +3204,7 @@ function resolveRuntime() {
|
|
|
3158
3204
|
return { installRoot, cwd: installRoot, command: undefined, devRepoRoot: undefined };
|
|
3159
3205
|
}
|
|
3160
3206
|
async function ensureInstalledGateway(installRoot) {
|
|
3161
|
-
const present =
|
|
3207
|
+
const present = existsSync5(resolveBinaryPath(installRoot));
|
|
3162
3208
|
if (present) {
|
|
3163
3209
|
await ensureGatewayInstalled({ installRoot, currentVersion: CLI_VERSION });
|
|
3164
3210
|
return;
|
|
@@ -3283,7 +3329,7 @@ async function stopServer(supervisor) {
|
|
|
3283
3329
|
await supervisor.dispose();
|
|
3284
3330
|
return 0;
|
|
3285
3331
|
}
|
|
3286
|
-
async function openSession(supervisor, runtime, host) {
|
|
3332
|
+
async function openSession(supervisor, runtime, host, bootCheck) {
|
|
3287
3333
|
ensureStateDirs(runtime.installRoot);
|
|
3288
3334
|
const control = new ControlServer({
|
|
3289
3335
|
installRoot: runtime.installRoot,
|
|
@@ -3296,6 +3342,7 @@ async function openSession(supervisor, runtime, host) {
|
|
|
3296
3342
|
hideConsoleWindow();
|
|
3297
3343
|
stopTray(runtime.installRoot);
|
|
3298
3344
|
},
|
|
3345
|
+
onCheckUpdate: () => checkUpdateNow(runtime.installRoot),
|
|
3299
3346
|
startUpdate: async () => {
|
|
3300
3347
|
control.setUpdateRunning(true);
|
|
3301
3348
|
try {
|
|
@@ -3321,6 +3368,11 @@ async function openSession(supervisor, runtime, host) {
|
|
|
3321
3368
|
});
|
|
3322
3369
|
const handshake = await control.start();
|
|
3323
3370
|
activeControl = control;
|
|
3371
|
+
if (bootCheck && !updateCheckDisabled()) {
|
|
3372
|
+
control.checkUpdate().catch(() => {
|
|
3373
|
+
return;
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3324
3376
|
return { supervisor, control, handshake, installRoot: runtime.installRoot };
|
|
3325
3377
|
}
|
|
3326
3378
|
async function openWeb(supervisor, options) {
|
|
@@ -3364,7 +3416,7 @@ async function runInteractive(supervisor, options, runtime) {
|
|
|
3364
3416
|
await ensureStarted(supervisor);
|
|
3365
3417
|
const launcher = await launcherCheck;
|
|
3366
3418
|
const launcherNotice = launcher?.status === "outdated" ? { launcher: { current: launcher.current, latest: launcher.latest } } : {};
|
|
3367
|
-
const session = await openSession(supervisor, runtime, options.host);
|
|
3419
|
+
const session = await openSession(supervisor, runtime, options.host, options.headless);
|
|
3368
3420
|
if (options.background) {
|
|
3369
3421
|
supervisor.detach();
|
|
3370
3422
|
await session.control.stop();
|
|
@@ -3374,7 +3426,10 @@ async function runInteractive(supervisor, options, runtime) {
|
|
|
3374
3426
|
if (options.headless) {
|
|
3375
3427
|
return await blockUntilTrayExit(supervisor, session, runtime);
|
|
3376
3428
|
}
|
|
3377
|
-
const update = checkDisabled ? null : await readUpdateInfo(runtime.installRoot);
|
|
3429
|
+
const update = checkDisabled ? null : await readUpdateInfo(runtime.installRoot).catch(() => null);
|
|
3430
|
+
if (update !== null) {
|
|
3431
|
+
session.control.publishUpdate(update);
|
|
3432
|
+
}
|
|
3378
3433
|
for (const line of renderUpdateNotices({
|
|
3379
3434
|
...launcherNotice,
|
|
3380
3435
|
...update !== null && update.available ? { gateway: { current: update.current, latest: update.latest } } : {}
|
|
@@ -3515,7 +3570,7 @@ async function shutdownAndExit(supervisor, control) {
|
|
|
3515
3570
|
}
|
|
3516
3571
|
async function enterTrayMode(supervisor, options, runtime) {
|
|
3517
3572
|
await ensureStarted(supervisor);
|
|
3518
|
-
const session = await openSession(supervisor, runtime, options.host);
|
|
3573
|
+
const session = await openSession(supervisor, runtime, options.host, true);
|
|
3519
3574
|
const started = await startTrayHost(supervisor, session, runtime);
|
|
3520
3575
|
if (!started.ok) {
|
|
3521
3576
|
console.error(started.error);
|
|
@@ -3529,7 +3584,7 @@ async function enterTrayMode(supervisor, options, runtime) {
|
|
|
3529
3584
|
}
|
|
3530
3585
|
async function runTui2(supervisor, options, runtime) {
|
|
3531
3586
|
await ensureStarted(supervisor);
|
|
3532
|
-
const session = await openSession(supervisor, runtime, options.host);
|
|
3587
|
+
const session = await openSession(supervisor, runtime, options.host, true);
|
|
3533
3588
|
await launchTui(supervisor, session);
|
|
3534
3589
|
await shutdownSession(session, supervisor);
|
|
3535
3590
|
return 0;
|
|
@@ -3567,13 +3622,16 @@ async function runUpdateFlow(supervisor, runtime) {
|
|
|
3567
3622
|
console.log("Update complete.");
|
|
3568
3623
|
return 0;
|
|
3569
3624
|
}
|
|
3625
|
+
async function checkUpdateNow(installRoot) {
|
|
3626
|
+
const engine = await Promise.resolve().then(() => (init_engine(), {}));
|
|
3627
|
+
const info = await checkForUpdate({
|
|
3628
|
+
currentVersion: await resolveGatewayVersion(installRoot, CLI_VERSION)
|
|
3629
|
+
});
|
|
3630
|
+
return { current: info.current, latest: info.latest, available: info.available };
|
|
3631
|
+
}
|
|
3570
3632
|
async function readUpdateInfo(installRoot) {
|
|
3571
3633
|
try {
|
|
3572
|
-
|
|
3573
|
-
const info = await checkForUpdate({
|
|
3574
|
-
currentVersion: await resolveGatewayVersion(installRoot, CLI_VERSION)
|
|
3575
|
-
});
|
|
3576
|
-
return { current: info.current, latest: info.latest, available: info.available };
|
|
3634
|
+
return await checkUpdateNow(installRoot);
|
|
3577
3635
|
} catch {
|
|
3578
3636
|
return null;
|
|
3579
3637
|
}
|
package/dist/tray.js
CHANGED
|
@@ -129,21 +129,11 @@ function createControlClient(port, token) {
|
|
|
129
129
|
}
|
|
130
130
|
return {
|
|
131
131
|
status: () => call("/status", "GET", readStatus),
|
|
132
|
-
restart: () => call("/server/restart", "POST", () =>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}),
|
|
138
|
-
shutdown: () => call("/shutdown", "POST", () => {
|
|
139
|
-
return;
|
|
140
|
-
}),
|
|
141
|
-
openWeb: () => call("/open-web", "POST", () => {
|
|
142
|
-
return;
|
|
143
|
-
}),
|
|
144
|
-
startUpdate: () => call("/update/start", "POST", () => {
|
|
145
|
-
return;
|
|
146
|
-
}),
|
|
132
|
+
restart: () => call("/server/restart", "POST", () => true),
|
|
133
|
+
stop: () => call("/server/stop", "POST", () => true),
|
|
134
|
+
shutdown: () => call("/shutdown", "POST", () => true),
|
|
135
|
+
openWeb: () => call("/open-web", "POST", () => true),
|
|
136
|
+
startUpdate: () => call("/update/start", "POST", () => true),
|
|
147
137
|
updateState: () => call("/update/state", "GET", readUpdateState)
|
|
148
138
|
};
|
|
149
139
|
}
|
|
@@ -395,6 +385,43 @@ function readStalePid(installRoot) {
|
|
|
395
385
|
return;
|
|
396
386
|
}
|
|
397
387
|
|
|
388
|
+
// cli/tray/command-guard.ts
|
|
389
|
+
var OPEN_CONSOLE_GUARD_MS = 1500;
|
|
390
|
+
var MENU_REOPEN_GUARD_MS = 300;
|
|
391
|
+
function createCommandGuard(windowMs, now) {
|
|
392
|
+
const inFlight = new Set;
|
|
393
|
+
const lastStartedAt = new Map;
|
|
394
|
+
return {
|
|
395
|
+
async run(command, action) {
|
|
396
|
+
if (inFlight.has(command))
|
|
397
|
+
return false;
|
|
398
|
+
const last = lastStartedAt.get(command);
|
|
399
|
+
if (last !== undefined && now() - last < windowMs)
|
|
400
|
+
return false;
|
|
401
|
+
inFlight.add(command);
|
|
402
|
+
lastStartedAt.set(command, now());
|
|
403
|
+
try {
|
|
404
|
+
await action();
|
|
405
|
+
} finally {
|
|
406
|
+
inFlight.delete(command);
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function createRepeatSuppressor(windowMs, now) {
|
|
413
|
+
let last = Number.NEGATIVE_INFINITY;
|
|
414
|
+
return {
|
|
415
|
+
allow() {
|
|
416
|
+
const at = now();
|
|
417
|
+
if (at - last < windowMs)
|
|
418
|
+
return false;
|
|
419
|
+
last = at;
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
398
425
|
// cli/tray/pump.ts
|
|
399
426
|
import { JSCallback, ptr as ptr2 } from "bun:ffi";
|
|
400
427
|
|
|
@@ -744,6 +771,7 @@ var WM_QUIT = 18;
|
|
|
744
771
|
var WM_NULL = 0;
|
|
745
772
|
var WM_NCCREATE = 129;
|
|
746
773
|
var WM_RBUTTONUP = 517;
|
|
774
|
+
var WM_LBUTTONUP = 514;
|
|
747
775
|
var WM_CONTEXTMENU = 123;
|
|
748
776
|
var WM_LBUTTONDBLCLK = 515;
|
|
749
777
|
var WM_APP = 32768;
|
|
@@ -811,9 +839,11 @@ function showContextMenu(window) {
|
|
|
811
839
|
return command;
|
|
812
840
|
}
|
|
813
841
|
function decodeTrayEvent(mouseMessage) {
|
|
814
|
-
if (mouseMessage === WM_RBUTTONUP
|
|
842
|
+
if (mouseMessage === WM_RBUTTONUP)
|
|
815
843
|
return "context";
|
|
816
|
-
if (mouseMessage ===
|
|
844
|
+
if (mouseMessage === WM_CONTEXTMENU)
|
|
845
|
+
return "context-alt";
|
|
846
|
+
if (mouseMessage === WM_LBUTTONUP || mouseMessage === WM_LBUTTONDBLCLK)
|
|
817
847
|
return "activate";
|
|
818
848
|
return "none";
|
|
819
849
|
}
|
|
@@ -851,6 +881,8 @@ async function startTrayPump(options) {
|
|
|
851
881
|
if (moduleHandle === undefined)
|
|
852
882
|
throw new Error("GetModuleHandleW returned NULL");
|
|
853
883
|
const state = { window: undefined, stopRequested: false, destroyed: false };
|
|
884
|
+
const menuGuard = createRepeatSuppressor(MENU_REOPEN_GUARD_MS, () => Date.now());
|
|
885
|
+
let menuOpen = false;
|
|
854
886
|
const windowProc = new JSCallback((hWnd, message, wParam, lParam) => {
|
|
855
887
|
if (message === WM_NCCREATE)
|
|
856
888
|
return 1n;
|
|
@@ -859,8 +891,18 @@ async function startTrayPump(options) {
|
|
|
859
891
|
const window = state.window;
|
|
860
892
|
if (window === undefined)
|
|
861
893
|
return 0n;
|
|
862
|
-
if (event === "context") {
|
|
863
|
-
|
|
894
|
+
if (event === "context" || event === "context-alt") {
|
|
895
|
+
if (menuOpen)
|
|
896
|
+
return 0n;
|
|
897
|
+
if (!menuGuard.allow())
|
|
898
|
+
return 0n;
|
|
899
|
+
menuOpen = true;
|
|
900
|
+
let chosen = 0;
|
|
901
|
+
try {
|
|
902
|
+
chosen = showContextMenu(window);
|
|
903
|
+
} finally {
|
|
904
|
+
menuOpen = false;
|
|
905
|
+
}
|
|
864
906
|
if (isTrayCommandId(chosen))
|
|
865
907
|
options.onCommand(chosen);
|
|
866
908
|
return 0n;
|
|
@@ -1175,6 +1217,7 @@ async function main() {
|
|
|
1175
1217
|
sleep: (ms) => Bun.sleep(ms),
|
|
1176
1218
|
now: () => Date.now()
|
|
1177
1219
|
};
|
|
1220
|
+
const openConsoleGuard = createCommandGuard(OPEN_CONSOLE_GUARD_MS, () => Date.now());
|
|
1178
1221
|
const runCommand = async (command) => {
|
|
1179
1222
|
if (command === TRAY_COMMANDS.exit) {
|
|
1180
1223
|
const result = await callRecovering({
|
|
@@ -1190,19 +1233,21 @@ async function main() {
|
|
|
1190
1233
|
return;
|
|
1191
1234
|
}
|
|
1192
1235
|
if (command === TRAY_COMMANDS.openConsole) {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1236
|
+
await openConsoleGuard.run(command, async () => {
|
|
1237
|
+
const result = await callRecovering({
|
|
1238
|
+
installRoot,
|
|
1239
|
+
startDir: import.meta.dir,
|
|
1240
|
+
deps: recoveryDeps,
|
|
1241
|
+
...knownPort === undefined ? {} : { gatewayPort: knownPort },
|
|
1242
|
+
call: (client) => client.openWeb()
|
|
1243
|
+
});
|
|
1244
|
+
if (result.result.ok) {
|
|
1245
|
+
refreshTooltip();
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
openConsoleDirectly();
|
|
1201
1249
|
refreshTooltip();
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
openConsoleDirectly();
|
|
1205
|
-
refreshTooltip();
|
|
1250
|
+
});
|
|
1206
1251
|
return;
|
|
1207
1252
|
}
|
|
1208
1253
|
if (command === TRAY_COMMANDS.checkUpdate) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lianrouter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "LianRouter launcher: install, run and control the gateway from one command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"lianrouter": "
|
|
7
|
+
"lianrouter": "dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
10
|
"bun": ">=1.4.2"
|