Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1ad5fac52 |
No files matched your search
@@ -1,11 +1,6 @@
|
||||
export const MAX_PORT_NUMBER = 65_535;
|
||||
import { MAX_PORT_NUMBER, normalizeRunningPorts } from "@t3tools/shared/port";
|
||||
|
||||
export function normalizeRunningPorts(ports: number[]): number[] {
|
||||
if (ports.length === 0) return [];
|
||||
return [...new Set(ports)]
|
||||
.filter((port) => Number.isInteger(port) && port > 0 && port <= MAX_PORT_NUMBER)
|
||||
.toSorted((left, right) => left - right);
|
||||
}
|
||||
export { MAX_PORT_NUMBER, normalizeRunningPorts };
|
||||
|
||||
export function parsePidList(stdout: string): number[] {
|
||||
const pids: number[] = [];
|
||||
|
||||
@@ -613,12 +613,17 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
|
||||
return cached.isWeb;
|
||||
}
|
||||
|
||||
const isWeb = yield* webPortInspector(port).pipe(Effect.catch(() => Effect.succeed(false)));
|
||||
webPortProbeCache.set(port, {
|
||||
isWeb,
|
||||
checkedAt: Date.now(),
|
||||
});
|
||||
return isWeb;
|
||||
const isWeb = yield* webPortInspector(port).pipe(
|
||||
Effect.map((result) => ({ result, probeSucceeded: true }) as const),
|
||||
Effect.catch(() => Effect.succeed({ result: false, probeSucceeded: false } as const)),
|
||||
);
|
||||
if (isWeb.probeSucceeded) {
|
||||
webPortProbeCache.set(port, {
|
||||
isWeb: isWeb.result,
|
||||
checkedAt: Date.now(),
|
||||
});
|
||||
}
|
||||
return isWeb.result;
|
||||
});
|
||||
|
||||
const detectWebPorts = (runningPorts: number[]) =>
|
||||
|
||||
@@ -61,11 +61,8 @@ import { APP_STAGE_LABEL, APP_VERSION } from "../branding";
|
||||
import { isTerminalFocused } from "../lib/terminalFocus";
|
||||
import { isLinuxPlatform, isMacPlatform, newCommandId, newProjectId } from "../lib/utils";
|
||||
import { useStore } from "../store";
|
||||
import {
|
||||
normalizeRunningPorts,
|
||||
selectThreadTerminalState,
|
||||
useTerminalStateStore,
|
||||
} from "../terminalStateStore";
|
||||
import { normalizeRunningPorts, portStatusLabel } from "@t3tools/shared/port";
|
||||
import { selectThreadTerminalState, useTerminalStateStore } from "../terminalStateStore";
|
||||
import { useUiStateStore } from "../uiStateStore";
|
||||
import {
|
||||
resolveShortcutCommand,
|
||||
@@ -219,15 +216,10 @@ function terminalStatusFromTerminalState(
|
||||
const runningPorts = normalizeRunningPorts(
|
||||
runningTerminalIds.flatMap((terminalId) => runningTerminalPorts[terminalId] ?? []),
|
||||
);
|
||||
const primaryWebPort = runningPorts[0] ?? null;
|
||||
const { label, primaryWebPort } = portStatusLabel(runningPorts);
|
||||
|
||||
return {
|
||||
label:
|
||||
primaryWebPort === null
|
||||
? "Terminal process running"
|
||||
: runningPorts.length === 1
|
||||
? `Open web server: http://localhost:${primaryWebPort}`
|
||||
: `Open web server: http://localhost:${primaryWebPort} (detected web ports: ${runningPorts.join(", ")})`,
|
||||
label,
|
||||
colorClass:
|
||||
primaryWebPort === null
|
||||
? "text-teal-600 dark:text-teal-300/90"
|
||||
|
||||
@@ -33,11 +33,8 @@ import {
|
||||
type ThreadTerminalGroup,
|
||||
} from "../types";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
import {
|
||||
normalizeRunningPorts,
|
||||
selectTerminalEventEntries,
|
||||
useTerminalStateStore,
|
||||
} from "../terminalStateStore";
|
||||
import { normalizeRunningPorts, portStatusLabel, type PortStatusLabel } from "@t3tools/shared/port";
|
||||
import { selectTerminalEventEntries, useTerminalStateStore } from "../terminalStateStore";
|
||||
|
||||
const MIN_DRAWER_HEIGHT = 180;
|
||||
const MAX_DRAWER_HEIGHT_RATIO = 0.75;
|
||||
@@ -79,33 +76,17 @@ export function selectPendingTerminalEventEntries(
|
||||
return entries.filter((entry) => entry.id > lastAppliedTerminalEventId);
|
||||
}
|
||||
|
||||
interface TerminalRuntimeStatus {
|
||||
label: string;
|
||||
primaryWebPort: number | null;
|
||||
}
|
||||
|
||||
function terminalRuntimeStatus(
|
||||
terminalId: string,
|
||||
runningTerminalIds: Set<string>,
|
||||
runningTerminalPorts: Record<string, number[]>,
|
||||
): TerminalRuntimeStatus | null {
|
||||
): PortStatusLabel | null {
|
||||
if (!runningTerminalIds.has(terminalId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const runningPorts = normalizeRunningPorts(runningTerminalPorts[terminalId]);
|
||||
const primaryWebPort = runningPorts[0] ?? null;
|
||||
const label =
|
||||
runningPorts.length === 0
|
||||
? "Terminal process running"
|
||||
: runningPorts.length === 1
|
||||
? `Open web server: http://localhost:${primaryWebPort}`
|
||||
: `Open web server: http://localhost:${primaryWebPort} (detected web ports: ${runningPorts.join(", ")})`;
|
||||
|
||||
return {
|
||||
label,
|
||||
primaryWebPort,
|
||||
};
|
||||
return portStatusLabel(runningPorts);
|
||||
}
|
||||
|
||||
function terminalThemeFromApp(): ITheme {
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
|
||||
import { ThreadId, type TerminalEvent } from "@t3tools/contracts";
|
||||
import { normalizeRunningPorts } from "@t3tools/shared/port";
|
||||
export { normalizeRunningPorts } from "@t3tools/shared/port";
|
||||
import { create } from "zustand";
|
||||
import { createJSONStorage, persist } from "zustand/middleware";
|
||||
import { resolveStorage } from "./lib/storage";
|
||||
@@ -62,13 +64,6 @@ function normalizeRunningTerminalIds(
|
||||
.filter((id) => id.length > 0 && validTerminalIdSet.has(id));
|
||||
}
|
||||
|
||||
export function normalizeRunningPorts(ports: readonly number[] | undefined): number[] {
|
||||
if (!ports || ports.length === 0) return [];
|
||||
return [...new Set(ports)]
|
||||
.filter((port) => Number.isInteger(port) && port > 0 && port <= 65_535)
|
||||
.toSorted((left, right) => left - right);
|
||||
}
|
||||
|
||||
function normalizeRunningTerminalPorts(
|
||||
runningTerminalPorts: Record<string, number[]> | undefined,
|
||||
terminalIds: string[],
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
"./projectScripts": {
|
||||
"types": "./src/projectScripts.ts",
|
||||
"import": "./src/projectScripts.ts"
|
||||
},
|
||||
"./port": {
|
||||
"types": "./src/port.ts",
|
||||
"import": "./src/port.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export const MAX_PORT_NUMBER = 65_535;
|
||||
|
||||
export function normalizeRunningPorts(ports: readonly number[] | undefined): number[] {
|
||||
if (!ports || ports.length === 0) return [];
|
||||
return [...new Set(ports)]
|
||||
.filter((port) => Number.isInteger(port) && port > 0 && port <= MAX_PORT_NUMBER)
|
||||
.toSorted((left, right) => left - right);
|
||||
}
|
||||
|
||||
export interface PortStatusLabel {
|
||||
label: string;
|
||||
primaryWebPort: number | null;
|
||||
}
|
||||
|
||||
export function portStatusLabel(runningPorts: readonly number[]): PortStatusLabel {
|
||||
const primaryWebPort = runningPorts[0] ?? null;
|
||||
const label =
|
||||
runningPorts.length === 0
|
||||
? "Terminal process running"
|
||||
: runningPorts.length === 1
|
||||
? `Open web server: http://localhost:${primaryWebPort}`
|
||||
: `Open web server: http://localhost:${primaryWebPort} (detected web ports: ${runningPorts.join(", ")})`;
|
||||
return { label, primaryWebPort };
|
||||
}
|
||||
Reference in new issue
Block a user