feat(cli): open projects in the running desktop app (#8824)
This commit is contained in:
1 parent
beae2147a9
commit
04efa7907e
26 files changed
+1890
-3
No files matched your search
@@ -0,0 +1,307 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off -- The integration fixture binds the same platform socket or named pipe as the CLI.
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodeNet from "node:net";
|
||||
import * as NodeOS from "node:os";
|
||||
import * as NodePath from "node:path";
|
||||
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it } from "@effect/vitest";
|
||||
import type { DesktopAppActivationRequest } from "@t3tools/contracts";
|
||||
import { resolveDesktopAppControlAddress } from "@t3tools/shared/desktopAppControl";
|
||||
import {
|
||||
HostProcessPlatform,
|
||||
HostProcessUserId,
|
||||
HostProcessWorkingDirectory,
|
||||
} from "@t3tools/shared/hostProcess";
|
||||
import * as NetService from "@t3tools/shared/Net";
|
||||
import * as ConfigProvider from "effect/ConfigProvider";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { Command } from "effect/unstable/cli";
|
||||
import { afterEach, describe, expect, vi } from "vite-plus/test";
|
||||
|
||||
import { makeCli } from "../bin.ts";
|
||||
|
||||
vi.mock("node:os", async (importOriginal) => {
|
||||
const os = await importOriginal<typeof import("node:os")>();
|
||||
return { ...os, homedir: vi.fn(os.homedir) };
|
||||
});
|
||||
|
||||
afterEach(() => vi.mocked(NodeOS.homedir).mockReset());
|
||||
|
||||
const runCli = (args: ReadonlyArray<string>, env: Record<string, string> = {}) =>
|
||||
Command.runWith(makeCli(), { version: "0.0.0" })(args).pipe(
|
||||
Effect.provide(
|
||||
Layer.mergeAll(
|
||||
NodeServices.layer,
|
||||
NetService.layer,
|
||||
ConfigProvider.layer(ConfigProvider.fromEnv({ env })),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const pathExists = (path: string) =>
|
||||
Effect.promise(() =>
|
||||
NodeFSP.stat(path).then(
|
||||
() => true,
|
||||
() => false,
|
||||
),
|
||||
);
|
||||
|
||||
async function startFakeDesktop(input: {
|
||||
readonly baseDir: string;
|
||||
readonly stateSubdirectory?: "userdata" | "dev";
|
||||
readonly platform: NodeJS.Platform;
|
||||
readonly userId: number | undefined;
|
||||
readonly reply?: (request: DesktopAppActivationRequest) => unknown;
|
||||
}) {
|
||||
const target = resolveDesktopAppControlAddress({
|
||||
stateDir: NodePath.join(input.baseDir, input.stateSubdirectory ?? "userdata"),
|
||||
platform: input.platform,
|
||||
tempDir: NodeOS.tmpdir(),
|
||||
userId: input.userId,
|
||||
joinPath: NodePath.join,
|
||||
});
|
||||
if (target.directory !== null) {
|
||||
await NodeFSP.mkdir(target.directory, { recursive: true, mode: 0o700 });
|
||||
await NodeFSP.unlink(target.address).catch((error: NodeJS.ErrnoException) => {
|
||||
if (error.code !== "ENOENT") throw error;
|
||||
});
|
||||
}
|
||||
|
||||
const received: DesktopAppActivationRequest[] = [];
|
||||
const server = NodeNet.createServer((socket) => {
|
||||
socket.setEncoding("utf8");
|
||||
let buffer = "";
|
||||
socket.on("data", (chunk) => {
|
||||
buffer += chunk;
|
||||
const newline = buffer.indexOf("\n");
|
||||
if (newline === -1) return;
|
||||
const request = JSON.parse(buffer.slice(0, newline)) as DesktopAppActivationRequest;
|
||||
received.push(request);
|
||||
const response = input.reply
|
||||
? input.reply(request)
|
||||
: {
|
||||
version: 1,
|
||||
requestId: request.requestId,
|
||||
ok: true,
|
||||
projectId: "project-1",
|
||||
threadId: `thread-${received.length}`,
|
||||
};
|
||||
socket.end(`${JSON.stringify(response)}\n`);
|
||||
});
|
||||
});
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.once("error", reject);
|
||||
server.listen(target.address, resolve);
|
||||
});
|
||||
|
||||
return {
|
||||
received,
|
||||
close: async () => {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
if (target.directory !== null) {
|
||||
await NodeFSP.unlink(target.address).catch((error: NodeJS.ErrnoException) => {
|
||||
if (error.code !== "ENOENT") throw error;
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const fakeDesktop = Effect.fn(function* (
|
||||
input: Omit<Parameters<typeof startFakeDesktop>[0], "platform" | "userId">,
|
||||
) {
|
||||
const platform = yield* HostProcessPlatform;
|
||||
const userId = yield* HostProcessUserId;
|
||||
return yield* Effect.acquireRelease(
|
||||
Effect.promise(() => startFakeDesktop({ ...input, platform, userId })),
|
||||
(server) => Effect.promise(() => server.close()),
|
||||
);
|
||||
});
|
||||
|
||||
const withTempDirectory = <A, E, R>(
|
||||
prefix: string,
|
||||
use: (root: string) => Effect.Effect<A, E, R>,
|
||||
) =>
|
||||
Effect.acquireUseRelease(
|
||||
Effect.promise(() => NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), prefix))),
|
||||
use,
|
||||
(root) => Effect.promise(() => NodeFSP.rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
|
||||
describe("t3 app", () => {
|
||||
it.effect("rejects SSH before it tries to reach a desktop app", () =>
|
||||
withTempDirectory("t3-app-ssh-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
const baseDir = NodePath.join(root, "missing-t3-home");
|
||||
const error = yield* runCli(["app", "--base-dir", baseDir], {
|
||||
SSH_CONNECTION: "client server",
|
||||
}).pipe(Effect.flip);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "DesktopAppSshUnsupportedError",
|
||||
message:
|
||||
"`t3 app` only controls a desktop app on the same machine. It cannot run over SSH.",
|
||||
});
|
||||
expect(yield* pathExists(baseDir)).toBe(false);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("rejects unsupported platforms without creating state", () =>
|
||||
withTempDirectory("t3-app-platform-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
const baseDir = NodePath.join(root, "missing-t3-home");
|
||||
const error = yield* runCli(["app", "--base-dir", baseDir]).pipe(
|
||||
Effect.provideService(HostProcessPlatform, "freebsd"),
|
||||
Effect.flip,
|
||||
);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "DesktopAppPlatformUnsupportedError",
|
||||
platform: "freebsd",
|
||||
message: "`t3 app` is not supported on freebsd.",
|
||||
});
|
||||
expect(yield* pathExists(baseDir)).toBe(false);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("does not create state when only a server or no desktop app is running", () =>
|
||||
withTempDirectory("t3-app-missing-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
const baseDir = NodePath.join(root, "missing-t3-home");
|
||||
const error = yield* runCli(["app", "--base-dir", baseDir]).pipe(Effect.flip);
|
||||
|
||||
expect(error).toMatchObject({
|
||||
_tag: "DesktopAppUnreachableError",
|
||||
candidateAddresses: [expect.any(String)],
|
||||
workspaceRoot: yield* HostProcessWorkingDirectory,
|
||||
message: expect.stringContaining("Could not reach the T3 Code desktop app."),
|
||||
cause: { code: "ENOENT" },
|
||||
});
|
||||
expect(yield* pathExists(baseDir)).toBe(false);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("uses T3CODE_HOME or --base-dir and sends the default or explicit path", () =>
|
||||
withTempDirectory("t3-app-command-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
const baseDir = NodePath.join(root, "t3-home");
|
||||
const explicitPath = NodePath.join(root, "project");
|
||||
const platform = yield* HostProcessPlatform;
|
||||
const workingDirectory = yield* HostProcessWorkingDirectory;
|
||||
const desktop = yield* fakeDesktop({ baseDir });
|
||||
|
||||
yield* runCli(["app"], { T3CODE_HOME: baseDir });
|
||||
yield* runCli(["app", explicitPath, "--base-dir", baseDir]);
|
||||
|
||||
expect(desktop.received.map((request) => request.workspaceRoot)).toEqual([
|
||||
workingDirectory,
|
||||
explicitPath,
|
||||
]);
|
||||
expect(desktop.received.every((request) => request.platform === platform)).toBe(true);
|
||||
}).pipe(Effect.scoped),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("prefers the installed desktop app when a dev desktop is also running", () =>
|
||||
withTempDirectory("t3-app-preferred-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
vi.mocked(NodeOS.homedir).mockReturnValue(root);
|
||||
const baseDir = NodePath.join(root, ".t3");
|
||||
const desktop = yield* fakeDesktop({ baseDir });
|
||||
const development = yield* fakeDesktop({ baseDir, stateSubdirectory: "dev" });
|
||||
|
||||
yield* runCli(["app"]);
|
||||
|
||||
expect(desktop.received).toHaveLength(1);
|
||||
expect(development.received).toHaveLength(0);
|
||||
}).pipe(Effect.scoped),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("finds the dev desktop when the default desktop socket is absent", () =>
|
||||
withTempDirectory("t3-app-dev-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
vi.mocked(NodeOS.homedir).mockReturnValue(root);
|
||||
const baseDir = NodePath.join(root, ".t3");
|
||||
const development = yield* fakeDesktop({ baseDir, stateSubdirectory: "dev" });
|
||||
|
||||
yield* runCli(["app"]);
|
||||
yield* runCli(["app"], { T3CODE_HOME: " " });
|
||||
|
||||
expect(development.received).toHaveLength(2);
|
||||
expect(yield* pathExists(baseDir)).toBe(false);
|
||||
}).pipe(Effect.scoped),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("never searches a dev state directory for an explicit T3 home", () =>
|
||||
withTempDirectory("t3-app-explicit-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
vi.mocked(NodeOS.homedir).mockReturnValue(root);
|
||||
const baseDir = NodePath.join(root, ".t3");
|
||||
const development = yield* fakeDesktop({ baseDir, stateSubdirectory: "dev" });
|
||||
|
||||
const flagError = yield* runCli(["app", "--base-dir", baseDir]).pipe(Effect.flip);
|
||||
const envError = yield* runCli(["app"], { T3CODE_HOME: baseDir }).pipe(Effect.flip);
|
||||
|
||||
expect(flagError).toMatchObject({ _tag: "DesktopAppUnreachableError" });
|
||||
expect(envError).toMatchObject({ _tag: "DesktopAppUnreachableError" });
|
||||
expect(development.received).toHaveLength(0);
|
||||
}).pipe(Effect.scoped),
|
||||
),
|
||||
);
|
||||
|
||||
for (const responseKind of ["failure", "invalid"] as const) {
|
||||
it.effect(`never falls back after the default desktop sends a ${responseKind} response`, () =>
|
||||
withTempDirectory("t3-app-response-test-", (root) =>
|
||||
Effect.gen(function* () {
|
||||
vi.mocked(NodeOS.homedir).mockReturnValue(root);
|
||||
const baseDir = NodePath.join(root, ".t3");
|
||||
const desktop = yield* fakeDesktop({
|
||||
baseDir,
|
||||
reply: (request) =>
|
||||
responseKind === "failure"
|
||||
? {
|
||||
version: 1,
|
||||
requestId: request.requestId,
|
||||
ok: false,
|
||||
code: "project-create-failed",
|
||||
message: "The project path is not available.",
|
||||
}
|
||||
: { invalid: true },
|
||||
});
|
||||
const development = yield* fakeDesktop({ baseDir, stateSubdirectory: "dev" });
|
||||
|
||||
const error = yield* runCli(["app"]).pipe(Effect.flip);
|
||||
|
||||
expect(desktop.received).toHaveLength(1);
|
||||
expect(development.received).toHaveLength(0);
|
||||
if (responseKind === "failure") {
|
||||
expect(error).toMatchObject({
|
||||
_tag: "DesktopAppRequestFailedError",
|
||||
code: "project-create-failed",
|
||||
requestId: desktop.received[0]?.requestId,
|
||||
workspaceRoot: yield* HostProcessWorkingDirectory,
|
||||
message: expect.stringContaining("project-create-failed"),
|
||||
cause: {
|
||||
ok: false,
|
||||
code: "project-create-failed",
|
||||
message: "The project path is not available.",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
expect(error).toMatchObject({
|
||||
_tag: "DesktopAppUnreachableError",
|
||||
cause: { message: "The desktop app response is invalid." },
|
||||
});
|
||||
}
|
||||
}).pipe(Effect.scoped),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,261 @@
|
||||
// @effect-diagnostics globalTimers:off -- The Node socket client owns its response deadline and clears it on every completion path.
|
||||
import * as NodeCrypto from "node:crypto";
|
||||
import * as NodeNet from "node:net";
|
||||
import * as NodeOS from "node:os";
|
||||
|
||||
import {
|
||||
DESKTOP_APP_ACTIVATION_PROTOCOL_VERSION,
|
||||
DesktopAppActivationErrorCode,
|
||||
DesktopAppActivationResponse,
|
||||
type DesktopAppActivationPlatform,
|
||||
type DesktopAppActivationRequest,
|
||||
} from "@t3tools/contracts";
|
||||
import { resolveDesktopAppControlAddress } from "@t3tools/shared/desktopAppControl";
|
||||
import {
|
||||
HostProcessPlatform,
|
||||
HostProcessUserId,
|
||||
HostProcessWorkingDirectory,
|
||||
} from "@t3tools/shared/hostProcess";
|
||||
import * as Config from "effect/Config";
|
||||
import * as Console from "effect/Console";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { Argument, Command } from "effect/unstable/cli";
|
||||
|
||||
import { expandHomePath, resolveBaseDir } from "../os-jank.ts";
|
||||
import { baseDirFlag } from "./config.ts";
|
||||
|
||||
const CLI_RESPONSE_TIMEOUT_MS = 17_000;
|
||||
const MAX_RESPONSE_BYTES = 64 * 1024;
|
||||
const isDesktopAppActivationResponse = Schema.is(DesktopAppActivationResponse);
|
||||
|
||||
export class DesktopAppSshUnsupportedError extends Schema.TaggedErrorClass<DesktopAppSshUnsupportedError>()(
|
||||
"DesktopAppSshUnsupportedError",
|
||||
{},
|
||||
) {
|
||||
override get message(): string {
|
||||
return "`t3 app` only controls a desktop app on the same machine. It cannot run over SSH.";
|
||||
}
|
||||
}
|
||||
|
||||
export class DesktopAppPlatformUnsupportedError extends Schema.TaggedErrorClass<DesktopAppPlatformUnsupportedError>()(
|
||||
"DesktopAppPlatformUnsupportedError",
|
||||
{ platform: Schema.String },
|
||||
) {
|
||||
override get message(): string {
|
||||
return `\`t3 app\` is not supported on ${this.platform}.`;
|
||||
}
|
||||
}
|
||||
|
||||
export class DesktopAppUnreachableError extends Schema.TaggedErrorClass<DesktopAppUnreachableError>()(
|
||||
"DesktopAppUnreachableError",
|
||||
{
|
||||
candidateAddresses: Schema.Array(Schema.String),
|
||||
requestId: Schema.String,
|
||||
workspaceRoot: Schema.String,
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return "Could not reach the T3 Code desktop app. Start or update the desktop app on this machine, then run `t3 app` again. A running T3 Code server is not enough.";
|
||||
}
|
||||
}
|
||||
|
||||
export class DesktopAppRequestFailedError extends Schema.TaggedErrorClass<DesktopAppRequestFailedError>()(
|
||||
"DesktopAppRequestFailedError",
|
||||
{
|
||||
code: DesktopAppActivationErrorCode,
|
||||
requestId: Schema.String,
|
||||
workspaceRoot: Schema.String,
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `T3 Code could not open ${this.workspaceRoot} (${this.code}).`;
|
||||
}
|
||||
}
|
||||
|
||||
function isDesktopPlatform(platform: NodeJS.Platform): platform is DesktopAppActivationPlatform {
|
||||
return platform === "darwin" || platform === "linux" || platform === "win32";
|
||||
}
|
||||
|
||||
export function sendDesktopAppActivationRequest(input: {
|
||||
readonly address: string;
|
||||
readonly fallbackAddress?: string;
|
||||
readonly request: DesktopAppActivationRequest;
|
||||
readonly timeoutMs?: number;
|
||||
}): Promise<DesktopAppActivationResponse> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = NodeNet.createConnection(input.address);
|
||||
socket.setEncoding("utf8");
|
||||
let buffer = "";
|
||||
let settled = false;
|
||||
let connected = false;
|
||||
|
||||
const finish = (
|
||||
result:
|
||||
| { readonly type: "success"; readonly response: DesktopAppActivationResponse }
|
||||
| { readonly type: "failure"; readonly error: Error },
|
||||
) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timeout);
|
||||
socket.destroy();
|
||||
if (result.type === "success") resolve(result.response);
|
||||
else reject(result.error);
|
||||
};
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
finish({
|
||||
type: "failure",
|
||||
error: new Error("The desktop app did not respond in time."),
|
||||
});
|
||||
}, input.timeoutMs ?? CLI_RESPONSE_TIMEOUT_MS);
|
||||
|
||||
socket.once("connect", () => {
|
||||
connected = true;
|
||||
socket.write(`${JSON.stringify(input.request)}\n`);
|
||||
});
|
||||
socket.on("data", (chunk) => {
|
||||
buffer += chunk;
|
||||
if (Buffer.byteLength(buffer, "utf8") > MAX_RESPONSE_BYTES) {
|
||||
finish({ type: "failure", error: new Error("The desktop app response is too large.") });
|
||||
return;
|
||||
}
|
||||
const newline = buffer.indexOf("\n");
|
||||
if (newline === -1) return;
|
||||
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(buffer.slice(0, newline));
|
||||
} catch {
|
||||
finish({
|
||||
type: "failure",
|
||||
error: new Error("The desktop app response is not valid JSON."),
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!isDesktopAppActivationResponse(parsed)) {
|
||||
finish({ type: "failure", error: new Error("The desktop app response is invalid.") });
|
||||
return;
|
||||
}
|
||||
if (parsed.requestId !== input.request.requestId) {
|
||||
finish({
|
||||
type: "failure",
|
||||
error: new Error("The desktop app response did not match this request."),
|
||||
});
|
||||
return;
|
||||
}
|
||||
finish({ type: "success", response: parsed });
|
||||
});
|
||||
socket.once("error", (error: NodeJS.ErrnoException) => {
|
||||
if (
|
||||
!settled &&
|
||||
!connected &&
|
||||
input.fallbackAddress !== undefined &&
|
||||
(error.code === "ENOENT" || error.code === "ECONNREFUSED")
|
||||
) {
|
||||
settled = true;
|
||||
clearTimeout(timeout);
|
||||
socket.destroy();
|
||||
resolve(
|
||||
sendDesktopAppActivationRequest({
|
||||
address: input.fallbackAddress,
|
||||
request: input.request,
|
||||
...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
finish({ type: "failure", error });
|
||||
});
|
||||
socket.once("end", () => {
|
||||
finish({ type: "failure", error: new Error("The desktop app closed the connection.") });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const appEnvironment = Config.all({
|
||||
t3Home: Config.string("T3CODE_HOME").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
||||
sshConnection: Config.string("SSH_CONNECTION").pipe(Config.option),
|
||||
sshTty: Config.string("SSH_TTY").pipe(Config.option),
|
||||
});
|
||||
|
||||
const runAppCommand = Effect.fn("cli.app")(function* (flags: {
|
||||
readonly baseDir: Option.Option<string>;
|
||||
readonly workspaceRoot: Option.Option<string>;
|
||||
}) {
|
||||
const environment = yield* appEnvironment;
|
||||
const hostPlatform = yield* HostProcessPlatform;
|
||||
if (Option.isSome(environment.sshConnection) || Option.isSome(environment.sshTty)) {
|
||||
return yield* new DesktopAppSshUnsupportedError({});
|
||||
}
|
||||
if (!isDesktopPlatform(hostPlatform)) {
|
||||
return yield* new DesktopAppPlatformUnsupportedError({ platform: hostPlatform });
|
||||
}
|
||||
|
||||
const path = yield* Path.Path;
|
||||
const configuredBaseDir = Option.getOrUndefined(flags.baseDir) ?? environment.t3Home;
|
||||
const baseDir = yield* resolveBaseDir(configuredBaseDir);
|
||||
const allowDevFallback = Option.isNone(flags.baseDir) && !environment.t3Home?.trim();
|
||||
const rawWorkspaceRoot =
|
||||
Option.getOrUndefined(flags.workspaceRoot) ?? (yield* HostProcessWorkingDirectory);
|
||||
const workspaceRoot = path.resolve(yield* expandHomePath(rawWorkspaceRoot));
|
||||
const userId = yield* HostProcessUserId;
|
||||
const resolveAddress = (stateSubdirectory: "userdata" | "dev") =>
|
||||
resolveDesktopAppControlAddress({
|
||||
stateDir: path.join(baseDir, stateSubdirectory),
|
||||
platform: hostPlatform,
|
||||
tempDir: NodeOS.tmpdir(),
|
||||
userId,
|
||||
joinPath: path.join,
|
||||
}).address;
|
||||
const request: DesktopAppActivationRequest = {
|
||||
version: DESKTOP_APP_ACTIVATION_PROTOCOL_VERSION,
|
||||
requestId: NodeCrypto.randomUUID(),
|
||||
type: "open-workspace",
|
||||
workspaceRoot,
|
||||
platform: hostPlatform,
|
||||
};
|
||||
const address = resolveAddress("userdata");
|
||||
const fallbackAddress = allowDevFallback ? resolveAddress("dev") : undefined;
|
||||
|
||||
const response = yield* Effect.tryPromise({
|
||||
try: () =>
|
||||
sendDesktopAppActivationRequest({
|
||||
address,
|
||||
...(fallbackAddress === undefined ? {} : { fallbackAddress }),
|
||||
request,
|
||||
}),
|
||||
catch: (cause) =>
|
||||
new DesktopAppUnreachableError({
|
||||
candidateAddresses: fallbackAddress === undefined ? [address] : [address, fallbackAddress],
|
||||
requestId: request.requestId,
|
||||
workspaceRoot,
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
return yield* new DesktopAppRequestFailedError({
|
||||
code: response.code,
|
||||
requestId: response.requestId,
|
||||
workspaceRoot,
|
||||
cause: response,
|
||||
});
|
||||
}
|
||||
|
||||
yield* Console.log(`Opened ${workspaceRoot} in T3 Code.`);
|
||||
});
|
||||
|
||||
export const appCommand = Command.make("app", {
|
||||
baseDir: baseDirFlag,
|
||||
workspaceRoot: Argument.string("path").pipe(
|
||||
Argument.withDescription("Project directory. Default: current directory."),
|
||||
Argument.optional,
|
||||
),
|
||||
}).pipe(
|
||||
Command.withDescription("Open a project in the running T3 Code desktop app."),
|
||||
Command.withHandler(runAppCommand),
|
||||
);
|
||||
Reference in new issue
Block a user