lianrouter 2.3.3 → 2.3.5
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 +305 -51
- package/dist/tray.js +6 -2
- package/package.json +4 -1
package/dist/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ var package_default;
|
|
|
17
17
|
var init_package = __esm(() => {
|
|
18
18
|
package_default = {
|
|
19
19
|
name: "lianrouter",
|
|
20
|
-
version: "2.3.
|
|
20
|
+
version: "2.3.5",
|
|
21
21
|
description: "LianRouter launcher: install, run and control the gateway from one command",
|
|
22
22
|
type: "module",
|
|
23
23
|
bin: {
|
|
@@ -36,6 +36,9 @@ var init_package = __esm(() => {
|
|
|
36
36
|
postinstall: "echo lianrouter: the gateway binary installs on first run, not during this install",
|
|
37
37
|
prepublishOnly: "bun run build"
|
|
38
38
|
},
|
|
39
|
+
dependencies: {
|
|
40
|
+
"embedded-postgres": "18.6.0-beta.19"
|
|
41
|
+
},
|
|
39
42
|
repository: {
|
|
40
43
|
type: "git",
|
|
41
44
|
url: "git+https://github.com/ReXooGen/Lian-Router.git",
|
|
@@ -1593,8 +1596,8 @@ var init_app = __esm(async () => {
|
|
|
1593
1596
|
|
|
1594
1597
|
// cli/src/launcher.ts
|
|
1595
1598
|
init_version();
|
|
1596
|
-
import { existsSync as
|
|
1597
|
-
import { join as
|
|
1599
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1600
|
+
import { join as join9 } from "path";
|
|
1598
1601
|
|
|
1599
1602
|
// cli/src/bootstrap.ts
|
|
1600
1603
|
init_download();
|
|
@@ -2186,6 +2189,114 @@ Select [1-${items.length}]: `);
|
|
|
2186
2189
|
// cli/src/launcher.ts
|
|
2187
2190
|
init_paths();
|
|
2188
2191
|
|
|
2192
|
+
// cli/src/embedded-database.ts
|
|
2193
|
+
import { spawn } from "child_process";
|
|
2194
|
+
import { existsSync as existsSync3 } from "fs";
|
|
2195
|
+
import { join as join7 } from "path";
|
|
2196
|
+
var EMBEDDED_DATABASE_PORT = 55433;
|
|
2197
|
+
var EMBEDDED_DATABASE_USER = "postgres";
|
|
2198
|
+
var EMBEDDED_DATABASE_PASSWORD = "postgres";
|
|
2199
|
+
var EMBEDDED_DATABASE_NAME = "lianrouter";
|
|
2200
|
+
function embeddedDatabaseUrl(port = EMBEDDED_DATABASE_PORT) {
|
|
2201
|
+
return `postgres://${EMBEDDED_DATABASE_USER}:${EMBEDDED_DATABASE_PASSWORD}@127.0.0.1:${port}/${EMBEDDED_DATABASE_NAME}`;
|
|
2202
|
+
}
|
|
2203
|
+
function resolveEmbeddedDatabaseDir(installRoot) {
|
|
2204
|
+
return join7(installRoot, "pgdata");
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
class EmbeddedDatabaseUnavailableError extends Error {
|
|
2208
|
+
constructor(message) {
|
|
2209
|
+
super(message);
|
|
2210
|
+
this.name = "EmbeddedDatabaseUnavailableError";
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
async function resolvePlatformBinary() {
|
|
2214
|
+
const platform = process.platform;
|
|
2215
|
+
const arch = process.arch;
|
|
2216
|
+
const packageName = platform === "win32" && arch === "x64" ? "@embedded-postgres/windows-x64" : platform === "darwin" && arch === "arm64" ? "@embedded-postgres/darwin-arm64" : platform === "darwin" && arch === "x64" ? "@embedded-postgres/darwin-x64" : platform === "linux" && arch === "x64" ? "@embedded-postgres/linux-x64" : platform === "linux" && arch === "arm64" ? "@embedded-postgres/linux-arm64" : platform === "linux" && arch === "arm" ? "@embedded-postgres/linux-arm" : undefined;
|
|
2217
|
+
if (packageName === undefined) {
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
try {
|
|
2221
|
+
const resolved = import.meta.resolve(packageName);
|
|
2222
|
+
const entryPath = resolved.startsWith("file:") ? new URL(resolved).pathname : resolved;
|
|
2223
|
+
const index = entryPath.lastIndexOf(`${packageName.replace("/", "/")}`);
|
|
2224
|
+
if (index === -1) {
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
const packageRoot = entryPath.slice(0, index + packageName.length);
|
|
2228
|
+
return { dir: packageRoot };
|
|
2229
|
+
} catch {
|
|
2230
|
+
return;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
async function stopOrphanCluster(databaseDir) {
|
|
2234
|
+
const dataDirectory = databaseDir;
|
|
2235
|
+
if (!existsSync3(join7(dataDirectory, "PG_VERSION"))) {
|
|
2236
|
+
return false;
|
|
2237
|
+
}
|
|
2238
|
+
const binary = await resolvePlatformBinary();
|
|
2239
|
+
if (binary === undefined) {
|
|
2240
|
+
return false;
|
|
2241
|
+
}
|
|
2242
|
+
const pgCtl = join7(binary.dir, "native", "bin", process.platform === "win32" ? "pg_ctl.exe" : "pg_ctl");
|
|
2243
|
+
if (!existsSync3(pgCtl)) {
|
|
2244
|
+
return false;
|
|
2245
|
+
}
|
|
2246
|
+
const { promise, resolve: settle } = Promise.withResolvers();
|
|
2247
|
+
const child = spawn(pgCtl, ["stop", "-D", dataDirectory, "-m", "fast", "-w"], {
|
|
2248
|
+
stdio: "ignore"
|
|
2249
|
+
});
|
|
2250
|
+
child.once("error", () => settle(false));
|
|
2251
|
+
child.once("exit", (code) => settle(code === 0));
|
|
2252
|
+
return await promise;
|
|
2253
|
+
}
|
|
2254
|
+
async function startEmbeddedDatabase(options) {
|
|
2255
|
+
const port = options.port ?? EMBEDDED_DATABASE_PORT;
|
|
2256
|
+
const databaseDir = resolveEmbeddedDatabaseDir(options.installRoot);
|
|
2257
|
+
let EmbeddedPostgres;
|
|
2258
|
+
try {
|
|
2259
|
+
({ default: EmbeddedPostgres } = await import("embedded-postgres"));
|
|
2260
|
+
} catch (error) {
|
|
2261
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
2262
|
+
throw new EmbeddedDatabaseUnavailableError(`DATABASE_MODE=embedded needs the \`embedded-postgres\` package, which is not installed here (${reason}). Reinstall the launcher, or set DATABASE_URL to a PostgreSQL server you already run.`);
|
|
2263
|
+
}
|
|
2264
|
+
const binary = await resolvePlatformBinary();
|
|
2265
|
+
if (binary === undefined) {
|
|
2266
|
+
throw new EmbeddedDatabaseUnavailableError(`DATABASE_MODE=embedded has no PostgreSQL binaries for ${process.platform}-${process.arch}. Set DATABASE_URL to a PostgreSQL server instead.`);
|
|
2267
|
+
}
|
|
2268
|
+
const log = options.onLog;
|
|
2269
|
+
const server = new EmbeddedPostgres({
|
|
2270
|
+
databaseDir,
|
|
2271
|
+
user: EMBEDDED_DATABASE_USER,
|
|
2272
|
+
password: EMBEDDED_DATABASE_PASSWORD,
|
|
2273
|
+
port,
|
|
2274
|
+
persistent: true,
|
|
2275
|
+
...log === undefined ? {} : { onLog: log, onError: (message) => log(String(message)) }
|
|
2276
|
+
});
|
|
2277
|
+
if (!existsSync3(join7(databaseDir, "PG_VERSION"))) {
|
|
2278
|
+
await server.initialise();
|
|
2279
|
+
} else if (await stopOrphanCluster(databaseDir)) {
|
|
2280
|
+
log?.("[launcher] reaped an embedded PostgreSQL cluster left by a previous run");
|
|
2281
|
+
}
|
|
2282
|
+
await server.start();
|
|
2283
|
+
try {
|
|
2284
|
+
await server.createDatabase(EMBEDDED_DATABASE_NAME);
|
|
2285
|
+
} catch {}
|
|
2286
|
+
const url = embeddedDatabaseUrl(port);
|
|
2287
|
+
let stopping;
|
|
2288
|
+
return {
|
|
2289
|
+
url,
|
|
2290
|
+
port,
|
|
2291
|
+
stop() {
|
|
2292
|
+
stopping ??= server.stop().catch(() => {
|
|
2293
|
+
return;
|
|
2294
|
+
});
|
|
2295
|
+
return stopping;
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2189
2300
|
// cli/src/shutdown.ts
|
|
2190
2301
|
init_paths();
|
|
2191
2302
|
import { rmSync } from "fs";
|
|
@@ -2462,7 +2573,8 @@ class GatewaySupervisor {
|
|
|
2462
2573
|
env,
|
|
2463
2574
|
stdin: "ignore",
|
|
2464
2575
|
stdout: "pipe",
|
|
2465
|
-
stderr: "pipe"
|
|
2576
|
+
stderr: "pipe",
|
|
2577
|
+
detached: true
|
|
2466
2578
|
});
|
|
2467
2579
|
} catch (error) {
|
|
2468
2580
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -2683,8 +2795,8 @@ class GatewaySupervisor {
|
|
|
2683
2795
|
// cli/src/install-config.ts
|
|
2684
2796
|
init_paths();
|
|
2685
2797
|
import { randomBytes } from "crypto";
|
|
2686
|
-
import { existsSync as
|
|
2687
|
-
var ALWAYS_REQUIRED = ["
|
|
2798
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
2799
|
+
var ALWAYS_REQUIRED = ["LIANROUTER_ENCRYPTION_KEY"];
|
|
2688
2800
|
function parseEnvFile(text) {
|
|
2689
2801
|
const values = {};
|
|
2690
2802
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
@@ -2713,7 +2825,7 @@ function parseEnvFile(text) {
|
|
|
2713
2825
|
}
|
|
2714
2826
|
function resolveGatewayConfig(installRoot, shellEnv = process.env) {
|
|
2715
2827
|
const path = resolveConfigFile(installRoot);
|
|
2716
|
-
const present =
|
|
2828
|
+
const present = existsSync4(path);
|
|
2717
2829
|
const fileValues = present ? parseEnvFile(readFileSync2(path, "utf8")) : {};
|
|
2718
2830
|
const env = {};
|
|
2719
2831
|
for (const [key, value] of Object.entries(fileValues)) {
|
|
@@ -2733,12 +2845,16 @@ function resolveGatewayConfig(installRoot, shellEnv = process.env) {
|
|
|
2733
2845
|
const fromFile = fileValues[name];
|
|
2734
2846
|
return fromFile !== undefined && fromFile.trim() !== "" ? fromFile.trim() : undefined;
|
|
2735
2847
|
};
|
|
2848
|
+
const databaseMode = (effective("DATABASE_MODE") ?? "url") === "embedded" ? "embedded" : "url";
|
|
2736
2849
|
const required = [...ALWAYS_REQUIRED];
|
|
2850
|
+
if (databaseMode !== "embedded") {
|
|
2851
|
+
required.push("DATABASE_URL");
|
|
2852
|
+
}
|
|
2737
2853
|
if ((effective("REDIS_MODE") ?? "normal") === "normal") {
|
|
2738
2854
|
required.push("REDIS_URL");
|
|
2739
2855
|
}
|
|
2740
2856
|
const missing = required.filter((name) => effective(name) === undefined);
|
|
2741
|
-
return { path, present, env, missing };
|
|
2857
|
+
return { path, present, env, missing, databaseMode };
|
|
2742
2858
|
}
|
|
2743
2859
|
function describeMissingConfig(config) {
|
|
2744
2860
|
const location = config.present ? ` config file: ${config.path}` : ` config file: ${config.path} (not found)`;
|
|
@@ -2758,8 +2874,11 @@ function describeMissingConfig(config) {
|
|
|
2758
2874
|
"or set them in your shell before starting; a shell value wins over the file.",
|
|
2759
2875
|
`run \`lianrouter init\` to write a starter file at ${config.path}`
|
|
2760
2876
|
];
|
|
2877
|
+
if (config.missing.includes("DATABASE_URL")) {
|
|
2878
|
+
lines.push("to have the launcher start a private PostgreSQL for you, set DATABASE_MODE=embedded instead of DATABASE_URL");
|
|
2879
|
+
}
|
|
2761
2880
|
if (config.missing.includes("REDIS_URL")) {
|
|
2762
|
-
lines.push("to run a
|
|
2881
|
+
lines.push("to run without a Redis server, set REDIS_MODE=embedded (in-process) or REDIS_MODE=single_instance_local (no Redis at all, and no console)");
|
|
2763
2882
|
}
|
|
2764
2883
|
return lines.join(`
|
|
2765
2884
|
`);
|
|
@@ -2775,10 +2894,12 @@ function starterConfigText(encryptionKey) {
|
|
|
2775
2894
|
# A variable already set in your shell wins over the value written here.
|
|
2776
2895
|
# Generated by \`lianrouter init\`.
|
|
2777
2896
|
|
|
2778
|
-
#
|
|
2779
|
-
#
|
|
2780
|
-
#
|
|
2897
|
+
# Database. DATABASE_MODE=embedded has the launcher start a private PostgreSQL
|
|
2898
|
+
# for this install and hand the gateway a DATABASE_URL pointing at it \u2014 nothing
|
|
2899
|
+
# to install, nothing to configure. To use your own server instead, delete the
|
|
2900
|
+
# DATABASE_MODE line and set DATABASE_URL:
|
|
2781
2901
|
# DATABASE_URL=postgres://user:password@localhost:5432/lianrouter
|
|
2902
|
+
DATABASE_MODE=embedded
|
|
2782
2903
|
|
|
2783
2904
|
# 256-bit key for encrypting provider credentials and hashing API keys.
|
|
2784
2905
|
# Required. Base64 (44 characters) or hex (64 characters); it must decode to
|
|
@@ -2786,26 +2907,68 @@ function starterConfigText(encryptionKey) {
|
|
|
2786
2907
|
# credentials encrypted with the old one.
|
|
2787
2908
|
LIANROUTER_ENCRYPTION_KEY=${encryptionKey}
|
|
2788
2909
|
|
|
2789
|
-
# Redis coordination.
|
|
2790
|
-
#
|
|
2791
|
-
#
|
|
2792
|
-
REDIS_MODE=
|
|
2910
|
+
# Redis coordination. \`embedded\` runs a Redis client inside the gateway process,
|
|
2911
|
+
# which is what a single-machine install wants; set REDIS_URL (with
|
|
2912
|
+
# REDIS_MODE=normal) to share coordination state with another process.
|
|
2913
|
+
REDIS_MODE=embedded
|
|
2793
2914
|
# REDIS_URL=redis://localhost:6379
|
|
2794
2915
|
`;
|
|
2795
2916
|
}
|
|
2917
|
+
function withoutActiveKey(text, key) {
|
|
2918
|
+
const pattern = new RegExp(`^[ \\t]*${key}[ \\t]*=`, "m");
|
|
2919
|
+
return text.split(/\r?\n/).filter((line) => !pattern.test(line)).join(`
|
|
2920
|
+
`);
|
|
2921
|
+
}
|
|
2922
|
+
function hasActiveKey(text, key) {
|
|
2923
|
+
return new RegExp(`^[ \\t]*${key}[ \\t]*=`, "m").test(text);
|
|
2924
|
+
}
|
|
2925
|
+
function appendEntry(text, key, value) {
|
|
2926
|
+
const body = text.endsWith(`
|
|
2927
|
+
`) ? text : `${text}
|
|
2928
|
+
`;
|
|
2929
|
+
return `${body}
|
|
2930
|
+
${key}=${value}
|
|
2931
|
+
`;
|
|
2932
|
+
}
|
|
2933
|
+
function upgradeStarterConfig(text, encryptionKey) {
|
|
2934
|
+
let next = text;
|
|
2935
|
+
const hasDatabaseUrl = hasActiveKey(next, "DATABASE_URL");
|
|
2936
|
+
if (!hasActiveKey(next, "DATABASE_MODE") && !hasDatabaseUrl) {
|
|
2937
|
+
next = appendEntry(next, "DATABASE_MODE", "embedded");
|
|
2938
|
+
}
|
|
2939
|
+
const redisMode = /^[ \t]*REDIS_MODE[ \t]*=[ \t]*(\S*)/m.exec(next)?.[1]?.replace(/^["']|["']$/g, "");
|
|
2940
|
+
const hasRedisUrl = hasActiveKey(next, "REDIS_URL");
|
|
2941
|
+
if (!hasActiveKey(next, "REDIS_MODE") && !hasRedisUrl) {
|
|
2942
|
+
next = appendEntry(next, "REDIS_MODE", "embedded");
|
|
2943
|
+
} else if (redisMode === "normal" && !hasRedisUrl) {
|
|
2944
|
+
next = withoutActiveKey(next, "REDIS_MODE");
|
|
2945
|
+
next = appendEntry(next, "REDIS_MODE", "embedded");
|
|
2946
|
+
}
|
|
2947
|
+
const existingKey = parseEnvFile(next).LIANROUTER_ENCRYPTION_KEY;
|
|
2948
|
+
if (existingKey === undefined || existingKey.trim() === "") {
|
|
2949
|
+
next = appendEntry(next, "LIANROUTER_ENCRYPTION_KEY", encryptionKey);
|
|
2950
|
+
}
|
|
2951
|
+
return next;
|
|
2952
|
+
}
|
|
2796
2953
|
function writeStarterConfig(installRoot) {
|
|
2797
2954
|
const path = resolveConfigFile(installRoot);
|
|
2798
2955
|
mkdirSync2(installRoot, { recursive: true });
|
|
2799
2956
|
const encryptionKey = randomBytes(32).toString("base64");
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2957
|
+
if (existsSync4(path)) {
|
|
2958
|
+
const current = readFileSync2(path, "utf8");
|
|
2959
|
+
const preserved = parseEnvFile(current).LIANROUTER_ENCRYPTION_KEY;
|
|
2960
|
+
const key = preserved !== undefined && preserved.trim() !== "" ? preserved : encryptionKey;
|
|
2961
|
+
const migrated = upgradeStarterConfig(current, key);
|
|
2962
|
+
if (migrated === current) {
|
|
2963
|
+
return { path, kind: "unchanged" };
|
|
2964
|
+
}
|
|
2965
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
2966
|
+
writeFileSync(`${path}.bak-${stamp}`, current, { encoding: "utf8" });
|
|
2967
|
+
writeFileSync(path, migrated, { encoding: "utf8" });
|
|
2968
|
+
return { path, kind: "migrated" };
|
|
2969
|
+
}
|
|
2970
|
+
writeFileSync(path, starterConfigText(encryptionKey), { encoding: "utf8", flag: "wx" });
|
|
2971
|
+
return { path, kind: "created" };
|
|
2809
2972
|
}
|
|
2810
2973
|
|
|
2811
2974
|
// cli/src/update-flow.ts
|
|
@@ -2947,19 +3110,97 @@ async function checkLauncherVersion(options) {
|
|
|
2947
3110
|
|
|
2948
3111
|
// cli/src/tray-launcher.ts
|
|
2949
3112
|
init_paths();
|
|
2950
|
-
import { existsSync as
|
|
3113
|
+
import { existsSync as existsSync5 } from "fs";
|
|
2951
3114
|
import { readFile as readFile2, rm as rm8, writeFile as writeFile3 } from "fs/promises";
|
|
2952
|
-
import { join as
|
|
3115
|
+
import { join as join8 } from "path";
|
|
3116
|
+
|
|
3117
|
+
// cli/tray/win32.ts
|
|
3118
|
+
import { dlopen, ptr, toBuffer } from "bun:ffi";
|
|
3119
|
+
var SW_HIDE = 0;
|
|
3120
|
+
function openUser32() {
|
|
3121
|
+
return dlopen("user32.dll", {
|
|
3122
|
+
RegisterClassExW: { args: ["ptr"], returns: "u16" },
|
|
3123
|
+
UnregisterClassW: { args: ["ptr", "ptr"], returns: "i32" },
|
|
3124
|
+
CreateWindowExW: {
|
|
3125
|
+
args: ["u32", "ptr", "ptr", "u32", "i32", "i32", "i32", "i32", "ptr", "ptr", "ptr", "ptr"],
|
|
3126
|
+
returns: "ptr"
|
|
3127
|
+
},
|
|
3128
|
+
DefWindowProcW: { args: ["ptr", "u32", "u64", "i64"], returns: "i64" },
|
|
3129
|
+
DestroyWindow: { args: ["ptr"], returns: "i32" },
|
|
3130
|
+
PeekMessageW: { args: ["ptr", "ptr", "u32", "u32", "u32"], returns: "i32" },
|
|
3131
|
+
TranslateMessage: { args: ["ptr"], returns: "i32" },
|
|
3132
|
+
DispatchMessageW: { args: ["ptr"], returns: "i64" },
|
|
3133
|
+
PostQuitMessage: { args: ["i32"], returns: "void" },
|
|
3134
|
+
PostMessageW: { args: ["ptr", "u32", "u64", "i64"], returns: "i32" },
|
|
3135
|
+
SetForegroundWindow: { args: ["ptr"], returns: "i32" },
|
|
3136
|
+
GetCursorPos: { args: ["ptr"], returns: "i32" },
|
|
3137
|
+
CreatePopupMenu: { args: [], returns: "ptr" },
|
|
3138
|
+
AppendMenuW: { args: ["ptr", "u32", "u64", "ptr"], returns: "i32" },
|
|
3139
|
+
TrackPopupMenu: { args: ["ptr", "u32", "i32", "i32", "i32", "ptr", "ptr"], returns: "i32" },
|
|
3140
|
+
DestroyMenu: { args: ["ptr"], returns: "i32" },
|
|
3141
|
+
LoadImageW: { args: ["ptr", "ptr", "u32", "i32", "i32", "u32"], returns: "ptr" },
|
|
3142
|
+
LoadIconW: { args: ["ptr", "ptr"], returns: "ptr" },
|
|
3143
|
+
CreateIconIndirect: { args: ["ptr"], returns: "ptr" },
|
|
3144
|
+
DestroyIcon: { args: ["ptr"], returns: "i32" },
|
|
3145
|
+
GetDC: { args: ["ptr"], returns: "ptr" },
|
|
3146
|
+
ReleaseDC: { args: ["ptr", "ptr"], returns: "i32" },
|
|
3147
|
+
GetSystemMetrics: { args: ["i32"], returns: "i32" },
|
|
3148
|
+
IsWindowVisible: { args: ["ptr"], returns: "i32" },
|
|
3149
|
+
ShowWindow: { args: ["ptr", "i32"], returns: "i32" },
|
|
3150
|
+
MessageBoxW: { args: ["ptr", "ptr", "ptr", "u32"], returns: "i32" }
|
|
3151
|
+
});
|
|
3152
|
+
}
|
|
3153
|
+
function openShell32() {
|
|
3154
|
+
return dlopen("shell32.dll", {
|
|
3155
|
+
Shell_NotifyIconW: { args: ["u32", "ptr"], returns: "i32" }
|
|
3156
|
+
});
|
|
3157
|
+
}
|
|
3158
|
+
function openKernel32() {
|
|
3159
|
+
return dlopen("kernel32.dll", {
|
|
3160
|
+
GetModuleHandleW: { args: ["ptr"], returns: "ptr" },
|
|
3161
|
+
GetLastError: { args: [], returns: "u32" },
|
|
3162
|
+
GetConsoleWindow: { args: [], returns: "ptr" }
|
|
3163
|
+
});
|
|
3164
|
+
}
|
|
3165
|
+
function openGdi32() {
|
|
3166
|
+
return dlopen("gdi32.dll", {
|
|
3167
|
+
CreateCompatibleDC: { args: ["ptr"], returns: "ptr" },
|
|
3168
|
+
DeleteDC: { args: ["ptr"], returns: "i32" },
|
|
3169
|
+
CreateDIBSection: { args: ["ptr", "ptr", "u32", "ptr", "ptr", "u32"], returns: "ptr" },
|
|
3170
|
+
SelectObject: { args: ["ptr", "ptr"], returns: "ptr" },
|
|
3171
|
+
DeleteObject: { args: ["ptr"], returns: "i32" }
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
var api;
|
|
3175
|
+
function getWin32() {
|
|
3176
|
+
if (api === undefined) {
|
|
3177
|
+
api = {
|
|
3178
|
+
user32: openUser32().symbols,
|
|
3179
|
+
shell32: openShell32().symbols,
|
|
3180
|
+
kernel32: openKernel32().symbols,
|
|
3181
|
+
gdi32: openGdi32().symbols
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
return api;
|
|
3185
|
+
}
|
|
3186
|
+
function toHandle(value) {
|
|
3187
|
+
if (value === null || value === undefined)
|
|
3188
|
+
return;
|
|
3189
|
+
const handle = typeof value === "bigint" ? value : BigInt(value);
|
|
3190
|
+
return handle === 0n ? undefined : handle;
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
// cli/src/tray-launcher.ts
|
|
2953
3194
|
function resolveTrayEntry(options) {
|
|
2954
|
-
return trayEntryCandidates(options).find((candidate) =>
|
|
3195
|
+
return trayEntryCandidates(options).find((candidate) => existsSync5(candidate));
|
|
2955
3196
|
}
|
|
2956
3197
|
function trayEntryCandidates(options) {
|
|
2957
3198
|
const bundleDir = options.bundleDir ?? moduleDir;
|
|
2958
3199
|
const candidates = [];
|
|
2959
3200
|
if (options.devRepoRoot !== undefined) {
|
|
2960
|
-
candidates.push(
|
|
3201
|
+
candidates.push(join8(options.devRepoRoot, "cli", "dist", "tray.js"));
|
|
2961
3202
|
}
|
|
2962
|
-
candidates.push(
|
|
3203
|
+
candidates.push(join8(bundleDir, "tray.js"));
|
|
2963
3204
|
return candidates;
|
|
2964
3205
|
}
|
|
2965
3206
|
async function startTray(options) {
|
|
@@ -2994,7 +3235,8 @@ async function startTray(options) {
|
|
|
2994
3235
|
env,
|
|
2995
3236
|
stdin: "ignore",
|
|
2996
3237
|
stdout: "ignore",
|
|
2997
|
-
stderr: "ignore"
|
|
3238
|
+
stderr: "ignore",
|
|
3239
|
+
detached: true
|
|
2998
3240
|
});
|
|
2999
3241
|
child.unref();
|
|
3000
3242
|
pid = child.pid;
|
|
@@ -3049,15 +3291,13 @@ function hideConsoleWindow() {
|
|
|
3049
3291
|
if (process.platform !== "win32") {
|
|
3050
3292
|
return false;
|
|
3051
3293
|
}
|
|
3052
|
-
const script = [
|
|
3053
|
-
"Add-Type -Name Win -Namespace Native -MemberDefinition",
|
|
3054
|
-
`'[DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow();`,
|
|
3055
|
-
`[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);';`,
|
|
3056
|
-
"[void][Native.Win]::ShowWindow([Native.Win]::GetConsoleWindow(), 0)"
|
|
3057
|
-
].join(" ");
|
|
3058
3294
|
try {
|
|
3059
|
-
const
|
|
3060
|
-
|
|
3295
|
+
const { kernel32, user32 } = getWin32();
|
|
3296
|
+
const window = toHandle(kernel32.GetConsoleWindow());
|
|
3297
|
+
if (window === undefined)
|
|
3298
|
+
return false;
|
|
3299
|
+
user32.ShowWindow(window, SW_HIDE);
|
|
3300
|
+
return user32.IsWindowVisible(window) === 0;
|
|
3061
3301
|
} catch {
|
|
3062
3302
|
return false;
|
|
3063
3303
|
}
|
|
@@ -3205,7 +3445,7 @@ function readPortEnv() {
|
|
|
3205
3445
|
}
|
|
3206
3446
|
function resolveRuntime() {
|
|
3207
3447
|
const repoRoot = resolveDevRepoRoot();
|
|
3208
|
-
if (repoRoot !== undefined &&
|
|
3448
|
+
if (repoRoot !== undefined && existsSync6(join9(repoRoot, "src", "app.ts"))) {
|
|
3209
3449
|
return {
|
|
3210
3450
|
installRoot: resolveInstallRoot(),
|
|
3211
3451
|
cwd: repoRoot,
|
|
@@ -3217,7 +3457,7 @@ function resolveRuntime() {
|
|
|
3217
3457
|
return { installRoot, cwd: installRoot, command: undefined, devRepoRoot: undefined };
|
|
3218
3458
|
}
|
|
3219
3459
|
async function ensureInstalledGateway(installRoot) {
|
|
3220
|
-
const present =
|
|
3460
|
+
const present = existsSync6(resolveBinaryPath(installRoot));
|
|
3221
3461
|
if (present) {
|
|
3222
3462
|
await ensureGatewayInstalled({ installRoot, currentVersion: CLI_VERSION });
|
|
3223
3463
|
return;
|
|
@@ -3252,16 +3492,28 @@ async function run(argv) {
|
|
|
3252
3492
|
}
|
|
3253
3493
|
const runtime = resolveRuntime();
|
|
3254
3494
|
if (options.command === "init") {
|
|
3255
|
-
const
|
|
3256
|
-
console.log(`Wrote ${path}`);
|
|
3257
|
-
console.log("
|
|
3495
|
+
const config = writeStarterConfig(runtime.installRoot);
|
|
3496
|
+
console.log(config.kind === "created" ? `Wrote ${config.path}` : `Updated ${config.path} (previous file kept beside it)`);
|
|
3497
|
+
console.log("It starts a private PostgreSQL for this install (DATABASE_MODE=embedded) and an " + "in-process Redis, so `lianrouter` works as-is. Point DATABASE_URL at your own " + "server instead if you prefer.");
|
|
3258
3498
|
return 0;
|
|
3259
3499
|
}
|
|
3260
3500
|
const startsGateway = options.command === undefined || options.command === "start" || options.command === "tray" || options.command === "tui";
|
|
3261
|
-
|
|
3501
|
+
let gatewayConfig = runtime.command === undefined && startsGateway ? resolveGatewayConfig(runtime.installRoot) : undefined;
|
|
3502
|
+
if (gatewayConfig !== undefined && gatewayConfig.missing.length > 0) {
|
|
3503
|
+
const prepared = writeStarterConfig(runtime.installRoot);
|
|
3504
|
+
if (prepared.kind !== "unchanged") {
|
|
3505
|
+
console.log(prepared.kind === "created" ? `Wrote ${prepared.path}` : `Updated ${prepared.path} so the gateway can start (previous file kept beside it)`);
|
|
3506
|
+
}
|
|
3507
|
+
gatewayConfig = resolveGatewayConfig(runtime.installRoot);
|
|
3508
|
+
}
|
|
3262
3509
|
if (gatewayConfig !== undefined) {
|
|
3263
3510
|
assertGatewayConfigured(gatewayConfig);
|
|
3264
3511
|
}
|
|
3512
|
+
const embeddedDatabase = gatewayConfig?.databaseMode === "embedded" && startsGateway ? await startEmbeddedDatabase({ installRoot: runtime.installRoot }) : undefined;
|
|
3513
|
+
if (embeddedDatabase !== undefined && options.background) {
|
|
3514
|
+
await embeddedDatabase.stop();
|
|
3515
|
+
throw new Error("DATABASE_MODE=embedded keeps PostgreSQL inside this process, so --background " + "cannot return and leave it running. Use `lianrouter tray` for a background " + "install with an icon, or set DATABASE_URL to a server that outlives the launcher.");
|
|
3516
|
+
}
|
|
3265
3517
|
if (runtime.command === undefined && options.command !== "status" && options.command !== "stop") {
|
|
3266
3518
|
await ensureInstalledGateway(runtime.installRoot);
|
|
3267
3519
|
}
|
|
@@ -3272,7 +3524,8 @@ async function run(argv) {
|
|
|
3272
3524
|
cwd: runtime.cwd,
|
|
3273
3525
|
env: {
|
|
3274
3526
|
LIANROUTER_LAUNCHER_HOME: runtime.installRoot,
|
|
3275
|
-
...gatewayConfig?.env ?? {}
|
|
3527
|
+
...gatewayConfig?.env ?? {},
|
|
3528
|
+
...embeddedDatabase === undefined ? {} : { DATABASE_URL: embeddedDatabase.url }
|
|
3276
3529
|
},
|
|
3277
3530
|
...runtime.command === undefined ? {} : { command: runtime.command }
|
|
3278
3531
|
});
|
|
@@ -3282,21 +3535,21 @@ async function run(argv) {
|
|
|
3282
3535
|
case "stop":
|
|
3283
3536
|
return await stopServer(supervisor);
|
|
3284
3537
|
case "start":
|
|
3285
|
-
return await withShutdownHandlers(supervisor, runtime, () => runInteractive(supervisor, options, runtime));
|
|
3538
|
+
return await withShutdownHandlers(supervisor, runtime, () => runInteractive(supervisor, options, runtime), embeddedDatabase);
|
|
3286
3539
|
case "tray":
|
|
3287
|
-
return await withShutdownHandlers(supervisor, runtime, () => enterTrayMode(supervisor, options, runtime));
|
|
3540
|
+
return await withShutdownHandlers(supervisor, runtime, () => enterTrayMode(supervisor, options, runtime), embeddedDatabase);
|
|
3288
3541
|
case "tui":
|
|
3289
|
-
return await withShutdownHandlers(supervisor, runtime, () => runTui2(supervisor, options, runtime));
|
|
3542
|
+
return await withShutdownHandlers(supervisor, runtime, () => runTui2(supervisor, options, runtime), embeddedDatabase);
|
|
3290
3543
|
case "update":
|
|
3291
3544
|
return await runUpdateFlow(supervisor, runtime);
|
|
3292
3545
|
case undefined:
|
|
3293
|
-
return await withShutdownHandlers(supervisor, runtime, () => runInteractive(supervisor, options, runtime));
|
|
3546
|
+
return await withShutdownHandlers(supervisor, runtime, () => runInteractive(supervisor, options, runtime), embeddedDatabase);
|
|
3294
3547
|
default:
|
|
3295
3548
|
throw new Error(`unknown command ${options.command}`);
|
|
3296
3549
|
}
|
|
3297
3550
|
}
|
|
3298
3551
|
var activeControl;
|
|
3299
|
-
async function withShutdownHandlers(supervisor, runtime, command) {
|
|
3552
|
+
async function withShutdownHandlers(supervisor, runtime, command, embeddedDatabase) {
|
|
3300
3553
|
const registration = installShutdownHandlers(() => shutdownSessionFiles({
|
|
3301
3554
|
installRoot: runtime.installRoot,
|
|
3302
3555
|
stopControl: async () => {
|
|
@@ -3307,6 +3560,7 @@ async function withShutdownHandlers(supervisor, runtime, command) {
|
|
|
3307
3560
|
stopGateway: async () => {
|
|
3308
3561
|
await supervisor.stop();
|
|
3309
3562
|
await supervisor.dispose();
|
|
3563
|
+
await embeddedDatabase?.stop();
|
|
3310
3564
|
}
|
|
3311
3565
|
}), (code) => process.exit(code));
|
|
3312
3566
|
try {
|
package/dist/tray.js
CHANGED
|
@@ -469,6 +469,8 @@ function openUser32() {
|
|
|
469
469
|
GetDC: { args: ["ptr"], returns: "ptr" },
|
|
470
470
|
ReleaseDC: { args: ["ptr", "ptr"], returns: "i32" },
|
|
471
471
|
GetSystemMetrics: { args: ["i32"], returns: "i32" },
|
|
472
|
+
IsWindowVisible: { args: ["ptr"], returns: "i32" },
|
|
473
|
+
ShowWindow: { args: ["ptr", "i32"], returns: "i32" },
|
|
472
474
|
MessageBoxW: { args: ["ptr", "ptr", "ptr", "u32"], returns: "i32" }
|
|
473
475
|
});
|
|
474
476
|
}
|
|
@@ -480,7 +482,8 @@ function openShell32() {
|
|
|
480
482
|
function openKernel32() {
|
|
481
483
|
return dlopen("kernel32.dll", {
|
|
482
484
|
GetModuleHandleW: { args: ["ptr"], returns: "ptr" },
|
|
483
|
-
GetLastError: { args: [], returns: "u32" }
|
|
485
|
+
GetLastError: { args: [], returns: "u32" },
|
|
486
|
+
GetConsoleWindow: { args: [], returns: "ptr" }
|
|
484
487
|
});
|
|
485
488
|
}
|
|
486
489
|
function openGdi32() {
|
|
@@ -1207,7 +1210,8 @@ async function main() {
|
|
|
1207
1210
|
env: { ...process.env, LIANROUTER_HOME: installRoot },
|
|
1208
1211
|
stdin: "ignore",
|
|
1209
1212
|
stdout: "ignore",
|
|
1210
|
-
stderr: "ignore"
|
|
1213
|
+
stderr: "ignore",
|
|
1214
|
+
detached: true
|
|
1211
1215
|
});
|
|
1212
1216
|
child.unref();
|
|
1213
1217
|
return child.pid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lianrouter",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
4
4
|
"description": "LianRouter launcher: install, run and control the gateway from one command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"postinstall": "echo lianrouter: the gateway binary installs on first run, not during this install",
|
|
20
20
|
"prepublishOnly": "bun run build"
|
|
21
21
|
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"embedded-postgres": "18.6.0-beta.19"
|
|
24
|
+
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
24
27
|
"url": "git+https://github.com/ReXooGen/Lian-Router.git",
|