Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
reduceDesktopUpdateStateOnUpdateAvailable,
} from "./updateMachine";
import { isArm64HostRunningIntelBuild, resolveDesktopRuntimeInfo } from "./runtimeArch";
import { attachWindowStatePersistence, loadWindowState } from "./windowState";

syncShellEnvironment();

Expand Down Expand Up @@ -75,6 +76,12 @@ const AUTO_UPDATE_STARTUP_DELAY_MS = 15_000;
const AUTO_UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000;
const DESKTOP_UPDATE_CHANNEL = "latest";
const DESKTOP_UPDATE_ALLOW_PRERELEASE = false;
const DEFAULT_WINDOW_BOUNDS = {
width: 1100,
height: 780,
} as const;
const MIN_WINDOW_WIDTH = 840;
const MIN_WINDOW_HEIGHT = 620;

type DesktopUpdateErrorContext = DesktopUpdateState["errorContext"];

Expand Down Expand Up @@ -1221,11 +1228,24 @@ function getIconOption(): { icon: string } | Record<string, never> {
}

function createWindow(): BrowserWindow {
const initialWindowState = loadWindowState({
userDataPath: app.getPath("userData"),
defaultBounds: {
x: 0,
y: 0,
width: DEFAULT_WINDOW_BOUNDS.width,
height: DEFAULT_WINDOW_BOUNDS.height,
},
minWidth: MIN_WINDOW_WIDTH,
minHeight: MIN_WINDOW_HEIGHT,
});
const window = new BrowserWindow({
width: 1100,
height: 780,
minWidth: 840,
minHeight: 620,
x: initialWindowState.bounds.x,
y: initialWindowState.bounds.y,
width: initialWindowState.bounds.width,
height: initialWindowState.bounds.height,
minWidth: MIN_WINDOW_WIDTH,
minHeight: MIN_WINDOW_HEIGHT,
show: false,
autoHideMenuBar: true,
...getIconOption(),
Expand All @@ -1239,6 +1259,10 @@ function createWindow(): BrowserWindow {
sandbox: true,
},
});
attachWindowStatePersistence({
window,
userDataPath: app.getPath("userData"),
});

window.webContents.on("context-menu", (event, params) => {
event.preventDefault();
Expand Down Expand Up @@ -1285,6 +1309,13 @@ function createWindow(): BrowserWindow {
emitUpdateState();
});
window.once("ready-to-show", () => {
if (initialWindowState.restoreMode === "fullscreen-origin") {
window.show();
return;
}
if (initialWindowState.restoreMode === "maximized") {
window.maximize();
}
window.show();
});

Expand Down
Loading