Skip to content

Commit 3d928bb

Browse files
committed
💄 auto fetch period
1 parent 32d22db commit 3d928bb

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

extensions/git/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@
10281028
"type": "number",
10291029
"scope": "resource",
10301030
"description": "%config.autofetchPeriod%",
1031-
"default": 3
1031+
"default": 180
10321032
},
10331033
"git.branchValidationRegex": {
10341034
"type": "string",

extensions/git/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"config.autoRepositoryDetection.openEditors": "Scan for parent folders of open files.",
6969
"config.autorefresh": "Whether auto refreshing is enabled.",
7070
"config.autofetch": "When enabled, commits will automatically be fetched from the default remote of the current Git repository.",
71-
"config.autofetchPeriod": "Duration in minutes between each automatic git fetch, when `git.autofetch` is enabled.",
71+
"config.autofetchPeriod": "Duration in seconds between each automatic git fetch, when `git.autofetch` is enabled.",
7272
"config.confirmSync": "Confirm before synchronizing git repositories.",
7373
"config.countBadge": "Controls the git badge counter.",
7474
"config.countBadge.all": "Count all changes.",

extensions/git/src/autofetch.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ export class AutoFetcher {
1919

2020
private static DidInformUser = 'autofetch.didInformUser';
2121

22-
private _onDidChange = new EventEmitter<boolean | number>();
22+
private _onDidChange = new EventEmitter<boolean>();
2323
private onDidChange = this._onDidChange.event;
2424

2525
private _enabled: boolean = false;
2626
get enabled(): boolean { return this._enabled; }
2727
set enabled(enabled: boolean) { this._enabled = enabled; this._onDidChange.fire(enabled); }
2828

29-
private _timeout: number = workspace.getConfiguration('git').get<number>('autofetchPeriod', 3) * 60 * 1000;
30-
private get timeout(): number { return this._timeout; }
31-
private set timeout(minutes: number) { this._timeout = minutes * 60 * 1000; this._onDidChange.fire(minutes); }
32-
3329
private disposables: Disposable[] = [];
3430

3531
constructor(private repository: Repository, private globalState: Memento) {
@@ -73,19 +69,19 @@ export class AutoFetcher {
7369

7470
private onConfiguration(): void {
7571
const gitConfig = workspace.getConfiguration('git');
76-
const minutes = gitConfig.get<number>('autofetchPeriod', 3);
77-
const autofetch = gitConfig.get<boolean>('autofetch');
78-
79-
if (this.timeout !== minutes) {
80-
this.timeout = minutes;
81-
}
8272

83-
if (this.enabled !== autofetch) {
84-
autofetch ? this.enable() : this.disable();
73+
if (gitConfig.get<boolean>('autofetch') === false) {
74+
this.disable();
75+
} else {
76+
this.enable();
8577
}
8678
}
8779

8880
enable(): void {
81+
if (this.enabled) {
82+
return;
83+
}
84+
8985
this.enabled = true;
9086
this.run();
9187
}
@@ -114,9 +110,11 @@ export class AutoFetcher {
114110
return;
115111
}
116112

117-
const timeout = new Promise(c => setTimeout(c, this.timeout));
118-
const onChanged = eventToPromise(filterEvent(this.onDidChange, () => true));
119-
await Promise.race([timeout, onChanged]);
113+
const period = workspace.getConfiguration('git').get<number>('autofetchPeriod', 180) * 1000;
114+
const timeout = new Promise(c => setTimeout(c, period));
115+
const whenDisabled = eventToPromise(filterEvent(this.onDidChange, enabled => !enabled));
116+
117+
await Promise.race([timeout, whenDisabled]);
120118
}
121119
}
122120

0 commit comments

Comments
 (0)