Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Fix desktop startup completion for visible windows (#7603)

Nick Gomez236b417ac2f8
diff --git a/.changeset/deep-link-show-gate.md b/.changeset/deep-link-show-gate.md
new file mode 100644
index 000000000..d0565bf9f
--- /dev/null
+++ b/.changeset/deep-link-show-gate.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge-desktop": patch
+---
+
+When the desktop app starts on a project that is opened a second time while its window is still loading, startup timing is now recorded, and on macOS, running the app again from a command line after every window is closed shows the Navigator.
diff --git a/packages/desktop/src/main/show-gate.ts b/packages/desktop/src/main/show-gate.ts
index 0439e6325..f19bdca9b 100644
--- a/packages/desktop/src/main/show-gate.ts
+++ b/packages/desktop/src/main/show-gate.ts
@@ -55,22 +55,26 @@ export function createShowGateRegistry(deps: ShowGateRegistryDeps): ShowGateRegi
window.show?.();
}
+ function markShown(state: PerWindowGateState): void {
+ state.shown = true;
+ try {
+ deps.onShown?.(state.kind);
+ } catch (cbErr) {
+ deps.log?.warn(
+ {
+ event: 'show-gate-on-shown-failed',
+ windowKind: state.kind,
+ err: cbErr,
+ },
+ 'show-gate onShown callback threw',
+ );
+ }
+ }
+
function safeShow(window: BrowserWindowLike, state: PerWindowGateState): void {
try {
revealWindow(window, state.kind);
- state.shown = true;
- try {
- deps.onShown?.(state.kind);
- } catch (cbErr) {
- deps.log?.warn(
- {
- event: 'show-gate-on-shown-failed',
- windowKind: state.kind,
- err: cbErr,
- },
- 'show-gate onShown callback threw',
- );
- }
+ markShown(state);
} catch (err) {
deps.log?.warn(
{
@@ -86,8 +90,14 @@ export function createShowGateRegistry(deps: ShowGateRegistryDeps): ShowGateRegi
function maybeShow(window: BrowserWindowLike, state: PerWindowGateState): void {
if (state.shown) return;
if (!(state.readyToShow && state.themeApplied)) return;
- if (window.isDestroyed?.() === true || window.isVisible?.() === true) {
+ if (window.isDestroyed?.() === true) {
+ clearTimer(state);
+ states.delete(window);
+ return;
+ }
+ if (window.isVisible?.() === true) {
clearTimer(state);
+ markShown(state);
states.delete(window);
return;
}
@@ -102,7 +112,12 @@ export function createShowGateRegistry(deps: ShowGateRegistryDeps): ShowGateRegi
states.delete(window);
return;
}
- if (window.isDestroyed?.() === true || window.isVisible?.() === true) {
+ if (window.isDestroyed?.() === true) {
+ states.delete(window);
+ return;
+ }
+ if (window.isVisible?.() === true) {
+ markShown(state);
states.delete(window);
return;
}
diff --git a/packages/desktop/tests/main/show-gate.test.ts b/packages/desktop/tests/main/show-gate.test.ts
index 5ba0b07e2..1b5f58e9e 100644
--- a/packages/desktop/tests/main/show-gate.test.ts
+++ b/packages/desktop/tests/main/show-gate.test.ts
@@ -63,6 +63,7 @@ interface TestEnv {
timers: CapturedTimer[];
cleared: unknown[];
warns: Array<{ obj: object; msg: string }>;
+ onShown: ReturnType<typeof vi.fn>;
registry: ShowGateRegistry;
}
@@ -70,6 +71,7 @@ function buildEnv(opts?: { timeoutMs?: number; shouldRevealInactive?: () => bool
const timers: CapturedTimer[] = [];
const cleared: unknown[] = [];
const warns: Array<{ obj: object; msg: string }> = [];
+ const onShown = vi.fn();
const registry = createShowGateRegistry({
log: {
warn: (obj, msg) => {
@@ -85,9 +87,10 @@ function buildEnv(opts?: { timeoutMs?: number; shouldRevealInactive?: () => bool
cleared.push(handle);
},
timeoutMs: opts?.timeoutMs,
+ onShown,
shouldRevealInactive: opts?.shouldRevealInactive,
});
- return { timers, cleared, warns, registry };
+ return { timers, cleared, warns, onShown, registry };
}
describe('createShowGateRegistry — dual-signal show contract', () => {
@@ -279,12 +282,14 @@ describe('createShowGateRegistry — timeout fallback', () => {
expect(env.warns).toHaveLength(0);
});
- test('window destroyed before signals + timeout → no show, no warn', () => {
+ test('window destroyed before signals + timeout → no show, no warn, no onShown', () => {
const win = makeWindow();
env.registry.register(win);
win.markDestroyed();
+ expect(env.timers).toHaveLength(1);
env.timers[0]?.cb();
expect(win.show).not.toHaveBeenCalled();
+ expect(env.onShown).not.toHaveBeenCalled();
expect(env.warns).toHaveLength(0);
});
@@ -297,6 +302,16 @@ describe('createShowGateRegistry — timeout fallback', () => {
expect(env.warns).toHaveLength(0);
});
+ test('window already visible before timeout still fires onShown once', () => {
+ const win = makeWindow();
+ env.registry.register(win, { kind: 'editor' });
+ win.markVisible();
+ env.timers[0]?.cb();
+ expect(win.show).not.toHaveBeenCalled();
+ expect(env.onShown).toHaveBeenCalledTimes(1);
+ expect(env.onShown).toHaveBeenCalledWith('editor');
+ });
+
test('windowKind defaults to editor when omitted', () => {
const win = makeWindow();
env.registry.register(win);
@@ -397,6 +412,7 @@ describe('createShowGateRegistry — destroyed-window race on the happy path', (
win.markDestroyed();
env.registry.fireThemeApplied(win);
expect(win.show).not.toHaveBeenCalled();
+ expect(env.onShown).not.toHaveBeenCalled();
});
test('window already-visible between both signals and maybeShow → does not double-show', () => {
@@ -407,6 +423,17 @@ describe('createShowGateRegistry — destroyed-window race on the happy path', (
env.registry.fireThemeApplied(win);
expect(win.show).not.toHaveBeenCalled();
});
+
+ test('window already visible before both signals still fires onShown once', () => {
+ const win = makeWindow();
+ env.registry.register(win, { kind: 'editor' });
+ win.markVisible();
+ win.fireReadyToShow();
+ env.registry.fireThemeApplied(win);
+ expect(win.show).not.toHaveBeenCalled();
+ expect(env.onShown).toHaveBeenCalledTimes(1);
+ expect(env.onShown).toHaveBeenCalledWith('editor');
+ });
});
describe('createShowGateRegistry — show() throws past the destroyed-window guard', () => {