提交 3d928bbb 编写于 作者: J Joao Moreno

💄 auto fetch period

上级 32d22dba
...@@ -1028,7 +1028,7 @@ ...@@ -1028,7 +1028,7 @@
"type": "number", "type": "number",
"scope": "resource", "scope": "resource",
"description": "%config.autofetchPeriod%", "description": "%config.autofetchPeriod%",
"default": 3 "default": 180
}, },
"git.branchValidationRegex": { "git.branchValidationRegex": {
"type": "string", "type": "string",
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
"config.autoRepositoryDetection.openEditors": "Scan for parent folders of open files.", "config.autoRepositoryDetection.openEditors": "Scan for parent folders of open files.",
"config.autorefresh": "Whether auto refreshing is enabled.", "config.autorefresh": "Whether auto refreshing is enabled.",
"config.autofetch": "When enabled, commits will automatically be fetched from the default remote of the current Git repository.", "config.autofetch": "When enabled, commits will automatically be fetched from the default remote of the current Git repository.",
"config.autofetchPeriod": "Duration in minutes between each automatic git fetch, when `git.autofetch` is enabled.", "config.autofetchPeriod": "Duration in seconds between each automatic git fetch, when `git.autofetch` is enabled.",
"config.confirmSync": "Confirm before synchronizing git repositories.", "config.confirmSync": "Confirm before synchronizing git repositories.",
"config.countBadge": "Controls the git badge counter.", "config.countBadge": "Controls the git badge counter.",
"config.countBadge.all": "Count all changes.", "config.countBadge.all": "Count all changes.",
......
...@@ -19,17 +19,13 @@ export class AutoFetcher { ...@@ -19,17 +19,13 @@ export class AutoFetcher {
private static DidInformUser = 'autofetch.didInformUser'; private static DidInformUser = 'autofetch.didInformUser';
private _onDidChange = new EventEmitter<boolean | number>(); private _onDidChange = new EventEmitter<boolean>();
private onDidChange = this._onDidChange.event; private onDidChange = this._onDidChange.event;
private _enabled: boolean = false; private _enabled: boolean = false;
get enabled(): boolean { return this._enabled; } get enabled(): boolean { return this._enabled; }
set enabled(enabled: boolean) { this._enabled = enabled; this._onDidChange.fire(enabled); } set enabled(enabled: boolean) { this._enabled = enabled; this._onDidChange.fire(enabled); }
private _timeout: number = workspace.getConfiguration('git').get<number>('autofetchPeriod', 3) * 60 * 1000;
private get timeout(): number { return this._timeout; }
private set timeout(minutes: number) { this._timeout = minutes * 60 * 1000; this._onDidChange.fire(minutes); }
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
constructor(private repository: Repository, private globalState: Memento) { constructor(private repository: Repository, private globalState: Memento) {
...@@ -73,19 +69,19 @@ export class AutoFetcher { ...@@ -73,19 +69,19 @@ export class AutoFetcher {
private onConfiguration(): void { private onConfiguration(): void {
const gitConfig = workspace.getConfiguration('git'); const gitConfig = workspace.getConfiguration('git');
const minutes = gitConfig.get<number>('autofetchPeriod', 3);
const autofetch = gitConfig.get<boolean>('autofetch');
if (this.timeout !== minutes) {
this.timeout = minutes;
}
if (this.enabled !== autofetch) { if (gitConfig.get<boolean>('autofetch') === false) {
autofetch ? this.enable() : this.disable(); this.disable();
} else {
this.enable();
} }
} }
enable(): void { enable(): void {
if (this.enabled) {
return;
}
this.enabled = true; this.enabled = true;
this.run(); this.run();
} }
...@@ -114,9 +110,11 @@ export class AutoFetcher { ...@@ -114,9 +110,11 @@ export class AutoFetcher {
return; return;
} }
const timeout = new Promise(c => setTimeout(c, this.timeout)); const period = workspace.getConfiguration('git').get<number>('autofetchPeriod', 180) * 1000;
const onChanged = eventToPromise(filterEvent(this.onDidChange, () => true)); const timeout = new Promise(c => setTimeout(c, period));
await Promise.race([timeout, onChanged]); const whenDisabled = eventToPromise(filterEvent(this.onDidChange, enabled => !enabled));
await Promise.race([timeout, whenDisabled]);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册