Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/main/ipc/runtime-environments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ describe('registerRuntimeEnvironmentHandlers', () => {
expect(handleMock.mock.calls.map((call) => call[0])).toEqual([
'runtimeEnvironments:list',
'runtimeEnvironments:addFromPairingCode',
'runtimeEnvironments:rename',
'runtimeEnvironments:updateFromPairingCode',
'runtimeEnvironments:resolve',
'runtimeEnvironments:remove',
'runtimeEnvironments:disconnect',
Expand All @@ -140,6 +142,8 @@ describe('registerRuntimeEnvironmentHandlers', () => {
expect(removeHandlerMock.mock.calls.map((call) => call[0])).toEqual([
'runtimeEnvironments:list',
'runtimeEnvironments:addFromPairingCode',
'runtimeEnvironments:rename',
'runtimeEnvironments:updateFromPairingCode',
'runtimeEnvironments:resolve',
'runtimeEnvironments:remove',
'runtimeEnvironments:disconnect',
Expand Down Expand Up @@ -217,6 +221,45 @@ describe('registerRuntimeEnvironmentHandlers', () => {
expect(await list(null, undefined)).toMatchObject([{ id: added.environment.id, name: 'desk' }])
})

it('renames a saved server and re-pairs its connection without changing id', async () => {
registerRuntimeEnvironmentHandlers(store as never)

const add = handler<
{ name: string; pairingCode: string },
{ environment: { id: string; name: string; endpoints: { endpoint: string }[] } }
>('runtimeEnvironments:addFromPairingCode')
const added = await add(null, {
name: 'desk',
pairingCode: pairingCode('ws://192.168.1.10:6768')
})

const rename = handler<
{ selector: string; name: string },
{ environment: { id: string; name: string } }
>('runtimeEnvironments:rename')
expect(await rename(null, { selector: added.environment.id, name: 'lab' })).toMatchObject({
environment: { id: added.environment.id, name: 'lab' }
})

const update = handler<
{ selector: string; pairingCode: string },
{ environment: { id: string; name: string; endpoints: { endpoint: string }[] } }
>('runtimeEnvironments:updateFromPairingCode')
const updated = await update(null, {
selector: added.environment.id,
pairingCode: pairingCode('ws://100.64.0.5:6768')
})
expect(updated).toMatchObject({
environment: {
id: added.environment.id,
name: 'lab',
endpoints: [{ endpoint: 'ws://100.64.0.5:6768' }]
}
})
expect(JSON.stringify(updated)).not.toContain('device-token')
expect(closeRemoteRuntimeRequestConnectionMock).toHaveBeenCalledWith(added.environment.id)
})

it('marks environments owned by ephemeral VM runtimes in the public list', async () => {
registerRuntimeEnvironmentHandlers(store as never)

Expand Down
38 changes: 37 additions & 1 deletion src/main/ipc/runtime-environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
addEnvironmentFromPairingCode,
listEnvironments,
removeEnvironment,
resolveEnvironment
renameEnvironment,
resolveEnvironment,
updateEnvironmentFromPairingCode
} from '../../shared/runtime-environment-store'
import {
redactRuntimeEnvironment,
Expand All @@ -27,6 +29,8 @@ import {
const RUNTIME_ENVIRONMENT_HANDLER_CHANNELS = [
'runtimeEnvironments:list',
'runtimeEnvironments:addFromPairingCode',
'runtimeEnvironments:rename',
'runtimeEnvironments:updateFromPairingCode',
'runtimeEnvironments:resolve',
'runtimeEnvironments:remove',
'runtimeEnvironments:disconnect',
Expand Down Expand Up @@ -86,6 +90,38 @@ export function registerRuntimeEnvironmentHandlers(store: Store): void {
environment: redactRuntimeEnvironment(addEnvironmentFromPairingCode(getUserDataPath(), args))
})
)
ipcMain.handle(
'runtimeEnvironments:rename',
(
_event,
args: { selector: string; name: string }
): { environment: PublicKnownRuntimeEnvironment } => ({
environment: redactRuntimeEnvironment(
renameEnvironment(getUserDataPath(), args.selector, { name: args.name })
)
})
)
ipcMain.handle(
'runtimeEnvironments:updateFromPairingCode',
(
_event,
args: { selector: string; pairingCode: string }
): { environment: PublicKnownRuntimeEnvironment } => {
const environment = updateEnvironmentFromPairingCode(getUserDataPath(), args.selector, {
pairingCode: args.pairingCode
})
// Why: re-pair replaces the endpoint/token; drop live sockets so the next
// connect/status probe uses the newly saved offer instead of a stale path.
closeRemoteRuntimeRequestConnection(environment.id)
clearSharedControlSupport(environment.id)
if (args.selector !== environment.id) {
closeRemoteRuntimeRequestConnection(args.selector)
clearSharedControlSupport(args.selector)
}
closeSubscriptionsForEnvironment(environment.id)
return { environment: redactRuntimeEnvironment(environment) }
}
)
ipcMain.handle(
'runtimeEnvironments:resolve',
(_event, args: { selector: string }): PublicKnownRuntimeEnvironment =>
Expand Down
8 changes: 8 additions & 0 deletions src/preload/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,14 @@ export type PreloadApi = {
name: string
pairingCode: string
}) => Promise<{ environment: PublicKnownRuntimeEnvironment }>
rename: (args: {
selector: string
name: string
}) => Promise<{ environment: PublicKnownRuntimeEnvironment }>
updateFromPairingCode: (args: {
selector: string
pairingCode: string
}) => Promise<{ environment: PublicKnownRuntimeEnvironment }>
resolve: (args: { selector: string }) => Promise<PublicKnownRuntimeEnvironment>
remove: (args: { selector: string }) => Promise<{ removed: PublicKnownRuntimeEnvironment }>
disconnect: (args: {
Expand Down
10 changes: 10 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,16 @@ const api = {
pairingCode: string
}): Promise<{ environment: PublicKnownRuntimeEnvironment }> =>
ipcRenderer.invoke('runtimeEnvironments:addFromPairingCode', args),
rename: (args: {
selector: string
name: string
}): Promise<{ environment: PublicKnownRuntimeEnvironment }> =>
ipcRenderer.invoke('runtimeEnvironments:rename', args),
updateFromPairingCode: (args: {
selector: string
pairingCode: string
}): Promise<{ environment: PublicKnownRuntimeEnvironment }> =>
ipcRenderer.invoke('runtimeEnvironments:updateFromPairingCode', args),
resolve: (args: { selector: string }): Promise<PublicKnownRuntimeEnvironment> =>
ipcRenderer.invoke('runtimeEnvironments:resolve', args),
remove: (args: { selector: string }): Promise<{ removed: PublicKnownRuntimeEnvironment }> =>
Expand Down
Loading
Loading