MCPcopy Index your code
hub / github.com/anomalyco/opencode / createMainWindow

Function createMainWindow

packages/desktop/src/main/windows.ts:148–212  ·  view source on GitHub ↗
(id: string = randomUUID())

Source from the content-addressed store, hash-verified

146}
147
148export function createMainWindow(id: string = randomUUID()) {
149 const state = windowState({
150 file: windowStateFile(id),
151 defaultWidth: 1280,
152 defaultHeight: 800,
153 })
154
155 const mode = tone()
156 const win = new BrowserWindow({
157 x: state.x,
158 y: state.y,
159 width: state.width,
160 height: state.height,
161 show: false,
162 autoHideMenuBar: true,
163 title: "OpenCode",
164 icon: iconPath(),
165 backgroundColor: backgroundColor ?? defaultBackgroundColor(),
166 ...(process.platform === "darwin"
167 ? {
168 titleBarStyle: "hidden" as const,
169 trafficLightPosition: { x: 12, y: 14 },
170 }
171 : {}),
172 ...(process.platform === "win32"
173 ? {
174 frame: false,
175 titleBarStyle: "hidden" as const,
176 titleBarOverlay: overlay({ mode }),
177 }
178 : {}),
179 webPreferences: {
180 preload: join(root, "../preload/index.js"),
181 contextIsolation: true,
182 nodeIntegration: false,
183 sandbox: true,
184 },
185 })
186
187 allowRendererPermissions(win)
188 wireWindowRecovery(win, id)
189
190 win.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
191 const { requestHeaders } = details
192 upsertKeyValue(requestHeaders, "Access-Control-Allow-Origin", ["*"])
193 callback({ requestHeaders })
194 })
195
196 win.webContents.session.webRequest.onHeadersReceived((details, callback) => {
197 const { responseHeaders = {} } = details
198 addRendererHeaders(details.url, responseHeaders)
199 callback({ responseHeaders })
200 })
201
202 state.manage(win)
203 registerWindow(win, id)
204 loadWindow(win, "index.html")
205 wireZoom(win)

Callers 2

runDesktopMenuActionFunction · 0.90
restoreMainWindowsFunction · 0.85

Calls 14

windowStateFileFunction · 0.85
iconPathFunction · 0.85
defaultBackgroundColorFunction · 0.85
joinFunction · 0.85
allowRendererPermissionsFunction · 0.85
wireWindowRecoveryFunction · 0.85
upsertKeyValueFunction · 0.85
addRendererHeadersFunction · 0.85
registerWindowFunction · 0.85
loadWindowFunction · 0.85
wireZoomFunction · 0.85
toneFunction · 0.70

Tested by

no test coverage detected