Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .reflection/reflection_metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"missingVerdictCount": 29,
"lastMissingAt": 1774298644774
}
269 changes: 269 additions & 0 deletions .tts-debug.log

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/desktop-electron/electron-builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const getBase = (): Configuration => ({
gatekeeperAssess: false,
entitlements: "resources/entitlements.plist",
entitlementsInherit: "resources/entitlements.plist",
extendInfo: {
NSMicrophoneUsageDescription: "OpenCode needs microphone access for voice input.",
},
notarize: true,
target: ["dmg", "zip"],
},
Expand Down
10 changes: 9 additions & 1 deletion packages/desktop-electron/src/main/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execFile } from "node:child_process"
import { BrowserWindow, Notification, app, clipboard, dialog, ipcMain, shell } from "electron"
import { BrowserWindow, Notification, app, clipboard, dialog, ipcMain, shell, systemPreferences } from "electron"
import type { IpcMainEvent, IpcMainInvokeEvent } from "electron"

import type { InitStep, ServerReadyData, SqliteMigrationProgress, TitlebarTheme, WslConfig } from "../preload/types"
Expand Down Expand Up @@ -138,6 +138,14 @@ export function registerIpcHandlers(deps: Deps) {
return { buffer, width: size.width, height: size.height }
})

ipcMain.handle("request-microphone-access", async () => {
if (process.platform !== "darwin") return true
const status = systemPreferences.getMediaAccessStatus("microphone")
if (status === "granted") return true
if (status === "denied" || status === "restricted") return false
return systemPreferences.askForMediaAccess("microphone")
})

ipcMain.on("show-notification", (_event: IpcMainEvent, title: string, body?: string) => {
new Notification({ title, body }).show()
})
Expand Down
25 changes: 25 additions & 0 deletions packages/desktop-electron/src/main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ function overlay(theme: Partial<TitlebarTheme> = {}) {
}
}

function wirePermissions(win: BrowserWindow) {
const ses = win.webContents.session

ses.setPermissionCheckHandler((_view, permission) => {
return permission === "media" || permission === "notifications"
})

ses.setPermissionRequestHandler((_view, permission, callback, details) => {
if (permission === "notifications") {
callback(true)
return
}

if (permission === "media") {
const list = "mediaTypes" in details && Array.isArray(details.mediaTypes) ? details.mediaTypes : []
callback(list.includes("audio"))
return
}

callback(false)
})
}

export function setTitlebar(win: BrowserWindow, theme: Partial<TitlebarTheme> = {}) {
if (process.platform !== "win32") return
win.setTitleBarOverlay(overlay(theme))
Expand Down Expand Up @@ -88,6 +111,7 @@ export function createMainWindow(globals: Globals) {
},
})

wirePermissions(win)
state.manage(win)
loadWindow(win, "index.html")
wireZoom(win)
Expand Down Expand Up @@ -120,6 +144,7 @@ export function createLoadingWindow(globals: Globals) {
},
})

wirePermissions(win)
loadWindow(win, "loading.html")
injectGlobals(win, globals)

Expand Down
1 change: 1 addition & 0 deletions packages/desktop-electron/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const api: ElectronAPI = {
openLink: (url) => ipcRenderer.send("open-link", url),
openPath: (path, app) => ipcRenderer.invoke("open-path", path, app),
readClipboardImage: () => ipcRenderer.invoke("read-clipboard-image"),
requestMicrophoneAccess: () => ipcRenderer.invoke("request-microphone-access"),
showNotification: (title, body) => ipcRenderer.send("show-notification", title, body),
getWindowFocused: () => ipcRenderer.invoke("get-window-focused"),
setWindowFocus: () => ipcRenderer.invoke("set-window-focus"),
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-electron/src/preload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type ElectronAPI = {
openLink: (url: string) => void
openPath: (path: string, app?: string) => Promise<void>
readClipboardImage: () => Promise<{ buffer: ArrayBuffer; width: number; height: number } | null>
requestMicrophoneAccess: () => Promise<boolean>
showNotification: (title: string, body?: string) => void
getWindowFocused: () => Promise<boolean>
setWindowFocus: () => Promise<void>
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop-electron/src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ const createPlatform = (): Platform => {
type: "image/png",
})
},

requestMicrophoneAccess: async () => {
return window.api.requestMicrophoneAccess().catch(() => false)
},
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/desktop/src-tauri/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSMicrophoneUsageDescription</key>
<string>OpenCode needs microphone access for voice input.</string>
</dict>
</plist>
Loading