Skip to content

Commit

Permalink
feat: specify source control refresh timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Sep 7, 2022
1 parent 82b2c1a commit a1ecb1b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const DEFAULT_SETTINGS: ObsidianGitSettings = {
changedFilesInStatusBar: false,
username: "",
showedMobileNotice: false,
refreshSourceControlTimer: 7000,
};

export const GIT_VIEW_CONFIG = {
Expand Down
24 changes: 15 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<undefined, void>;

setState(state: PluginState): void {
this.state = state;
Expand Down Expand Up @@ -103,6 +95,7 @@ export default class ObsidianGit extends Plugin {
defaultMod: true,
});

this.setRefreshDebouncer();

this.addCommand({
id: 'edit-gitignore',
Expand Down Expand Up @@ -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<void> {
const length = 10000;
if (this.manifest.id === "obsidian-git" && Platform.isDesktopApp && !this.settings.showedMobileNotice) {
Expand Down
14 changes: 14 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ObsidianGitSettings {
refreshSourceControl: boolean;
basePath: string;
showedMobileNotice: boolean;
refreshSourceControlTimer: number;
}

export type SyncMethod = 'rebase' | 'merge' | 'reset';
Expand Down

0 comments on commit a1ecb1b

Please sign in to comment.