Skip to content

Commit 5aefd57

Browse files
authored
🤖 Make window size responsive to screen dimensions (#339)
Calculates window size as 80% of primary display dimensions instead of using fixed 1600×1000 size. Uses Electron's `screen.getPrimaryDisplay().workArea` to detect available screen space (excluding taskbars/menubars), then sizes the window to 80% of that space with a minimum floor of 1200×800 for smaller displays. **Examples:** - 1920×1080 display → 1536×864 window - 2560×1440 display → 2048×1152 window - 3840×2160 display (4K) → 3072×1728 window _Generated with `cmux`_
1 parent 1dc11e6 commit 5aefd57

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import "source-map-support/register";
33
import "disposablestack/auto";
44

55
import type { MenuItemConstructorOptions } from "electron";
6-
import { app, BrowserWindow, ipcMain as electronIpcMain, Menu, shell, dialog } from "electron";
6+
import {
7+
app,
8+
BrowserWindow,
9+
ipcMain as electronIpcMain,
10+
Menu,
11+
shell,
12+
dialog,
13+
screen,
14+
} from "electron";
715
import * as fs from "fs";
816
import * as path from "path";
917
import type { Config } from "./config";
@@ -314,9 +322,16 @@ function createWindow() {
314322
throw new Error("Services must be loaded before creating window");
315323
}
316324

325+
// Calculate window size based on screen dimensions (80% of available space)
326+
const primaryDisplay = screen.getPrimaryDisplay();
327+
const { width: screenWidth, height: screenHeight } = primaryDisplay.workArea;
328+
329+
const windowWidth = Math.max(1200, Math.floor(screenWidth * 0.8));
330+
const windowHeight = Math.max(800, Math.floor(screenHeight * 0.8));
331+
317332
mainWindow = new BrowserWindow({
318-
width: 1200,
319-
height: 800,
333+
width: windowWidth,
334+
height: windowHeight,
320335
webPreferences: {
321336
nodeIntegration: false,
322337
contextIsolation: true,

0 commit comments

Comments
 (0)