lianrouter 2.3.4 → 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 +150 -23
- package/dist/tray.js +6 -2
- package/package.json +1 -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: {
|
|
@@ -2573,7 +2573,8 @@ class GatewaySupervisor {
|
|
|
2573
2573
|
env,
|
|
2574
2574
|
stdin: "ignore",
|
|
2575
2575
|
stdout: "pipe",
|
|
2576
|
-
stderr: "pipe"
|
|
2576
|
+
stderr: "pipe",
|
|
2577
|
+
detached: true
|
|
2577
2578
|
});
|
|
2578
2579
|
} catch (error) {
|
|
2579
2580
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -2913,19 +2914,61 @@ REDIS_MODE=embedded
|
|
|
2913
2914
|
# REDIS_URL=redis://localhost:6379
|
|
2914
2915
|
`;
|
|
2915
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
|
+
}
|
|
2916
2953
|
function writeStarterConfig(installRoot) {
|
|
2917
2954
|
const path = resolveConfigFile(installRoot);
|
|
2918
2955
|
mkdirSync2(installRoot, { recursive: true });
|
|
2919
2956
|
const encryptionKey = randomBytes(32).toString("base64");
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
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" };
|
|
2929
2972
|
}
|
|
2930
2973
|
|
|
2931
2974
|
// cli/src/update-flow.ts
|
|
@@ -3070,6 +3113,84 @@ init_paths();
|
|
|
3070
3113
|
import { existsSync as existsSync5 } from "fs";
|
|
3071
3114
|
import { readFile as readFile2, rm as rm8, writeFile as writeFile3 } from "fs/promises";
|
|
3072
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
|
|
3073
3194
|
function resolveTrayEntry(options) {
|
|
3074
3195
|
return trayEntryCandidates(options).find((candidate) => existsSync5(candidate));
|
|
3075
3196
|
}
|
|
@@ -3114,7 +3235,8 @@ async function startTray(options) {
|
|
|
3114
3235
|
env,
|
|
3115
3236
|
stdin: "ignore",
|
|
3116
3237
|
stdout: "ignore",
|
|
3117
|
-
stderr: "ignore"
|
|
3238
|
+
stderr: "ignore",
|
|
3239
|
+
detached: true
|
|
3118
3240
|
});
|
|
3119
3241
|
child.unref();
|
|
3120
3242
|
pid = child.pid;
|
|
@@ -3169,15 +3291,13 @@ function hideConsoleWindow() {
|
|
|
3169
3291
|
if (process.platform !== "win32") {
|
|
3170
3292
|
return false;
|
|
3171
3293
|
}
|
|
3172
|
-
const script = [
|
|
3173
|
-
"Add-Type -Name Win -Namespace Native -MemberDefinition",
|
|
3174
|
-
`'[DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow();`,
|
|
3175
|
-
`[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);';`,
|
|
3176
|
-
"[void][Native.Win]::ShowWindow([Native.Win]::GetConsoleWindow(), 0)"
|
|
3177
|
-
].join(" ");
|
|
3178
3294
|
try {
|
|
3179
|
-
const
|
|
3180
|
-
|
|
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;
|
|
3181
3301
|
} catch {
|
|
3182
3302
|
return false;
|
|
3183
3303
|
}
|
|
@@ -3372,13 +3492,20 @@ async function run(argv) {
|
|
|
3372
3492
|
}
|
|
3373
3493
|
const runtime = resolveRuntime();
|
|
3374
3494
|
if (options.command === "init") {
|
|
3375
|
-
const
|
|
3376
|
-
console.log(`Wrote ${path}`);
|
|
3495
|
+
const config = writeStarterConfig(runtime.installRoot);
|
|
3496
|
+
console.log(config.kind === "created" ? `Wrote ${config.path}` : `Updated ${config.path} (previous file kept beside it)`);
|
|
3377
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.");
|
|
3378
3498
|
return 0;
|
|
3379
3499
|
}
|
|
3380
3500
|
const startsGateway = options.command === undefined || options.command === "start" || options.command === "tray" || options.command === "tui";
|
|
3381
|
-
|
|
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
|
+
}
|
|
3382
3509
|
if (gatewayConfig !== undefined) {
|
|
3383
3510
|
assertGatewayConfigured(gatewayConfig);
|
|
3384
3511
|
}
|
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;
|