Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): cold-start share link lands on shared target (#1861)
miles-kt-inkeepce6841b2233f
diff --git a/.changeset/share-cold-start-wrong-target.md b/.changeset/share-cold-start-wrong-target.mdnew file mode 100644index 000000000..6fa040d0f--- /dev/null+++ b/.changeset/share-cold-start-wrong-target.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Clicking an Open Knowledge share link when the app was not already running no longer opens a previously-opened project instead of the shared doc or folder. On a cold start the boot path now recognizes a valid share deep-link as claiming the launch (the same way a single-file `ok <file>` open does) and suppresses the default window-restore, so the share flow opens the shared target — or the receive prompt — directly. Invalid or unsupported share links, and `screen` deep-links, still restore the previous window as before, since they need an existing window to surface their toast or navigation. Git preflight still runs for share launches.diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.tsindex 763d151d6..df99c17f9 100644--- a/packages/desktop/src/main/index.ts+++ b/packages/desktop/src/main/index.ts@@ -2464,7 +2464,7 @@ function bootPrimaryInstance(): void {lastOpenedProject: appState.lastOpenedProject,optionHeld: process.argv.includes('--navigator'),pathExists: existsSync,- urlLaunch: protocolControl.singleFileLaunch(),+ urlLaunch: protocolControl.urlLaunchOwnsWindow(),});if (decision.clearSnapshot) {appState = { ...appState, pendingWindowRestore: null };@@ -2475,7 +2475,8 @@ function bootPrimaryInstance(): void {}}- if (decision.action !== 'none') {+ const skipGitPreflight = decision.action === 'none' && protocolControl.singleFileLaunch();+ if (!skipGitPreflight) {const gitOutcome = await ensureGitAvailable({assertGitAvailable,showMessageBox: async (opts) =>diff --git a/packages/desktop/src/main/url-scheme.ts b/packages/desktop/src/main/url-scheme.tsindex 6ae960579..8a2c842ba 100644--- a/packages/desktop/src/main/url-scheme.ts+++ b/packages/desktop/src/main/url-scheme.ts@@ -348,6 +348,7 @@ interface BrowserWindowHandle {}interface ProtocolHandlerControl {singleFileLaunch(): boolean;+ urlLaunchOwnsWindow(): boolean;drainQueuedUrls(): void;routeUrl(url: string): void;}@@ -363,6 +364,7 @@ export function registerProtocolHandler(deps: ProtocolHandlerDeps): ProtocolHandconst shareDedup = new Map<string, number>();let flushed = false;let singleFileLaunch = false;+ let urlLaunchOwnsWindow = false;if (!deps.app.isPackaged) {try {@@ -669,9 +671,13 @@ export function registerProtocolHandler(deps: ProtocolHandlerDeps): ProtocolHand};const enqueueOrRoute = (url: string): void => {- if (parseOpenKnowledgeFileUrl(url) !== null) {+ const isSingleFile = parseOpenKnowledgeFileUrl(url) !== null;+ if (isSingleFile) {singleFileLaunch = true;}+ if (isSingleFile || parseShareUrl(url)?.kind === 'ok') {+ urlLaunchOwnsWindow = true;+ }if (flushed) {routeUrl(url);} else {@@ -733,6 +739,7 @@ export function registerProtocolHandler(deps: ProtocolHandlerDeps): ProtocolHandreturn {singleFileLaunch: () => singleFileLaunch,+ urlLaunchOwnsWindow: () => urlLaunchOwnsWindow,drainQueuedUrls: () => drainAll(),routeUrl: (url) => enqueueOrRoute(url),};diff --git a/packages/desktop/tests/main/url-scheme-handler.test.ts b/packages/desktop/tests/main/url-scheme-handler.test.tsindex d7d83005b..affab568f 100644--- a/packages/desktop/tests/main/url-scheme-handler.test.ts+++ b/packages/desktop/tests/main/url-scheme-handler.test.ts@@ -587,6 +587,68 @@ describe('registerProtocolHandler — single-file launch control', () => {});});+describe('registerProtocolHandler — urlLaunchOwnsWindow (boot-restore suppression)', () => {+ let env: TestEnv;+ const SHARE_URL = `https://openknowledge.ai/d/${encodeShareUrl(+ 'https://github.com/inkeep/notes/blob/main/welcome.md',+ )}`;+ const FILE_URL = `openknowledge://open?file=${encodeURIComponent('/Users/me/notes/todo.md')}`;++ beforeEach(() => {+ env = makeEnv();+ });++ function makeControl() {+ return registerProtocolHandler({+ app: env.app,+ focusWindowForProject: env.focusWindowForProject,+ openProject: env.openProject,+ openEphemeralFile: env.openEphemeralFile,+ sendDeepLink: env.sendDeepLink,+ getAnyReadyWindow: env.getAnyReadyWindow,+ setTimeout: (cb, ms) => env.timers.push({ cb, ms }),+ });+ }++ test('becomes true after a valid share URL queued pre-ready (suppresses boot-restore window)', () => {+ const control = makeControl();+ expect(control.urlLaunchOwnsWindow()).toBe(false);+ env.app.fireOpenUrl(SHARE_URL);+ expect(control.urlLaunchOwnsWindow()).toBe(true);+ });++ test('becomes true after a valid custom-scheme share URL', () => {+ const control = makeControl();+ const blobUrl = 'https://github.com/inkeep/notes/blob/main/welcome.md';+ env.app.fireOpenUrl(`openknowledge://share?url=${encodeURIComponent(blobUrl)}`);+ expect(control.urlLaunchOwnsWindow()).toBe(true);+ });++ test('becomes true after a single-file file= URL (own-window launch parity)', () => {+ const control = makeControl();+ env.app.fireOpenUrl(FILE_URL);+ expect(control.urlLaunchOwnsWindow()).toBe(true);+ });++ test('stays false for an invalid share URL — its toast needs an existing window', () => {+ const control = makeControl();+ env.app.fireOpenUrl('https://openknowledge.ai/d/!!!not-base64!!!');+ expect(control.urlLaunchOwnsWindow()).toBe(false);+ });++ test('stays false after a screen deep-link — it targets an existing window', () => {+ const control = makeControl();+ env.app.fireOpenUrl('openknowledge://screen?name=settings');+ expect(control.urlLaunchOwnsWindow()).toBe(false);+ });++ test('stays false after a legacy project deep-link (unchanged scope)', () => {+ const control = makeControl();+ env.app.fireOpenUrl('openknowledge://open?project=/tmp/p&doc=a.md');+ expect(control.urlLaunchOwnsWindow()).toBe(false);+ });+});+describe('registerProtocolHandler — second-instance argv parsing', () => {test('extracts openknowledge:// entries from second-instance argv', async () => {const env = makeEnv();