From ffa20a9201dd65c31bd455847bb9ed40681ab189 Mon Sep 17 00:00:00 2001 From: Michael Naumov Date: Mon, 20 Jul 2026 08:36:44 -0600 Subject: [PATCH] feat: register the open demo vault command Add the shared OpenDemoVaultCommandHandler to the command batch so users can open the plugin's demo vault. The plugin test seeds the plugin notice component and asserts the handler is constructed. --- src/plugin.test.ts | 10 ++++++++++ src/plugin.ts | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/plugin.test.ts b/src/plugin.test.ts index 266f2b8..6f1e8fa 100644 --- a/src/plugin.test.ts +++ b/src/plugin.test.ts @@ -3,9 +3,11 @@ import type { PluginManifest } from 'obsidian'; import type { CommandHandlerComponent } from 'obsidian-dev-utils/obsidian/command-handlers/command-handler-component'; +import type { PluginNoticeComponent } from 'obsidian-dev-utils/obsidian/components/plugin-notice-component'; import { Component } from 'obsidian'; import { castTo } from 'obsidian-dev-utils/object-utils'; +import { OpenDemoVaultCommandHandler } from 'obsidian-dev-utils/obsidian/command-handlers/open-demo-vault-command-handler'; import { PluginSettingsTabComponent } from 'obsidian-dev-utils/obsidian/components/plugin-settings-tab-component'; import { strictProxy } from 'obsidian-dev-utils/strict-proxy'; import { App } from 'obsidian-test-mocks/obsidian'; @@ -35,6 +37,10 @@ vi.mock('obsidian-dev-utils/obsidian/components/plugin-settings-tab-component', // --- Collaborator dev-utils components NOT added as children: bare constructor spies. --- +vi.mock('obsidian-dev-utils/obsidian/command-handlers/open-demo-vault-command-handler', () => ({ + OpenDemoVaultCommandHandler: vi.fn() +})); + vi.mock('obsidian-dev-utils/obsidian/command-handlers/open-settings-command-handler', () => ({ OpenSettingsCommandHandler: vi.fn() })); @@ -102,6 +108,7 @@ import { Plugin } from './plugin.ts'; interface PluginInternals { _commandHandlerComponent: CommandHandlerComponent; + _pluginNoticeComponent: PluginNoticeComponent; onloadImpl(): void; } @@ -128,6 +135,8 @@ describe('Plugin', () => { const registerCommandHandlers = vi.fn(); // The base PluginBase.onload seeds and pre-wires commandHandlerComponent before onloadImpl; seed it here so onloadImpl can register the plugin's command handlers on it. internals._commandHandlerComponent = strictProxy({ registerCommandHandlers }); + // The base PluginBase.onload also seeds pluginNoticeComponent before onloadImpl; seed it here so the OpenDemoVaultCommandHandler can read it via the non-null getter. + internals._pluginNoticeComponent = strictProxy({}); internals.onloadImpl(); @@ -137,6 +146,7 @@ describe('Plugin', () => { expect(PluginSettingsTab).toHaveBeenCalledOnce(); expect(DevToolsComponent).toHaveBeenCalledOnce(); expect(registerCommandHandlers).toHaveBeenCalledOnce(); + expect(OpenDemoVaultCommandHandler).toHaveBeenCalledOnce(); expect(LongRunningTasksComponent).toHaveBeenCalledOnce(); expect(ErrorStackTraceLimitComponent).toHaveBeenCalledOnce(); expect(LongStackTracesComponent).toHaveBeenCalledOnce(); diff --git a/src/plugin.ts b/src/plugin.ts index f07c024..f984eee 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,6 +1,7 @@ import type { FileSystemAdapter } from 'obsidian'; import { getDebugController } from 'obsidian-dev-utils/debug'; +import { OpenDemoVaultCommandHandler } from 'obsidian-dev-utils/obsidian/command-handlers/open-demo-vault-command-handler'; import { OpenSettingsCommandHandler } from 'obsidian-dev-utils/obsidian/command-handlers/open-settings-command-handler'; import { PluginSettingsTabComponent } from 'obsidian-dev-utils/obsidian/components/plugin-settings-tab-component'; import { PluginDataHandler } from 'obsidian-dev-utils/obsidian/data-handler'; @@ -46,7 +47,13 @@ export class Plugin extends PluginBase { app: this.app, settingTab: pluginSettingsTab }), - new ToggleDevToolsButtonCommandHandler(devToolsComponent) + new ToggleDevToolsButtonCommandHandler(devToolsComponent), + new OpenDemoVaultCommandHandler({ + app: this.app, + pluginId: this.manifest.id, + pluginNoticeComponent: this.pluginNoticeComponent, + pluginVersion: this.manifest.version + }) ]); new LongRunningTasksComponent({