lianrouter 2.2.1 → 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 +177 -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)) {
|
|
@@ -2820,13 +2866,89 @@ async function runUpdateSequence(deps) {
|
|
|
2820
2866
|
}
|
|
2821
2867
|
}
|
|
2822
2868
|
|
|
2869
|
+
// cli/src/update-notice.ts
|
|
2870
|
+
var ARROW = "\u2192";
|
|
2871
|
+
function renderUpdateNotices(input) {
|
|
2872
|
+
const lines = [];
|
|
2873
|
+
const launcher = input.launcher;
|
|
2874
|
+
if (launcher !== undefined && compareVersions(launcher.latest, launcher.current) > 0) {
|
|
2875
|
+
lines.push(`lianrouter: a newer launcher is published (${launcher.current} ${ARROW} ${launcher.latest}). Run: bun add -g lianrouter@latest`);
|
|
2876
|
+
}
|
|
2877
|
+
const gateway = input.gateway;
|
|
2878
|
+
if (gateway !== undefined && compareVersions(gateway.latest, gateway.current) > 0) {
|
|
2879
|
+
lines.push(`lianrouter: a gateway update is available (${gateway.current} ${ARROW} ${gateway.latest}). Run: lianrouter update`);
|
|
2880
|
+
}
|
|
2881
|
+
return lines;
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
// cli/update/npm-source.ts
|
|
2885
|
+
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/lianrouter/latest";
|
|
2886
|
+
var REGISTRY_URL = (() => {
|
|
2887
|
+
const override = process.env.LIANROUTER_NPM_REGISTRY;
|
|
2888
|
+
return override !== undefined && override.trim().length > 0 ? override.trim() : DEFAULT_REGISTRY_URL;
|
|
2889
|
+
})();
|
|
2890
|
+
var REQUEST_TIMEOUT_MS2 = 2500;
|
|
2891
|
+
var UPDATE_CHECK_DISABLE_ENV = "LIANROUTER_NO_UPDATE_CHECK";
|
|
2892
|
+
function updateCheckDisabled() {
|
|
2893
|
+
return process.env[UPDATE_CHECK_DISABLE_ENV] === "1";
|
|
2894
|
+
}
|
|
2895
|
+
var VERSION_SHAPE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
2896
|
+
function isSemverish(value) {
|
|
2897
|
+
return typeof value === "string" && VERSION_SHAPE.test(normalizeVersion(value));
|
|
2898
|
+
}
|
|
2899
|
+
async function checkLauncherVersion(options) {
|
|
2900
|
+
const url = options.registryUrl ?? REGISTRY_URL;
|
|
2901
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
2902
|
+
const controller = new AbortController;
|
|
2903
|
+
let timer;
|
|
2904
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
2905
|
+
timer = setTimeout(() => {
|
|
2906
|
+
controller.abort();
|
|
2907
|
+
reject(new Error(`registry did not answer within ${REQUEST_TIMEOUT_MS2} ms`));
|
|
2908
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
2909
|
+
});
|
|
2910
|
+
let response;
|
|
2911
|
+
try {
|
|
2912
|
+
response = await Promise.race([
|
|
2913
|
+
doFetch(url, { headers: { Accept: "application/json" }, signal: controller.signal }),
|
|
2914
|
+
deadline
|
|
2915
|
+
]);
|
|
2916
|
+
} catch (error) {
|
|
2917
|
+
return {
|
|
2918
|
+
status: "unavailable",
|
|
2919
|
+
reason: `registry unreachable: ${error instanceof Error ? error.message : String(error)}`
|
|
2920
|
+
};
|
|
2921
|
+
} finally {
|
|
2922
|
+
clearTimeout(timer);
|
|
2923
|
+
}
|
|
2924
|
+
if (!response.ok) {
|
|
2925
|
+
return { status: "unavailable", reason: `registry returned ${response.status}` };
|
|
2926
|
+
}
|
|
2927
|
+
let payload;
|
|
2928
|
+
try {
|
|
2929
|
+
payload = await response.json();
|
|
2930
|
+
} catch {
|
|
2931
|
+
return { status: "unavailable", reason: "registry returned a non-JSON body" };
|
|
2932
|
+
}
|
|
2933
|
+
if (typeof payload !== "object" || payload === null || !("version" in payload)) {
|
|
2934
|
+
return { status: "unavailable", reason: "registry returned no usable version" };
|
|
2935
|
+
}
|
|
2936
|
+
const published = payload.version;
|
|
2937
|
+
if (!isSemverish(published)) {
|
|
2938
|
+
return { status: "unavailable", reason: "registry returned no usable version" };
|
|
2939
|
+
}
|
|
2940
|
+
const latest = normalizeVersion(published);
|
|
2941
|
+
const current = normalizeVersion(options.currentVersion);
|
|
2942
|
+
return compareVersions(latest, current) > 0 ? { status: "outdated", latest, current } : { status: "current", latest };
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2823
2945
|
// cli/src/tray-launcher.ts
|
|
2824
2946
|
init_paths();
|
|
2825
|
-
import { existsSync as
|
|
2947
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2826
2948
|
import { readFile as readFile2, rm as rm8, writeFile as writeFile3 } from "fs/promises";
|
|
2827
2949
|
import { join as join7 } from "path";
|
|
2828
2950
|
function resolveTrayEntry(options) {
|
|
2829
|
-
return trayEntryCandidates(options).find((candidate) =>
|
|
2951
|
+
return trayEntryCandidates(options).find((candidate) => existsSync4(candidate));
|
|
2830
2952
|
}
|
|
2831
2953
|
function trayEntryCandidates(options) {
|
|
2832
2954
|
const bundleDir = options.bundleDir ?? import.meta.dir;
|
|
@@ -3070,7 +3192,7 @@ function readPortEnv() {
|
|
|
3070
3192
|
}
|
|
3071
3193
|
function resolveRuntime() {
|
|
3072
3194
|
const repoRoot = resolveDevRepoRoot();
|
|
3073
|
-
if (repoRoot !== undefined &&
|
|
3195
|
+
if (repoRoot !== undefined && existsSync5(join8(repoRoot, "src", "app.ts"))) {
|
|
3074
3196
|
return {
|
|
3075
3197
|
installRoot: resolveInstallRoot(),
|
|
3076
3198
|
cwd: repoRoot,
|
|
@@ -3082,7 +3204,7 @@ function resolveRuntime() {
|
|
|
3082
3204
|
return { installRoot, cwd: installRoot, command: undefined, devRepoRoot: undefined };
|
|
3083
3205
|
}
|
|
3084
3206
|
async function ensureInstalledGateway(installRoot) {
|
|
3085
|
-
const present =
|
|
3207
|
+
const present = existsSync5(resolveBinaryPath(installRoot));
|
|
3086
3208
|
if (present) {
|
|
3087
3209
|
await ensureGatewayInstalled({ installRoot, currentVersion: CLI_VERSION });
|
|
3088
3210
|
return;
|
|
@@ -3207,7 +3329,7 @@ async function stopServer(supervisor) {
|
|
|
3207
3329
|
await supervisor.dispose();
|
|
3208
3330
|
return 0;
|
|
3209
3331
|
}
|
|
3210
|
-
async function openSession(supervisor, runtime, host) {
|
|
3332
|
+
async function openSession(supervisor, runtime, host, bootCheck) {
|
|
3211
3333
|
ensureStateDirs(runtime.installRoot);
|
|
3212
3334
|
const control = new ControlServer({
|
|
3213
3335
|
installRoot: runtime.installRoot,
|
|
@@ -3220,6 +3342,7 @@ async function openSession(supervisor, runtime, host) {
|
|
|
3220
3342
|
hideConsoleWindow();
|
|
3221
3343
|
stopTray(runtime.installRoot);
|
|
3222
3344
|
},
|
|
3345
|
+
onCheckUpdate: () => checkUpdateNow(runtime.installRoot),
|
|
3223
3346
|
startUpdate: async () => {
|
|
3224
3347
|
control.setUpdateRunning(true);
|
|
3225
3348
|
try {
|
|
@@ -3245,6 +3368,11 @@ async function openSession(supervisor, runtime, host) {
|
|
|
3245
3368
|
});
|
|
3246
3369
|
const handshake = await control.start();
|
|
3247
3370
|
activeControl = control;
|
|
3371
|
+
if (bootCheck && !updateCheckDisabled()) {
|
|
3372
|
+
control.checkUpdate().catch(() => {
|
|
3373
|
+
return;
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3248
3376
|
return { supervisor, control, handshake, installRoot: runtime.installRoot };
|
|
3249
3377
|
}
|
|
3250
3378
|
async function openWeb(supervisor, options) {
|
|
@@ -3280,8 +3408,15 @@ ${cause}`);
|
|
|
3280
3408
|
return supervisor.status;
|
|
3281
3409
|
}
|
|
3282
3410
|
async function runInteractive(supervisor, options, runtime) {
|
|
3411
|
+
const checkDisabled = updateCheckDisabled();
|
|
3412
|
+
const noticesApply = !options.background && !options.headless;
|
|
3413
|
+
const launcherCheck = checkDisabled || !noticesApply ? undefined : checkLauncherVersion({ currentVersion: CLI_VERSION }).catch(() => {
|
|
3414
|
+
return;
|
|
3415
|
+
});
|
|
3283
3416
|
await ensureStarted(supervisor);
|
|
3284
|
-
const
|
|
3417
|
+
const launcher = await launcherCheck;
|
|
3418
|
+
const launcherNotice = launcher?.status === "outdated" ? { launcher: { current: launcher.current, latest: launcher.latest } } : {};
|
|
3419
|
+
const session = await openSession(supervisor, runtime, options.host, options.headless);
|
|
3285
3420
|
if (options.background) {
|
|
3286
3421
|
supervisor.detach();
|
|
3287
3422
|
await session.control.stop();
|
|
@@ -3291,7 +3426,16 @@ async function runInteractive(supervisor, options, runtime) {
|
|
|
3291
3426
|
if (options.headless) {
|
|
3292
3427
|
return await blockUntilTrayExit(supervisor, session, runtime);
|
|
3293
3428
|
}
|
|
3294
|
-
const update = 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
|
+
}
|
|
3433
|
+
for (const line of renderUpdateNotices({
|
|
3434
|
+
...launcherNotice,
|
|
3435
|
+
...update !== null && update.available ? { gateway: { current: update.current, latest: update.latest } } : {}
|
|
3436
|
+
})) {
|
|
3437
|
+
console.log(line);
|
|
3438
|
+
}
|
|
3295
3439
|
const action = await promptMenu({
|
|
3296
3440
|
version: CLI_VERSION,
|
|
3297
3441
|
port: supervisor.status.port,
|
|
@@ -3426,7 +3570,7 @@ async function shutdownAndExit(supervisor, control) {
|
|
|
3426
3570
|
}
|
|
3427
3571
|
async function enterTrayMode(supervisor, options, runtime) {
|
|
3428
3572
|
await ensureStarted(supervisor);
|
|
3429
|
-
const session = await openSession(supervisor, runtime, options.host);
|
|
3573
|
+
const session = await openSession(supervisor, runtime, options.host, true);
|
|
3430
3574
|
const started = await startTrayHost(supervisor, session, runtime);
|
|
3431
3575
|
if (!started.ok) {
|
|
3432
3576
|
console.error(started.error);
|
|
@@ -3440,7 +3584,7 @@ async function enterTrayMode(supervisor, options, runtime) {
|
|
|
3440
3584
|
}
|
|
3441
3585
|
async function runTui2(supervisor, options, runtime) {
|
|
3442
3586
|
await ensureStarted(supervisor);
|
|
3443
|
-
const session = await openSession(supervisor, runtime, options.host);
|
|
3587
|
+
const session = await openSession(supervisor, runtime, options.host, true);
|
|
3444
3588
|
await launchTui(supervisor, session);
|
|
3445
3589
|
await shutdownSession(session, supervisor);
|
|
3446
3590
|
return 0;
|
|
@@ -3478,13 +3622,16 @@ async function runUpdateFlow(supervisor, runtime) {
|
|
|
3478
3622
|
console.log("Update complete.");
|
|
3479
3623
|
return 0;
|
|
3480
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
|
+
}
|
|
3481
3632
|
async function readUpdateInfo(installRoot) {
|
|
3482
3633
|
try {
|
|
3483
|
-
|
|
3484
|
-
const info = await checkForUpdate({
|
|
3485
|
-
currentVersion: await resolveGatewayVersion(installRoot, CLI_VERSION)
|
|
3486
|
-
});
|
|
3487
|
-
return { current: info.current, latest: info.latest, available: info.available };
|
|
3634
|
+
return await checkUpdateNow(installRoot);
|
|
3488
3635
|
} catch {
|
|
3489
3636
|
return null;
|
|
3490
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"
|