MCPcopy Create free account
hub / github.com/contextgo/contextgo / createWindow

Function createWindow

src/index.ts:207–639  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205};
206
207const createWindow = (): void => {
208 console.log('[ContextGo] Creating main window...');
209 // Get primary display size
210 const primaryDisplay = screen.getPrimaryDisplay();
211 const { width: screenWidth, height: screenHeight } = primaryDisplay.workAreaSize;
212
213 // Use a slightly taller, less wide default window and clamp it so large displays
214 // do not open an excessively wide first-run layout.
215 const windowWidth = clampWindowDimension(
216 Math.floor(screenWidth * DEFAULT_WINDOW_WIDTH_RATIO),
217 DEFAULT_WINDOW_MIN_WIDTH,
218 DEFAULT_WINDOW_MAX_WIDTH,
219 screenWidth
220 );
221 const windowHeight = clampWindowDimension(
222 Math.floor(screenHeight * DEFAULT_WINDOW_HEIGHT_RATIO),
223 DEFAULT_WINDOW_MIN_HEIGHT,
224 DEFAULT_WINDOW_MAX_HEIGHT,
225 screenHeight
226 );
227
228 // Get app icon for development mode (Windows/Linux need icon in BrowserWindow)
229 // In production, icons are set via forge.config.ts packagerConfig
230 let devIcon: Electron.NativeImage | undefined;
231 if (!app.isPackaged) {
232 try {
233 // Windows: app.ico (no dev version), Linux: app_dev.png (with padding)
234 const iconFile = process.platform === 'win32' ? 'app.ico' : 'app_dev.png';
235 const iconPath = path.join(process.cwd(), 'resources', iconFile);
236 if (fs.existsSync(iconPath)) {
237 devIcon = nativeImage.createFromPath(iconPath);
238 if (devIcon.isEmpty()) devIcon = undefined;
239 }
240 } catch {
241 // Ignore icon loading errors in development
242 }
243 }
244
245 // Create the browser window.
246 mainWindow = new BrowserWindow({
247 width: windowWidth,
248 height: windowHeight,
249 show: false, // Hide until CSS is loaded to prevent FOUC
250 backgroundColor: '#ffffff',
251 autoHideMenuBar: true,
252 // Set icon for Windows/Linux in development mode
253 ...(devIcon && process.platform !== 'darwin' ? { icon: devIcon } : {}),
254 // Custom titlebar configuration / 自定义标题栏配置
255 ...(process.platform === 'darwin'
256 ? {
257 titleBarStyle: 'hidden',
258 trafficLightPosition: { x: 10, y: 10 },
259 }
260 : { frame: false }),
261 webPreferences: {
262 preload: path.join(__dirname, '../preload/index.js'),
263 webviewTag: true, // 启用 webview 标签用于 HTML 预览 / Enable webview tag for HTML preview
264 },

Callers 3

index.tsFile · 0.85
handleAppReadyFunction · 0.85
showOrCreateMainWindowFunction · 0.85

Calls 15

getCloseToTrayEnabledFunction · 0.90
getIsQuittingFunction · 0.90
bindMainWindowReferencesFunction · 0.90
setupApplicationMenuFunction · 0.90
applyZoomToWindowFunction · 0.90
clampWindowDimensionFunction · 0.85
logMainWindowLifecycleFunction · 0.85

Tested by

no test coverage detected