Skip to content

Commit 23a52b6

Browse files
committed
feat: add confirmation modal for enabling attachment sync in SurfSense plugin
1 parent 6eeaa2d commit 23a52b6

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { type App, Modal, Setting } from "obsidian";
2+
3+
/**
4+
* Confirmation modal shown before enabling attachment sync.
5+
* Attachment files can be large and increase sync latency/cost.
6+
*/
7+
export class AttachmentsConfirmModal extends Modal {
8+
private resolver: ((confirmed: boolean) => void) | null = null;
9+
10+
constructor(app: App) {
11+
super(app);
12+
}
13+
14+
onOpen(): void {
15+
this.setTitle("Enable attachment sync?");
16+
this.contentEl.empty();
17+
18+
new Setting(this.contentEl).setDesc(
19+
"Syncing attachments (images, PDFs, and other non-Markdown files) can make indexing slower, especially on large vaults.",
20+
);
21+
new Setting(this.contentEl).setDesc(
22+
"You can disable this anytime in settings if syncing becomes too slow.",
23+
);
24+
25+
new Setting(this.contentEl)
26+
.addButton((btn) =>
27+
btn
28+
.setButtonText("Cancel")
29+
.onClick(() => this.resolveAndClose(false)),
30+
)
31+
.addButton((btn) =>
32+
btn
33+
.setButtonText("Enable")
34+
.setCta()
35+
.onClick(() => this.resolveAndClose(true)),
36+
);
37+
}
38+
39+
onClose(): void {
40+
this.contentEl.empty();
41+
if (this.resolver) {
42+
this.resolver(false);
43+
this.resolver = null;
44+
}
45+
}
46+
47+
waitForConfirmation(): Promise<boolean> {
48+
this.open();
49+
return new Promise<boolean>((resolve) => {
50+
this.resolver = resolve;
51+
});
52+
}
53+
54+
private resolveAndClose(confirmed: boolean): void {
55+
if (this.resolver) {
56+
this.resolver(confirmed);
57+
this.resolver = null;
58+
}
59+
this.close();
60+
}
61+
}

surfsense_obsidian/src/settings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
setIcon,
88
} from "obsidian";
99
import { AuthError } from "./api-client";
10+
import { AttachmentsConfirmModal } from "./attachments-confirm-modal";
1011
import { normalizeFolder, parseExcludePatterns } from "./excludes";
1112
import { FolderSuggestModal } from "./folder-suggest-modal";
1213
import type SurfSensePlugin from "./main";
@@ -210,6 +211,17 @@ export class SurfSenseSettingTab extends PluginSettingTab {
210211
toggle
211212
.setValue(settings.includeAttachments)
212213
.onChange(async (value) => {
214+
const isEnabling =
215+
value && !this.plugin.settings.includeAttachments;
216+
if (isEnabling) {
217+
const confirmed = await new AttachmentsConfirmModal(
218+
this.app,
219+
).waitForConfirmation();
220+
if (!confirmed) {
221+
this.display();
222+
return;
223+
}
224+
}
213225
this.plugin.settings.includeAttachments = value;
214226
await this.plugin.saveSettings();
215227
}),

0 commit comments

Comments
 (0)