From a1ecb1b39954422de150169a71d0b9da8ee84167 Mon Sep 17 00:00:00 2001 From: Vinzent Date: Wed, 7 Sep 2022 22:58:29 +0200 Subject: [PATCH] feat: specify source control refresh timer #199 --- src/constants.ts | 1 + src/main.ts | 24 +++++++++++++++--------- src/settings.ts | 14 ++++++++++++++ src/types.ts | 1 + 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 4d2dbb96..0dd046af 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -25,6 +25,7 @@ export const DEFAULT_SETTINGS: ObsidianGitSettings = { changedFilesInStatusBar: false, username: "", showedMobileNotice: false, + refreshSourceControlTimer: 7000, }; export const GIT_VIEW_CONFIG = { diff --git a/src/main.ts b/src/main.ts index 3cc13bb9..ee46f97c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -40,15 +40,7 @@ export default class ObsidianGit extends Plugin { createEvent: EventRef; renameEvent: EventRef; - debRefresh = debounce( - () => { - if (this.settings.refreshSourceControl) { - this.refresh(); - } - }, - 7000, - true - ); + debRefresh: Debouncer; setState(state: PluginState): void { this.state = state; @@ -103,6 +95,7 @@ export default class ObsidianGit extends Plugin { defaultMod: true, }); + this.setRefreshDebouncer(); this.addCommand({ id: 'edit-gitignore', @@ -331,6 +324,19 @@ export default class ObsidianGit extends Plugin { } + setRefreshDebouncer(): void { + this.debRefresh?.cancel(); + this.debRefresh = debounce( + () => { + if (this.settings.refreshSourceControl) { + this.refresh(); + } + }, + this.settings.refreshSourceControlTimer, + true + ); + } + async showNotices(): Promise { const length = 10000; if (this.manifest.id === "obsidian-git" && Platform.isDesktopApp && !this.settings.showedMobileNotice) { diff --git a/src/settings.ts b/src/settings.ts index b3ae7159..1b6e9164 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -331,6 +331,20 @@ export class ObsidianGitSettingsTab extends PluginSettingTab { }) ); + new Setting(containerEl) + .setName("Source Control View refresh interval") + .setDesc("Milliseconds two wait after file change before refreshing the Source Control View") + .addText((toggle) => + toggle + .setValue(plugin.settings.refreshSourceControlTimer.toString()) + .setPlaceholder("7000") + .onChange((value) => { + plugin.settings.refreshSourceControlTimer = Math.max(parseInt(value), 500); + plugin.saveSettings(); + plugin.setRefreshDebouncer(); + }) + ); + new Setting(containerEl) .setName("Disable notifications") .setDesc( diff --git a/src/types.ts b/src/types.ts index 7bc84ee5..a7743088 100644 --- a/src/types.ts +++ b/src/types.ts @@ -31,6 +31,7 @@ export interface ObsidianGitSettings { refreshSourceControl: boolean; basePath: string; showedMobileNotice: boolean; + refreshSourceControlTimer: number; } export type SyncMethod = 'rebase' | 'merge' | 'reset';