Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

PRD-10097 Preserve hidden editor state across relaunch (#7884)

Nick Gomez1032ac6b1a82
diff --git a/.changeset/hidden-editor-relaunch.md b/.changeset/hidden-editor-relaunch.md
new file mode 100644
index 000000000..e818c59fc
--- /dev/null
+++ b/.changeset/hidden-editor-relaunch.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge-desktop": patch
+---
+
+Hidden editor choices now survive quitting and relaunching a project window.
diff --git a/packages/app/src/components/EditorPane.dom.test.tsx b/packages/app/src/components/EditorPane.dom.test.tsx
index b05c24f38..72f67f2af 100644
--- a/packages/app/src/components/EditorPane.dom.test.tsx
+++ b/packages/app/src/components/EditorPane.dom.test.tsx
@@ -640,6 +640,7 @@ function makeOkDesktopStub(
) {
const menuHandlers: Array<(action: string) => void> = [];
const viewMenuPushes: Array<{
+ editorVisible?: boolean;
terminalVisible?: boolean;
agentPanelVisible?: boolean;
canViewInSource?: boolean;
@@ -662,6 +663,7 @@ function makeOkDesktopStub(
},
editor: {
notifyViewMenuStateChanged(state: {
+ editorVisible?: boolean;
terminalVisible?: boolean;
agentPanelVisible?: boolean;
canViewInSource?: boolean;
@@ -2632,6 +2634,34 @@ describe('EditorPane saves and restores whether the editor is shown', () => {
expect(editorVisibleAttr()).toBe('true');
});
+ test('desktop: an explicit hide during restore publishes before settlement', async () => {
+ let release: (value: DockStateResult) => void = () => {};
+ const desk = makeOkDesktopStub(() => {
+ const { promise, resolve } = Promise.withResolvers<DockStateResult>();
+ release = resolve;
+ return promise;
+ });
+ (window as { okDesktop?: unknown }).okDesktop = desk.stub;
+ await renderEditorPane();
+
+ act(() => desk.dispatchMenuAction('toggle-editor'));
+ expect(editorVisibleAttr()).toBe('false');
+ expect(desk.viewMenuPushes).toContainEqual({
+ editorVisible: false,
+ wideIntent: { editorVisible: false },
+ });
+
+ await act(async () => {
+ release({ terminalVisible: false, agentPanelVisible: false, editorVisible: true });
+ });
+ expect(editorVisibleAttr()).toBe('false');
+ const editorPushes = desk.viewMenuPushes.filter((push) => 'editorVisible' in push);
+ expect(editorPushes.at(-1)).toEqual({
+ editorVisible: false,
+ wideIntent: { editorVisible: false },
+ });
+ });
+
test('desktop: a deep link that opens a document before the editor pane mounts keeps a saved-hidden editor shown', async () => {
const desk = makeOkDesktopStub(async () => ({
terminalVisible: false,
diff --git a/packages/app/src/components/EditorPane.tsx b/packages/app/src/components/EditorPane.tsx
index d2ffb9634..bb23e57cf 100644
--- a/packages/app/src/components/EditorPane.tsx
+++ b/packages/app/src/components/EditorPane.tsx
@@ -1134,8 +1134,8 @@ export function EditorPane() {
useEffect(() => {
if (window.okDesktop == null || !editorToggleable) return;
noteRestoreVisibilityLevel(editorRestoreGateRef, editorShown);
- if (!dockRestoreSettled) return;
- if (!consumeRestoreVisibilityGate(editorRestoreGateRef)) return;
+ if (!dockRestoreSettled && !editorChosenSinceMountRef.current) return;
+ if (dockRestoreSettled && !consumeRestoreVisibilityGate(editorRestoreGateRef)) return;
window.okDesktop.editor.notifyViewMenuStateChanged({
editorVisible: effectiveEditorVisible,
wideIntent: { editorVisible: editorShown },
diff --git a/packages/desktop/src/main/bootstrap.ts b/packages/desktop/src/main/bootstrap.ts
index 1de3dbb53..776ee1b8b 100644
--- a/packages/desktop/src/main/bootstrap.ts
+++ b/packages/desktop/src/main/bootstrap.ts
@@ -14,6 +14,7 @@ interface BootstrapDeps {
) => SchemaCompatibilityResult;
installLocalhostCorsInjector: () => void;
installEmbedRefererRewriter: () => void;
+ publishAppState: (state: AppState) => void;
registerIpcHandlers: () => void;
setNativeThemeSource: (source: OkThemeSource) => void;
refreshApplicationMenu: () => void;
@@ -24,7 +25,6 @@ interface BootstrapDeps {
}
interface BootstrapResult {
- appState: AppState;
pendingSchemaIncompatibility: SchemaIncompatibilityDiagnostic | null;
}
@@ -45,6 +45,7 @@ export async function runBootstrap(deps: BootstrapDeps): Promise<BootstrapResult
deps.installLocalhostCorsInjector();
deps.installEmbedRefererRewriter();
+ deps.publishAppState(appState);
deps.registerIpcHandlers();
deps.setNativeThemeSource('system');
@@ -52,5 +53,5 @@ export async function runBootstrap(deps: BootstrapDeps): Promise<BootstrapResult
deps.refreshApplicationMenu();
deps.installDockIcon();
- return { appState, pendingSchemaIncompatibility };
+ return { pendingSchemaIncompatibility };
}
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 0ee91659c..453b2032a 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -6603,6 +6603,9 @@ function bootPrimaryInstance(): void {
evaluateSchemaCompatibility,
installLocalhostCorsInjector,
installEmbedRefererRewriter,
+ publishAppState: (state) => {
+ appState = state;
+ },
registerIpcHandlers,
setNativeThemeSource: (source) => {
nativeTheme.themeSource = source;
@@ -6613,7 +6616,6 @@ function bootPrimaryInstance(): void {
appVersion: app.getVersion(),
maxSupportedSchemaVersion: MAX_SUPPORTED_SCHEMA_VERSION,
});
- appState = result.appState;
if (process.platform !== 'darwin') {
nativeTheme.on('updated', fanOutChromeColors);
diff --git a/packages/desktop/tests/main/bootstrap.test.ts b/packages/desktop/tests/main/bootstrap.test.ts
index 0cecffff9..ce9977186 100644
--- a/packages/desktop/tests/main/bootstrap.test.ts
+++ b/packages/desktop/tests/main/bootstrap.test.ts
@@ -51,6 +51,9 @@ function makeTracingDeps(overrides?: {
installEmbedRefererRewriter: () => {
calls.push({ step: 'installEmbedRefererRewriter' });
},
+ publishAppState: (state: typeof baseState) => {
+ calls.push({ step: 'publishAppState', args: { appState: state } });
+ },
registerIpcHandlers: () => {
calls.push({ step: 'registerIpcHandlers' });
},
@@ -71,10 +74,27 @@ function makeTracingDeps(overrides?: {
appVersion: '0.99.0',
maxSupportedSchemaVersion: 1,
},
+ loadedState: baseState,
};
}
describe('runBootstrap order-of-operations', () => {
+ test('publishes loaded appState before IPC handlers register', async () => {
+ const { calls, deps, loadedState } = makeTracingDeps({
+ appStateOverride: { spellCheckEnabled: false },
+ });
+ expect(loadedState).not.toEqual(emptyState());
+ await runBootstrap(deps);
+
+ const publication = calls.find((c) => c.step === 'publishAppState');
+ const publicationIdx = calls.findIndex((c) => c.step === 'publishAppState');
+ const ipcIdx = calls.findIndex((c) => c.step === 'registerIpcHandlers');
+ expect(publicationIdx).toBeGreaterThanOrEqual(0);
+ expect(ipcIdx).toBeGreaterThanOrEqual(0);
+ expect(publicationIdx).toBeLessThan(ipcIdx);
+ expect(publication?.args).toEqual({ appState: loadedState });
+ });
+
test('IPC handlers register before nativeTheme.themeSource is set', async () => {
const { calls, deps } = makeTracingDeps();
await runBootstrap(deps);
@@ -104,6 +124,7 @@ describe('runBootstrap order-of-operations', () => {
'evaluateSchemaCompatibility',
'installLocalhostCorsInjector',
'installEmbedRefererRewriter',
+ 'publishAppState',
'registerIpcHandlers',
'setNativeThemeSource',
'refreshApplicationMenu',
@@ -123,6 +144,7 @@ describe('runBootstrap order-of-operations', () => {
'evaluateSchemaCompatibility',
'installLocalhostCorsInjector',
'installEmbedRefererRewriter',
+ 'publishAppState',
'registerIpcHandlers',
'setNativeThemeSource',
'refreshApplicationMenu',
@@ -132,10 +154,9 @@ describe('runBootstrap order-of-operations', () => {
});
describe('runBootstrap return shape', () => {
- test('returns loaded appState and null diagnostic on the happy path', async () => {
+ test('returns a null diagnostic on the happy path', async () => {
const { deps } = makeTracingDeps();
const result = await runBootstrap(deps);
- expect(result.appState.schemaVersion).toBe(1);
expect(result.pendingSchemaIncompatibility).toBeNull();
});
diff --git a/packages/desktop/tests/smoke/terminal-dock.e2e.ts b/packages/desktop/tests/smoke/terminal-dock.e2e.ts
index 2e18dc583..0f68c4285 100644
--- a/packages/desktop/tests/smoke/terminal-dock.e2e.ts
+++ b/packages/desktop/tests/smoke/terminal-dock.e2e.ts
@@ -125,6 +125,7 @@ interface LaunchOpts {
restrictPath?: boolean;
connectionsAvailable?: boolean;
phaseTrace?: boolean;
+ deepLink?: boolean;
}
async function launchApp(s: Seed, opts: LaunchOpts = {}): Promise<ElectronApplication> {
@@ -140,7 +141,7 @@ async function launchApp(s: Seed, opts: LaunchOpts = {}): Promise<ElectronApplic
electron,
desktopLaunchOptions({
target: TARGET,
- args: [`--user-data-dir=${s.userDataDir}`, deepLink],
+ args: [`--user-data-dir=${s.userDataDir}`, ...(opts.deepLink === false ? [] : [deepLink])],
timeout: 30_000,
env: {
...process.env,
@@ -1710,8 +1711,10 @@ test.describe('Docked terminal — live Electron', () => {
test.setTimeout(sumOfDeclaredBoundsMs(test.info()));
const s = seed('editor-relaunch', { consent: true });
track(s.tmpHome, s.projectDir);
- const launchOnProfile = async (): Promise<{ app: ElectronApplication; page: Page }> => {
- const app = await launchApp(s, { restrictPath: true });
+ const launchOnProfile = async (
+ deepLink = true,
+ ): Promise<{ app: ElectronApplication; page: Page }> => {
+ const app = await launchApp(s, { restrictPath: true, deepLink });
captureStderrFor(app, { home: s.tmpHome, cleanupDirs: [s.tmpHome, s.projectDir] });
return { app, page: await findEditorWindow(app) };
};
@@ -1726,7 +1729,7 @@ test.describe('Docked terminal — live Electron', () => {
await expect.poll(() => viewMenuEditorLabel(first.app), { timeout: 8_000 }).toBe('Show Editor');
await closeAppForRelaunch(first.app);
- const second = await launchOnProfile();
+ const second = await launchOnProfile(false);
await expect
.poll(() => restoredDockState(second.page), { timeout: 25_000 })
.toMatchObject({ editorVisible: false });
@@ -1741,7 +1744,7 @@ test.describe('Docked terminal — live Electron', () => {
await expect(editorPaneButton(second.page)).toHaveAttribute('aria-pressed', 'true');
await closeAppForRelaunch(second.app);
- const third = await launchOnProfile();
+ const third = await launchOnProfile(false);
await expect(editorPaneButton(third.page)).toHaveAttribute('aria-pressed', 'true', {
timeout: 25_000,
});