This commit is contained in:
Joao Moreno 2016-07-25 14:07:31 +02:00
parent 74af3ff7b4
commit b3ace48664

View file

@ -19,13 +19,13 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import pkg from 'vs/platform/package';
import product from 'vs/platform/product';
class NPSContribution implements IWorkbenchContribution {
const PROBABILITY = 0.15;
const SESSION_COUNT_KEY = 'nps/sessionCount';
const LAST_SESSION_DATE_KEY = 'nps/lastSessionDate';
const SKIP_VERSION_KEY = 'nps/skipVersion';
const IS_CANDIDATE_KEY = 'nps/isCandidate';
private static PROBABILITY = 0.15;
private static SESSION_COUNT_KEY = 'nps/sessionCount';
private static LAST_SESSION_DATE_KEY = 'nps/lastSessionDate';
private static SKIP_VERSION_KEY = 'nps/skipVersion';
private static IS_CANDIDATE_KEY = 'nps/isCandidate';
class NPSContribution implements IWorkbenchContribution {
constructor(
@IInstantiationService instantiationService: IInstantiationService,
@ -33,35 +33,34 @@ class NPSContribution implements IWorkbenchContribution {
@IMessageService messageService: IMessageService,
@ITelemetryService telemetryService: ITelemetryService
) {
const skipVersion = storageService.get(NPSContribution.SKIP_VERSION_KEY, StorageScope.GLOBAL, '0.0.0');
const skipVersion = storageService.get(SKIP_VERSION_KEY, StorageScope.GLOBAL, '0.0.0');
if (semver.gte(pkg.version, skipVersion)) {
storageService.store(NPSContribution.IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
return;
}
const date = new Date().toDateString();
const lastSessionDate = storageService.get(NPSContribution.LAST_SESSION_DATE_KEY, StorageScope.GLOBAL, new Date(0).toDateString());
const lastSessionDate = storageService.get(LAST_SESSION_DATE_KEY, StorageScope.GLOBAL, new Date(0).toDateString());
if (date === lastSessionDate) {
return;
}
const sessionCount = storageService.getInteger(NPSContribution.SESSION_COUNT_KEY, StorageScope.GLOBAL, 0) + 1;
storageService.store(NPSContribution.LAST_SESSION_DATE_KEY, date, StorageScope.GLOBAL);
storageService.store(NPSContribution.SESSION_COUNT_KEY, sessionCount, StorageScope.GLOBAL);
const sessionCount = storageService.getInteger(SESSION_COUNT_KEY, StorageScope.GLOBAL, 0) + 1;
storageService.store(LAST_SESSION_DATE_KEY, date, StorageScope.GLOBAL);
storageService.store(SESSION_COUNT_KEY, sessionCount, StorageScope.GLOBAL);
if (sessionCount < 9) {
return;
}
const isCandidate = storageService.getBoolean(NPSContribution.IS_CANDIDATE_KEY, StorageScope.GLOBAL, false)
|| Math.random() < NPSContribution.PROBABILITY;
const isCandidate = storageService.getBoolean(IS_CANDIDATE_KEY, StorageScope.GLOBAL, false)
|| Math.random() < PROBABILITY;
storageService.store(NPSContribution.IS_CANDIDATE_KEY, true, StorageScope.GLOBAL);
storageService.store(IS_CANDIDATE_KEY, isCandidate, StorageScope.GLOBAL);
if (!isCandidate) {
storageService.store(NPSContribution.SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
return;
}
@ -70,17 +69,19 @@ class NPSContribution implements IWorkbenchContribution {
const takeSurveyAction = new Action('nps.takeSurvey', nls.localize('takeSurvey', "Take Survey"), '', true, () => {
return telemetryService.getTelemetryInfo().then(info => {
shell.openExternal(`${ product.npsSurveyUrl }?o=${ encodeURIComponent(process.platform) }&v=${ encodeURIComponent(pkg.version) }&m=${ encodeURIComponent(info.machineId) }`);
storageService.store(NPSContribution.SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
});
});
const remindMeLaterAction = new Action('nps.later', nls.localize('remindLater', "Remind Me later"), '', true, () => {
storageService.store(NPSContribution.SESSION_COUNT_KEY, sessionCount - 3, StorageScope.GLOBAL);
storageService.store(SESSION_COUNT_KEY, sessionCount - 3, StorageScope.GLOBAL);
return TPromise.as(null);
});
const neverAgainAction = new Action('nps.never', nls.localize('neverAgain', "Never Show Again"), '', true, () => {
storageService.store(NPSContribution.SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
return TPromise.as(null);
});