Add error on duplicate plugin load

This commit is contained in:
Andras Schmelczer 2025-11-28 21:27:27 +00:00
parent 91f49d6997
commit 10fdc938c5

View file

@ -43,6 +43,14 @@ export default class VaultLinkPlugin extends Plugin {
public async onload(): Promise<void> {
this.app.workspace.onLayoutReady(async () => {
if ((globalThis as any).VAULT_LINK_RUNNING_INSTANCE) {
new Notice(
"Another instance of VaultLink is already running. Please disable the duplicate instance."
);
throw new Error("VaultLink instance already running");
}
(globalThis as any).VAULT_LINK_RUNNING_INSTANCE = this;
const client = await this.createSyncClient();
this.registerObsidianExtensions(client);
@ -188,6 +196,10 @@ export default class VaultLinkPlugin extends Plugin {
this.register(() => {
editorStatusDisplayManager.dispose();
});
this.register(() => {
(globalThis as any).VAULT_LINK_RUNNING_INSTANCE = null;
});
}
private addRibbonIcons(): void {