(id: string = randomUUID())
| 146 | } |
| 147 | |
| 148 | export 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) |
no test coverage detected