forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownloadChannelRules.ts
More file actions
45 lines (38 loc) · 1.79 KB
/
Copy pathdownloadChannelRules.ts
File metadata and controls
45 lines (38 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { IPersistentStateFactory } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { FolderVersionPair, IDownloadChannelRule } from './types';
const lastCheckedForLSDateTimeCacheKey = 'LS.LAST.CHECK.TIME';
const frequencyForBetalLSDownloadCheck = 1000 * 60 * 60 * 24; // One day.
@injectable()
export class DownloadDailyChannelRule implements IDownloadChannelRule {
public async shouldLookForNewLanguageServer(currentFolder?: FolderVersionPair): Promise<boolean> {
return true;
}
}
@injectable()
export class DownloadStableChannelRule implements IDownloadChannelRule {
public async shouldLookForNewLanguageServer(currentFolder?: FolderVersionPair): Promise<boolean> {
return currentFolder ? false : true;
}
}
@injectable()
export class DownloadBetaChannelRule implements IDownloadChannelRule {
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) { }
public async shouldLookForNewLanguageServer(currentFolder?: FolderVersionPair): Promise<boolean> {
// For beta, we do this only once a day.
const stateFactory = this.serviceContainer.get<IPersistentStateFactory>(IPersistentStateFactory);
const globalState = stateFactory.createGlobalPersistentState<boolean>(lastCheckedForLSDateTimeCacheKey,
true,
frequencyForBetalLSDownloadCheck);
// If we haven't checked it in the last 24 hours, then ensure we don't do it again.
if (globalState.value) {
await globalState.updateValue(false);
return true;
}
return !currentFolder || globalState.value;
}
}