Skip to content

Commit e576fda

Browse files
committed
feat(web): suggest ssh hosts in a dropdown under the host field
1 parent d1f2c4f commit e576fda

7 files changed

Lines changed: 233 additions & 193 deletions

File tree

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
fetchSshEnvironmentDescriptor,
2222
fetchSshSessionState,
2323
issueSshWebSocketTicket,
24+
resolveSshHost,
2425
resolveSshPasswordPrompt,
2526
} from "./methods/sshEnvironment.ts";
2627
import {
@@ -68,6 +69,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
6869
yield* ipc.handle(clearConnectionCatalog);
6970

7071
yield* ipc.handle(discoverSshHosts);
72+
yield* ipc.handle(resolveSshHost);
7173
yield* ipc.handle(ensureSshEnvironment);
7274
yield* ipc.handle(disconnectSshEnvironment);
7375
yield* ipc.handle(fetchSshEnvironmentDescriptor);

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const GET_CONNECTION_CATALOG_CHANNEL = "desktop:get-connection-catalog";
2929
export const SET_CONNECTION_CATALOG_CHANNEL = "desktop:set-connection-catalog";
3030
export const CLEAR_CONNECTION_CATALOG_CHANNEL = "desktop:clear-connection-catalog";
3131
export const DISCOVER_SSH_HOSTS_CHANNEL = "desktop:discover-ssh-hosts";
32+
export const RESOLVE_SSH_HOST_CHANNEL = "desktop:resolve-ssh-host";
3233
export const ENSURE_SSH_ENVIRONMENT_CHANNEL = "desktop:ensure-ssh-environment";
3334
export const DISCONNECT_SSH_ENVIRONMENT_CHANNEL = "desktop:disconnect-ssh-environment";
3435
export const FETCH_SSH_ENVIRONMENT_DESCRIPTOR_CHANNEL = "desktop:fetch-ssh-environment-descriptor";

‎apps/desktop/src/ipc/methods/sshEnvironment.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ export const discoverSshHosts = DesktopIpc.makeIpcMethod({
117117
}),
118118
});
119119

120+
export const resolveSshHost = DesktopIpc.makeIpcMethod({
121+
channel: IpcChannels.RESOLVE_SSH_HOST_CHANNEL,
122+
payload: Schema.String,
123+
result: DesktopSshEnvironmentTargetSchema,
124+
handler: Effect.fn("desktop.ipc.sshEnvironment.resolveHost")(function* (alias) {
125+
const sshEnvironment = yield* DesktopSshEnvironment.DesktopSshEnvironment;
126+
return yield* sshEnvironment.resolveHost(alias);
127+
}),
128+
});
129+
120130
export const ensureSshEnvironment = DesktopIpc.makeIpcMethod({
121131
channel: IpcChannels.ENSURE_SSH_ENVIRONMENT_CHANNEL,
122132
payload: DesktopSshEnvironmentEnsureInputSchema,

‎apps/desktop/src/preload.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {
6060
ipcRenderer.invoke(IpcChannels.SET_CONNECTION_CATALOG_CHANNEL, catalog),
6161
clearConnectionCatalog: () => ipcRenderer.invoke(IpcChannels.CLEAR_CONNECTION_CATALOG_CHANNEL),
6262
discoverSshHosts: () => ipcRenderer.invoke(IpcChannels.DISCOVER_SSH_HOSTS_CHANNEL),
63+
resolveSshHost: (alias) => ipcRenderer.invoke(IpcChannels.RESOLVE_SSH_HOST_CHANNEL, alias),
6364
ensureSshEnvironment: async (target, options) =>
6465
unwrapEnsureSshEnvironmentResult(
6566
await ipcRenderer.invoke(IpcChannels.ENSURE_SSH_ENVIRONMENT_CHANNEL, {

‎apps/desktop/src/ssh/DesktopSshEnvironment.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from "@t3tools/contracts";
66
import * as NetService from "@t3tools/shared/Net";
77
import * as SshAuth from "@t3tools/ssh/auth";
8+
import { resolveSshTarget } from "@t3tools/ssh/command";
89
import { discoverSshHosts } from "@t3tools/ssh/config";
910
import {
1011
SshCommandError,
@@ -54,6 +55,9 @@ export class DesktopSshEnvironment extends Context.Service<
5455
readonly discoverHosts: (input?: {
5556
readonly homeDir?: string;
5657
}) => Effect.Effect<readonly DesktopDiscoveredSshHost[], DesktopSshEnvironmentDiscoverError>;
58+
readonly resolveHost: (
59+
alias: string,
60+
) => Effect.Effect<DesktopSshEnvironmentTarget, SshCommandError | SshInvalidTargetError>;
5761
readonly ensureEnvironment: (
5862
target: DesktopSshEnvironmentTarget,
5963
options?: { readonly issuePairingToken?: boolean },
@@ -136,6 +140,11 @@ export const make = Effect.gen(function* () {
136140
Effect.provide(runtimeContext),
137141
Effect.withSpan("desktop.ssh.discoverHosts"),
138142
),
143+
resolveHost: (alias) =>
144+
resolveSshTarget(alias.trim()).pipe(
145+
Effect.provide(runtimeContext),
146+
Effect.withSpan("desktop.ssh.resolveHost"),
147+
),
139148
ensureEnvironment: (target, ensureOptions) =>
140149
manager
141150
.ensureEnvironment(target, ensureOptions)

0 commit comments

Comments
 (0)