- Implement dedicated Logs tab showing stdout/stderr from OpenCode server - Add log level parsing (INFO, ERROR, WARN, DEBUG) with color coding - Stream logs from main process to renderer via IPC events - Persist scroll position and auto-scroll state per instance - Synchronize instance IDs between renderer and main process - Consolidate syntax highlighting to single shared highlighter instance - Optimize markdown rendering with global highlighter initialization - Fix code block copy button to always appear on right side - Enable debug logging with --print-logs --log-level DEBUG flags
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { contextBridge, ipcRenderer } from "electron"
|
|
|
|
export interface ElectronAPI {
|
|
selectFolder: () => Promise<string | null>
|
|
createInstance: (id: string, folder: string) => Promise<{ id: string; port: number; pid: number }>
|
|
stopInstance: (pid: number) => Promise<void>
|
|
onInstanceStarted: (callback: (data: { id: string; port: number; pid: number }) => void) => void
|
|
onInstanceError: (callback: (data: { id: string; error: string }) => void) => void
|
|
onInstanceStopped: (callback: (data: { id: string }) => void) => void
|
|
onInstanceLog: (
|
|
callback: (data: {
|
|
id: string
|
|
entry: { timestamp: number; level: "info" | "error" | "warn" | "debug"; message: string }
|
|
}) => void,
|
|
) => void
|
|
onNewInstance: (callback: () => void) => void
|
|
}
|
|
|
|
const electronAPI: ElectronAPI = {
|
|
selectFolder: () => ipcRenderer.invoke("dialog:selectFolder"),
|
|
createInstance: (id: string, folder: string) => ipcRenderer.invoke("instance:create", id, folder),
|
|
stopInstance: (pid: number) => ipcRenderer.invoke("instance:stop", pid),
|
|
onInstanceStarted: (callback) => {
|
|
ipcRenderer.on("instance:started", (_, data) => callback(data))
|
|
},
|
|
onInstanceError: (callback) => {
|
|
ipcRenderer.on("instance:error", (_, data) => callback(data))
|
|
},
|
|
onInstanceStopped: (callback) => {
|
|
ipcRenderer.on("instance:stopped", (_, data) => callback(data))
|
|
},
|
|
onInstanceLog: (callback) => {
|
|
ipcRenderer.on("instance:log", (_, data) => callback(data))
|
|
},
|
|
onNewInstance: (callback) => {
|
|
ipcRenderer.on("menu:newInstance", () => callback())
|
|
},
|
|
}
|
|
|
|
contextBridge.exposeInMainWorld("electronAPI", electronAPI)
|
|
|
|
declare global {
|
|
interface Window {
|
|
electronAPI: ElectronAPI
|
|
}
|
|
}
|