Skip to content
Merged
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
4 changes: 4 additions & 0 deletions apps/desktop/src/main/lib/app-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export async function initAppState(): Promise<void> {
console.log(`App state initialized at: ${APP_STATE_PATH}`);
}

export function isAppStateInitialized(): boolean {
return _appState !== null;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

export const appState = new Proxy({} as AppStateDB, {
get(_target, prop) {
if (!_appState) {
Expand Down
10 changes: 9 additions & 1 deletion apps/desktop/src/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { env } from "shared/env.shared";
import type { AgentLifecycleEvent } from "shared/notification-types";
import { createIPCHandler } from "trpc-electron/main";
import { productName } from "~/package.json";
import { appState, pruneWindowScopedState } from "../lib/app-state";
import {
appState,
isAppStateInitialized,
pruneWindowScopedState,
} from "../lib/app-state";
import { browserManager } from "../lib/browser/browser-manager";
import { attachEditContextMenu } from "../lib/edit-context-menu";
import { createApplicationMenu } from "../lib/menu";
Expand Down Expand Up @@ -298,6 +302,10 @@ function snapshotWindowState(window: BrowserWindow): WindowState {

/** Persist every open window's bounds + org so they can be restored on relaunch. */
export function persistOpenWindows(): void {
// Quit before initAppState() completed: windows are only created after init,
// so there is nothing to snapshot — appState access below would throw, and
// writing the empty set would clobber the previous session's restore state.
if (!isAppStateInitialized()) return;
const persisted: PersistedWindow[] = getAllWindows()
.filter((w) => !w.isDestroyed())
.map((w) => ({
Expand Down
Loading