From 23a52b6c634520ef8e604d834d70744929110763 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Wed, 22 Apr 2026 22:01:14 +0530 Subject: [PATCH] feat: add confirmation modal for enabling attachment sync in SurfSense plugin --- .../src/attachments-confirm-modal.ts | 61 +++++++++++++++++++ surfsense_obsidian/src/settings.ts | 12 ++++ 2 files changed, 73 insertions(+) create mode 100644 surfsense_obsidian/src/attachments-confirm-modal.ts diff --git a/surfsense_obsidian/src/attachments-confirm-modal.ts b/surfsense_obsidian/src/attachments-confirm-modal.ts new file mode 100644 index 000000000..54a0a4afd --- /dev/null +++ b/surfsense_obsidian/src/attachments-confirm-modal.ts @@ -0,0 +1,61 @@ +import { type App, Modal, Setting } from "obsidian"; + +/** + * Confirmation modal shown before enabling attachment sync. + * Attachment files can be large and increase sync latency/cost. + */ +export class AttachmentsConfirmModal extends Modal { + private resolver: ((confirmed: boolean) => void) | null = null; + + constructor(app: App) { + super(app); + } + + onOpen(): void { + this.setTitle("Enable attachment sync?"); + this.contentEl.empty(); + + new Setting(this.contentEl).setDesc( + "Syncing attachments (images, PDFs, and other non-Markdown files) can make indexing slower, especially on large vaults.", + ); + new Setting(this.contentEl).setDesc( + "You can disable this anytime in settings if syncing becomes too slow.", + ); + + new Setting(this.contentEl) + .addButton((btn) => + btn + .setButtonText("Cancel") + .onClick(() => this.resolveAndClose(false)), + ) + .addButton((btn) => + btn + .setButtonText("Enable") + .setCta() + .onClick(() => this.resolveAndClose(true)), + ); + } + + onClose(): void { + this.contentEl.empty(); + if (this.resolver) { + this.resolver(false); + this.resolver = null; + } + } + + waitForConfirmation(): Promise { + this.open(); + return new Promise((resolve) => { + this.resolver = resolve; + }); + } + + private resolveAndClose(confirmed: boolean): void { + if (this.resolver) { + this.resolver(confirmed); + this.resolver = null; + } + this.close(); + } +} diff --git a/surfsense_obsidian/src/settings.ts b/surfsense_obsidian/src/settings.ts index 8efea62fe..acb650790 100644 --- a/surfsense_obsidian/src/settings.ts +++ b/surfsense_obsidian/src/settings.ts @@ -7,6 +7,7 @@ import { setIcon, } from "obsidian"; import { AuthError } from "./api-client"; +import { AttachmentsConfirmModal } from "./attachments-confirm-modal"; import { normalizeFolder, parseExcludePatterns } from "./excludes"; import { FolderSuggestModal } from "./folder-suggest-modal"; import type SurfSensePlugin from "./main"; @@ -210,6 +211,17 @@ export class SurfSenseSettingTab extends PluginSettingTab { toggle .setValue(settings.includeAttachments) .onChange(async (value) => { + const isEnabling = + value && !this.plugin.settings.includeAttachments; + if (isEnabling) { + const confirmed = await new AttachmentsConfirmModal( + this.app, + ).waitForConfirmation(); + if (!confirmed) { + this.display(); + return; + } + } this.plugin.settings.includeAttachments = value; await this.plugin.saveSettings(); }),