Skip to content

Commit 12feb2c

Browse files
committed
Add button to reset plugin settings and metadata
1 parent 42c15f4 commit 12feb2c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,10 @@ export default class GitHubSyncPlugin extends Plugin {
287287
this.syncManager.stopSyncInterval();
288288
this.syncManager.startSyncInterval(this.settings.syncInterval);
289289
}
290+
291+
async reset() {
292+
this.settings = DEFAULT_SETTINGS;
293+
this.saveSettings();
294+
await this.syncManager.resetMetadata();
295+
}
290296
}

src/metadata-store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,8 @@ export default class MetadataStore {
7777
});
7878
return this.writeQueue;
7979
}
80+
81+
reset() {
82+
this.data = { lastSync: 0, files: {} };
83+
}
8084
}

src/settings/tab.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginSettingTab, App, Setting, TextComponent } from "obsidian";
1+
import { PluginSettingTab, App, Setting, TextComponent, Modal } from "obsidian";
22
import GitHubSyncPlugin from "src/main";
33

44
export default class GitHubSyncSettingsTab extends PluginSettingTab {
@@ -269,5 +269,39 @@ export default class GitHubSyncSettingsTab extends PluginSettingTab {
269269
this.plugin.saveSettings();
270270
});
271271
});
272+
273+
new Setting(containerEl)
274+
.setName("Reset")
275+
.setDesc("Reset the plugin settings and metadata")
276+
.addButton((button) => {
277+
button
278+
.setButtonText("RESET")
279+
.setCta()
280+
.onClick(() => {
281+
const modal = new Modal(this.plugin.app);
282+
modal.setTitle("Are you sure?");
283+
modal.setContent(
284+
"This will completely delete all sync metadata and plugin settings.\n" +
285+
"You'll have to repeat the first sync if you want to use the plugin again.",
286+
);
287+
new Setting(modal.contentEl);
288+
new Setting(modal.contentEl)
289+
.addButton((btn) =>
290+
btn
291+
.setButtonText("Reset")
292+
.setCta()
293+
.onClick(async () => {
294+
await this.plugin.reset();
295+
modal.close();
296+
}),
297+
)
298+
.addButton((btn) =>
299+
btn.setButtonText("Cancel").onClick(() => {
300+
modal.close();
301+
}),
302+
);
303+
modal.open();
304+
});
305+
});
272306
}
273307
}

src/sync-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,4 +953,9 @@ export default class SyncManager {
953953
this.stopSyncInterval();
954954
return this.startSyncInterval(minutes);
955955
}
956+
957+
async resetMetadata() {
958+
this.metadataStore.reset();
959+
await this.metadataStore.save();
960+
}
956961
}

0 commit comments

Comments
 (0)