Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript

fix: copy pairing commands through native desktop clipboard

bingqilinweimaotai3e53d2f262c1
diff --git a/electron/main.cjs b/electron/main.cjs
index 93f303f..12ac777 100644
--- a/electron/main.cjs
+++ b/electron/main.cjs
@@ -1,5 +1,5 @@
/* eslint-env node */
-const { app, BrowserWindow, Tray, Menu, nativeImage, shell, nativeTheme, screen, ipcMain, globalShortcut, protocol, net } = require('electron')
+const { app, BrowserWindow, Tray, Menu, nativeImage, shell, nativeTheme, screen, ipcMain, globalShortcut, protocol, net, clipboard } = require('electron')
const path = require('node:path')
const fs = require('node:fs')
const http = require('node:http')
@@ -1417,6 +1417,19 @@ ipcMain.handle('app:is-focused', () => {
return !!(mainWindow && !mainWindow.isDestroyed() && mainWindow.isFocused())
})
+// Pairing commands must copy even immediately after a native confirmation
+// dialog, when Chromium can still consider the renderer document unfocused.
+ipcMain.handle('clipboard:write-text', (event, value) => {
+ if (!mainWindow || mainWindow.isDestroyed() || event.sender !== mainWindow.webContents) {
+ throw new Error('clipboard write is only available to the main window')
+ }
+ if (typeof value !== 'string' || value.length > 8192) {
+ throw new Error('invalid clipboard text')
+ }
+ clipboard.writeText(value)
+ if (clipboard.readText() !== value) throw new Error('clipboard write failed')
+})
+
ipcMain.on('theme:set', (_event, source) => {
if (source !== 'system' && source !== 'light' && source !== 'dark') return
nativeTheme.themeSource = source
diff --git a/electron/preload.cjs b/electron/preload.cjs
index 67e5d7c..d0af5b0 100644
--- a/electron/preload.cjs
+++ b/electron/preload.cjs
@@ -24,6 +24,11 @@ contextBridge.exposeInMainWorld('cumora', {
},
},
+ /** OS clipboard write, independent of Chromium document focus. */
+ clipboard: {
+ writeText: (value) => ipcRenderer.invoke('clipboard:write-text', value),
+ },
+
/** Native Dock affordances. macOS-only in main; no-op elsewhere. */
dock: {
setUnreadDot: (visible) => ipcRenderer.send('dock:set-unread-dot', !!visible),
diff --git a/src/desktop/MeView.tsx b/src/desktop/MeView.tsx
index ab1f339..7ebc0c6 100644
--- a/src/desktop/MeView.tsx
+++ b/src/desktop/MeView.tsx
@@ -6,6 +6,7 @@ import { useSoundStore } from '@/stores/sound'
import { useDevtools } from '@/stores/devtools'
import { useAuth } from '@/stores/auth'
import { usePairingCodes } from '@/stores/pairing-codes'
+import { copyText } from '@/lib/clipboard'
import { Avatar } from '@/components/Avatar'
import { Checkbox } from '@/components/Checkbox'
import { AppearancePicker, ChatLayoutPicker } from '@/components/AppearancePicker'
@@ -919,8 +920,7 @@ function ComputersTab() {
setErr(null)
setCopied(false)
try {
- if (!navigator.clipboard?.writeText) throw new Error('clipboard unavailable')
- await navigator.clipboard.writeText(pairCommand)
+ await copyText(pairCommand)
setCopied(true)
} catch {
setErr(t('me.copyFailed'))
@@ -931,8 +931,7 @@ function ComputersTab() {
setErr(null)
setRepairCopied(false)
try {
- if (!navigator.clipboard?.writeText) throw new Error('clipboard unavailable')
- await navigator.clipboard.writeText(command)
+ await copyText(command)
setRepairCopied(true)
} catch {
setErr(t('me.copyFailed'))
diff --git a/src/desktop/Onboarding.tsx b/src/desktop/Onboarding.tsx
index df513e1..75cb0b9 100644
--- a/src/desktop/Onboarding.tsx
+++ b/src/desktop/Onboarding.tsx
@@ -6,6 +6,7 @@ import { useT } from '@/lib/i18n'
import { RUNNABLE_ENGINES, engineLabel, type RunnableEngineId } from '@/lib/engines'
import { useAuth } from '@/stores/auth'
import { usePairingCodes } from '@/stores/pairing-codes'
+import { copyText } from '@/lib/clipboard'
/**
* First-run gate for free-tier users: their agents run on their own machine
@@ -80,8 +81,7 @@ export function Onboarding() {
setErr(null)
setCopied(false)
try {
- if (!navigator.clipboard?.writeText) throw new Error('clipboard unavailable')
- await navigator.clipboard.writeText(cmd)
+ await copyText(cmd)
setCopied(true)
} catch {
setErr(t('onboard.copyFailed'))
diff --git a/src/lib/clipboard.ts b/src/lib/clipboard.ts
new file mode 100644
index 0000000..b4851df
--- /dev/null
+++ b/src/lib/clipboard.ts
@@ -0,0 +1,10 @@
+/** Copy text through Electron when available. Chromium requires a focused
+ * document for navigator.clipboard, which can lag after a native dialog. */
+export async function copyText(text: string): Promise<void> {
+ if (window.cumora?.clipboard?.writeText) {
+ await window.cumora.clipboard.writeText(text)
+ return
+ }
+ if (!navigator.clipboard?.writeText) throw new Error('clipboard unavailable')
+ await navigator.clipboard.writeText(text)
+}
diff --git a/src/lib/runtime.ts b/src/lib/runtime.ts
index 10634e9..728c040 100644
--- a/src/lib/runtime.ts
+++ b/src/lib/runtime.ts
@@ -37,6 +37,10 @@ interface CumoraBridge {
isFocused: () => Promise<boolean>
onFocusChange: (handler: (focused: boolean) => void) => () => void
}
+ /** Native clipboard write for desktop commands; works while the renderer is unfocused. */
+ clipboard?: {
+ writeText: (value: string) => Promise<void>
+ }
/** Native Dock affordances. Currently only meaningful on macOS. */
dock?: {
setUnreadDot: (visible: boolean) => void