feat: guide control ui access without gui
This commit is contained in:
@@ -83,6 +83,7 @@ It does **not** install or change anything on the remote host.
|
|||||||
|
|
||||||
9) **Finish**
|
9) **Finish**
|
||||||
- Summary + next steps, including iOS/Android/macOS apps for extra features.
|
- Summary + next steps, including iOS/Android/macOS apps for extra features.
|
||||||
|
- If no GUI is detected, the wizard prints SSH port-forward instructions for the Control UI instead of opening a browser.
|
||||||
|
|
||||||
## Remote mode
|
## Remote mode
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
applyWizardMetadata,
|
applyWizardMetadata,
|
||||||
DEFAULT_WORKSPACE,
|
DEFAULT_WORKSPACE,
|
||||||
|
detectBrowserOpenSupport,
|
||||||
ensureWorkspaceAndSessions,
|
ensureWorkspaceAndSessions,
|
||||||
|
formatControlUiSshHint,
|
||||||
guardCancel,
|
guardCancel,
|
||||||
openUrl,
|
openUrl,
|
||||||
printWizardHeader,
|
printWizardHeader,
|
||||||
@@ -630,21 +632,43 @@ export async function runConfigureWizard(
|
|||||||
"Control UI",
|
"Control UI",
|
||||||
);
|
);
|
||||||
|
|
||||||
const wantsOpen = guardCancel(
|
const browserSupport = await detectBrowserOpenSupport();
|
||||||
await confirm({
|
if (!browserSupport.ok) {
|
||||||
message: "Open Control UI now?",
|
note(
|
||||||
initialValue: false,
|
formatControlUiSshHint({
|
||||||
}),
|
port: gatewayPort,
|
||||||
runtime,
|
basePath: nextConfig.gateway?.controlUi?.basePath,
|
||||||
);
|
token: gatewayToken,
|
||||||
if (wantsOpen) {
|
}),
|
||||||
const bind = nextConfig.gateway?.bind ?? "loopback";
|
"Open Control UI",
|
||||||
const links = resolveControlUiLinks({
|
);
|
||||||
bind,
|
} else {
|
||||||
port: gatewayPort,
|
const wantsOpen = guardCancel(
|
||||||
basePath: nextConfig.gateway?.controlUi?.basePath,
|
await confirm({
|
||||||
});
|
message: "Open Control UI now?",
|
||||||
await openUrl(links.httpUrl);
|
initialValue: false,
|
||||||
|
}),
|
||||||
|
runtime,
|
||||||
|
);
|
||||||
|
if (wantsOpen) {
|
||||||
|
const bind = nextConfig.gateway?.bind ?? "loopback";
|
||||||
|
const links = resolveControlUiLinks({
|
||||||
|
bind,
|
||||||
|
port: gatewayPort,
|
||||||
|
basePath: nextConfig.gateway?.controlUi?.basePath,
|
||||||
|
});
|
||||||
|
const opened = await openUrl(links.httpUrl);
|
||||||
|
if (!opened) {
|
||||||
|
note(
|
||||||
|
formatControlUiSshHint({
|
||||||
|
port: gatewayPort,
|
||||||
|
basePath: nextConfig.gateway?.controlUi?.basePath,
|
||||||
|
token: gatewayToken,
|
||||||
|
}),
|
||||||
|
"Open Control UI",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outro("Configure complete.");
|
outro("Configure complete.");
|
||||||
|
|||||||
@@ -83,18 +83,126 @@ export function applyWizardMetadata(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function openUrl(url: string): Promise<void> {
|
type BrowserOpenSupport = {
|
||||||
|
ok: boolean;
|
||||||
|
reason?: string;
|
||||||
|
command?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
let wslCached: boolean | null = null;
|
||||||
|
|
||||||
|
async function isWSL(): Promise<boolean> {
|
||||||
|
if (wslCached !== null) return wslCached;
|
||||||
|
if (process.platform !== "linux") {
|
||||||
|
wslCached = false;
|
||||||
|
return wslCached;
|
||||||
|
}
|
||||||
|
if (process.env.WSL_INTEROP || process.env.WSL_DISTRO_NAME || process.env.WSLENV) {
|
||||||
|
wslCached = true;
|
||||||
|
return wslCached;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const release = (await fs.readFile("/proc/version", "utf8")).toLowerCase();
|
||||||
|
wslCached = release.includes("microsoft") || release.includes("wsl");
|
||||||
|
} catch {
|
||||||
|
wslCached = false;
|
||||||
|
}
|
||||||
|
return wslCached;
|
||||||
|
}
|
||||||
|
|
||||||
|
type BrowserOpenCommand = {
|
||||||
|
argv: string[] | null;
|
||||||
|
reason?: string;
|
||||||
|
command?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function resolveBrowserOpenCommand(): Promise<BrowserOpenCommand> {
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
const command =
|
const hasDisplay = Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
||||||
platform === "darwin"
|
const isSsh =
|
||||||
? ["open", url]
|
Boolean(process.env.SSH_CLIENT) ||
|
||||||
: platform === "win32"
|
Boolean(process.env.SSH_TTY) ||
|
||||||
? ["cmd", "/c", "start", "", url]
|
Boolean(process.env.SSH_CONNECTION);
|
||||||
: ["xdg-open", url];
|
|
||||||
|
if (isSsh && !hasDisplay && platform !== "win32") {
|
||||||
|
return { argv: null, reason: "ssh-no-display" };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (platform === "win32") {
|
||||||
|
return { argv: ["cmd", "/c", "start", ""], command: "cmd" };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (platform === "darwin") {
|
||||||
|
const hasOpen = await detectBinary("open");
|
||||||
|
return hasOpen
|
||||||
|
? { argv: ["open"], command: "open" }
|
||||||
|
: { argv: null, reason: "missing-open" };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (platform === "linux") {
|
||||||
|
const wsl = await isWSL();
|
||||||
|
if (!hasDisplay && !wsl) {
|
||||||
|
return { argv: null, reason: "no-display" };
|
||||||
|
}
|
||||||
|
if (wsl) {
|
||||||
|
const hasWslview = await detectBinary("wslview");
|
||||||
|
if (hasWslview) return { argv: ["wslview"], command: "wslview" };
|
||||||
|
if (!hasDisplay) return { argv: null, reason: "wsl-no-wslview" };
|
||||||
|
}
|
||||||
|
const hasXdgOpen = await detectBinary("xdg-open");
|
||||||
|
return hasXdgOpen
|
||||||
|
? { argv: ["xdg-open"], command: "xdg-open" }
|
||||||
|
: { argv: null, reason: "missing-xdg-open" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { argv: null, reason: "unsupported-platform" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function detectBrowserOpenSupport(): Promise<BrowserOpenSupport> {
|
||||||
|
const resolved = await resolveBrowserOpenCommand();
|
||||||
|
if (!resolved.argv) return { ok: false, reason: resolved.reason };
|
||||||
|
return { ok: true, command: resolved.command };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatControlUiSshHint(params: {
|
||||||
|
port: number;
|
||||||
|
basePath?: string;
|
||||||
|
token?: string;
|
||||||
|
}): string {
|
||||||
|
const basePath = normalizeControlUiBasePath(params.basePath);
|
||||||
|
const uiPath = basePath ? `${basePath}/` : "/";
|
||||||
|
const localUrl = `http://localhost:${params.port}${uiPath}`;
|
||||||
|
const tokenParam = params.token ? `?token=${encodeURIComponent(params.token)}` : "";
|
||||||
|
const authedUrl = params.token ? `${localUrl}${tokenParam}` : undefined;
|
||||||
|
const sshTarget = resolveSshTargetHint();
|
||||||
|
return [
|
||||||
|
"No GUI detected. Open from your computer:",
|
||||||
|
`ssh -N -L ${params.port}:127.0.0.1:${params.port} ${sshTarget}`,
|
||||||
|
"Then open:",
|
||||||
|
localUrl,
|
||||||
|
authedUrl,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveSshTargetHint(): string {
|
||||||
|
const user = process.env.USER || process.env.LOGNAME || "user";
|
||||||
|
const conn = process.env.SSH_CONNECTION?.trim().split(/\s+/);
|
||||||
|
const host = conn?.[2] ?? "<host>";
|
||||||
|
return `${user}@${host}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function openUrl(url: string): Promise<boolean> {
|
||||||
|
const resolved = await resolveBrowserOpenCommand();
|
||||||
|
if (!resolved.argv) return false;
|
||||||
|
const command = [...resolved.argv, url];
|
||||||
try {
|
try {
|
||||||
await runCommandWithTimeout(command, { timeoutMs: 5_000 });
|
await runCommandWithTimeout(command, { timeoutMs: 5_000 });
|
||||||
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
// ignore; we still print the URL for manual open
|
// ignore; we still print the URL for manual open
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
applyWizardMetadata,
|
applyWizardMetadata,
|
||||||
DEFAULT_WORKSPACE,
|
DEFAULT_WORKSPACE,
|
||||||
|
detectBrowserOpenSupport,
|
||||||
ensureWorkspaceAndSessions,
|
ensureWorkspaceAndSessions,
|
||||||
|
formatControlUiSshHint,
|
||||||
handleReset,
|
handleReset,
|
||||||
openUrl,
|
openUrl,
|
||||||
printWizardHeader,
|
printWizardHeader,
|
||||||
@@ -522,21 +524,43 @@ export async function runOnboardingWizard(
|
|||||||
"Control UI",
|
"Control UI",
|
||||||
);
|
);
|
||||||
|
|
||||||
const wantsOpen = await prompter.confirm({
|
const browserSupport = await detectBrowserOpenSupport();
|
||||||
message: "Open Control UI now?",
|
if (!browserSupport.ok) {
|
||||||
initialValue: true,
|
await prompter.note(
|
||||||
});
|
formatControlUiSshHint({
|
||||||
if (wantsOpen) {
|
port,
|
||||||
const links = resolveControlUiLinks({
|
basePath: baseConfig.gateway?.controlUi?.basePath,
|
||||||
bind,
|
token: authMode === "token" ? gatewayToken : undefined,
|
||||||
port,
|
}),
|
||||||
basePath: baseConfig.gateway?.controlUi?.basePath,
|
"Open Control UI",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const wantsOpen = await prompter.confirm({
|
||||||
|
message: "Open Control UI now?",
|
||||||
|
initialValue: true,
|
||||||
});
|
});
|
||||||
const tokenParam =
|
if (wantsOpen) {
|
||||||
authMode === "token" && gatewayToken
|
const links = resolveControlUiLinks({
|
||||||
? `?token=${encodeURIComponent(gatewayToken)}`
|
bind,
|
||||||
: "";
|
port,
|
||||||
await openUrl(`${links.httpUrl}${tokenParam}`);
|
basePath: baseConfig.gateway?.controlUi?.basePath,
|
||||||
|
});
|
||||||
|
const tokenParam =
|
||||||
|
authMode === "token" && gatewayToken
|
||||||
|
? `?token=${encodeURIComponent(gatewayToken)}`
|
||||||
|
: "";
|
||||||
|
const opened = await openUrl(`${links.httpUrl}${tokenParam}`);
|
||||||
|
if (!opened) {
|
||||||
|
await prompter.note(
|
||||||
|
formatControlUiSshHint({
|
||||||
|
port,
|
||||||
|
basePath: baseConfig.gateway?.controlUi?.basePath,
|
||||||
|
token: authMode === "token" ? gatewayToken : undefined,
|
||||||
|
}),
|
||||||
|
"Open Control UI",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await prompter.outro("Onboarding complete.");
|
await prompter.outro("Onboarding complete.");
|
||||||
|
|||||||
Reference in New Issue
Block a user