Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(desktop): add device confirmation dialog and token registration IPC

yushenff827f05e47e
diff --git a/apps/desktop/electron/electron-env.d.ts b/apps/desktop/electron/electron-env.d.ts
index 583a19b966..4cb6355084 100644
--- a/apps/desktop/electron/electron-env.d.ts
+++ b/apps/desktop/electron/electron-env.d.ts
@@ -77,6 +77,9 @@ interface ElectronAPI {
getAgent: (id: string) => Promise<unknown>
closeAgent: (id: string) => Promise<unknown>
sendMessage: (agentId: string, content: string) => Promise<unknown>
+ registerToken: (token: string, agentId: string, expiresAt: number) => Promise<unknown>
+ onDeviceConfirmRequest: (callback: (deviceId: string) => void) => void
+ deviceConfirmResponse: (deviceId: string, allowed: boolean) => void
}
tools: {
list: () => Promise<ToolInfo[]>
diff --git a/apps/desktop/electron/ipc/hub.ts b/apps/desktop/electron/ipc/hub.ts
index 6992d7cabd..1aa9671c5b 100644
--- a/apps/desktop/electron/ipc/hub.ts
+++ b/apps/desktop/electron/ipc/hub.ts
@@ -221,6 +221,43 @@ export function registerHubIpcHandlers(): void {
agent.write(content)
return { ok: true }
})
+
+ /**
+ * Register a one-time token for device verification.
+ * Called by the QR code component when a token is generated or refreshed.
+ */
+ ipcMain.handle('hub:registerToken', async (_event, token: string, agentId: string, expiresAt: number) => {
+ const h = getHub()
+ h.registerToken(token, agentId, expiresAt)
+ return { ok: true }
+ })
+
+}
+
+/**
+ * Set up device confirmation flow between Hub (main process) and renderer.
+ * Must be called after both Hub initialization and window creation.
+ */
+export function setupDeviceConfirmation(mainWindow: Electron.BrowserWindow): void {
+ const h = getHub()
+ const pendingConfirms = new Map<string, (allowed: boolean) => void>()
+
+ // Listen for renderer responses to device confirm dialogs
+ ipcMain.on('hub:device-confirm-response', (_event, deviceId: string, allowed: boolean) => {
+ const resolve = pendingConfirms.get(deviceId)
+ if (resolve) {
+ pendingConfirms.delete(deviceId)
+ resolve(allowed)
+ }
+ })
+
+ // Register confirm handler on Hub — sends request to renderer, awaits response
+ h.setConfirmHandler((deviceId: string, _agentId: string) => {
+ return new Promise<boolean>((resolve) => {
+ pendingConfirms.set(deviceId, resolve)
+ mainWindow.webContents.send('hub:device-confirm-request', deviceId)
+ })
+ })
}
/**
diff --git a/apps/desktop/electron/ipc/index.ts b/apps/desktop/electron/ipc/index.ts
index 71bbec888b..13ad6fe4d7 100644
--- a/apps/desktop/electron/ipc/index.ts
+++ b/apps/desktop/electron/ipc/index.ts
@@ -3,11 +3,11 @@
*/
export { registerAgentIpcHandlers, cleanupAgent } from './agent.js'
export { registerSkillsIpcHandlers } from './skills.js'
-export { registerHubIpcHandlers, cleanupHub, initializeHub } from './hub.js'
+export { registerHubIpcHandlers, cleanupHub, initializeHub, setupDeviceConfirmation } from './hub.js'
import { registerAgentIpcHandlers, cleanupAgent } from './agent.js'
import { registerSkillsIpcHandlers } from './skills.js'
-import { registerHubIpcHandlers, cleanupHub, initializeHub } from './hub.js'
+import { registerHubIpcHandlers, cleanupHub, initializeHub, setupDeviceConfirmation } from './hub.js'
/**
* Register all IPC handlers.
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index a360a499b3..193ca84dfb 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -1,7 +1,7 @@
import { app, BrowserWindow } from 'electron'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
-import { registerAllIpcHandlers, initializeApp, cleanupAll } from './ipc/index.js'
+import { registerAllIpcHandlers, initializeApp, cleanupAll, setupDeviceConfirmation } from './ipc/index.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@@ -59,4 +59,9 @@ app.whenReady().then(async () => {
await initializeApp()
createWindow()
+
+ // Set up device confirmation flow (requires both Hub and window)
+ if (win) {
+ setupDeviceConfirmation(win)
+ }
})
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 8c89881991..b439cd56e6 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -55,6 +55,14 @@ const electronAPI = {
closeAgent: (id: string) => ipcRenderer.invoke('hub:closeAgent', id),
sendMessage: (agentId: string, content: string) =>
ipcRenderer.invoke('hub:sendMessage', agentId, content),
+ registerToken: (token: string, agentId: string, expiresAt: number) =>
+ ipcRenderer.invoke('hub:registerToken', token, agentId, expiresAt),
+ onDeviceConfirmRequest: (callback: (deviceId: string) => void) => {
+ ipcRenderer.on('hub:device-confirm-request', (_event, deviceId: string) => callback(deviceId))
+ },
+ deviceConfirmResponse: (deviceId: string, allowed: boolean) => {
+ ipcRenderer.send('hub:device-confirm-response', deviceId, allowed)
+ },
},
// Tools management
diff --git a/apps/desktop/src/components/device-confirm-dialog.tsx b/apps/desktop/src/components/device-confirm-dialog.tsx
new file mode 100644
index 0000000000..30e81f0f8e
--- /dev/null
+++ b/apps/desktop/src/components/device-confirm-dialog.tsx
@@ -0,0 +1,64 @@
+import { useState, useEffect, useCallback } from 'react'
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from '@multica/ui/components/ui/alert-dialog'
+
+interface PendingConfirm {
+ deviceId: string
+}
+
+/**
+ * Device confirmation dialog — shown when a new device tries to connect via QR code.
+ * Listens for 'hub:device-confirm-request' IPC events from the main process,
+ * shows an AlertDialog, and sends the user's response back.
+ */
+export function DeviceConfirmDialog() {
+ const [pending, setPending] = useState<PendingConfirm | null>(null)
+
+ useEffect(() => {
+ window.electronAPI?.hub.onDeviceConfirmRequest((deviceId: string) => {
+ setPending({ deviceId })
+ })
+ }, [])
+
+ const handleAllow = useCallback(() => {
+ if (!pending) return
+ window.electronAPI?.hub.deviceConfirmResponse(pending.deviceId, true)
+ setPending(null)
+ }, [pending])
+
+ const handleReject = useCallback(() => {
+ if (!pending) return
+ window.electronAPI?.hub.deviceConfirmResponse(pending.deviceId, false)
+ setPending(null)
+ }, [pending])
+
+ return (
+ <AlertDialog open={pending !== null}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>New Device Connection</AlertDialogTitle>
+ <AlertDialogDescription>
+ Device <span className="font-mono font-medium">{pending?.deviceId}</span> wants to connect.
+ Allow this device?
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel onClick={handleReject}>
+ Reject
+ </AlertDialogCancel>
+ <AlertDialogAction onClick={handleAllow}>
+ Allow
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ )
+}
diff --git a/apps/desktop/src/components/qr-code.tsx b/apps/desktop/src/components/qr-code.tsx
index 1562dfd1e2..e2d44d471e 100644
--- a/apps/desktop/src/components/qr-code.tsx
+++ b/apps/desktop/src/components/qr-code.tsx
@@ -54,11 +54,17 @@ export function ConnectionQRCode({
size = 180,
onRefresh,
}: ConnectionQRCodeProps) {
- const [token, setToken] = useState(() => generateToken())
+ const [token, setToken] = useState(generateToken)
const [expiresAt, setExpiresAt] = useState(() => Date.now() + expirySeconds * 1000)
const [remainingSeconds, setRemainingSeconds] = useState(expirySeconds)
const [copied, setCopied] = useState(false)
+ // Register initial token with Hub on mount
+ useEffect(() => {
+ window.electronAPI?.hub.registerToken(token, agentId, expiresAt)
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- only on mount
+ }, [])
+
// QR code data payload
const qrData: QRCodeData = useMemo(
() => ({
@@ -93,6 +99,9 @@ export function ConnectionQRCode({
setExpiresAt(newExpires)
setRemainingSeconds(expirySeconds)
+ // Register new token with Hub for verification
+ window.electronAPI?.hub.registerToken(newToken, agentId, newExpires)
+
if (onRefresh) {
onRefresh({
type: 'multica-connect',
diff --git a/apps/desktop/src/pages/layout.tsx b/apps/desktop/src/pages/layout.tsx
index 63a536b20c..8e6d472c1d 100644
--- a/apps/desktop/src/pages/layout.tsx
+++ b/apps/desktop/src/pages/layout.tsx
@@ -10,6 +10,7 @@ import {
Comment01Icon,
} from '@hugeicons/core-free-icons'
import { cn } from '@multica/ui/lib/utils'
+import { DeviceConfirmDialog } from '../components/device-confirm-dialog'
const tabs = [
{ path: '/', label: 'Home', icon: Home01Icon, exact: true },
@@ -62,6 +63,7 @@ export default function Layout() {
<Outlet />
</main>
<Toaster />
+ <DeviceConfirmDialog />
</div>
)
}