Skip to content

Commit

Permalink
wip: NPS
Browse files Browse the repository at this point in the history
related to #9686
  • Loading branch information
joaomoreno committed Jul 25, 2016
1 parent 182698e commit 5bcde31
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface IProductConfiguration {
reportIssueUrl: string;
licenseUrl: string;
privacyStatementUrl: string;
npsSurveyUrl: string;
}

const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
Expand Down
96 changes: 96 additions & 0 deletions src/vs/workbench/electron-browser/nps.contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import * as nls from 'vs/nls';
import * as semver from 'semver';
import { shell } from 'electron';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/platform';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import pkg from 'vs/platform/package';
import product from 'vs/platform/product';

class NPSContribution implements IWorkbenchContribution {

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';

constructor(
@IInstantiationService instantiationService: IInstantiationService,
@IStorageService storageService: IStorageService,
@IMessageService messageService: IMessageService
) {
const skipVersion = storageService.get(NPSContribution.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());

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);

if (sessionCount < 9) {
return;
}

const isCandidate = storageService.getBoolean(NPSContribution.IS_CANDIDATE_KEY, StorageScope.GLOBAL, false)
|| Math.random() < NPSContribution.PROBABILITY;

storageService.store(NPSContribution.IS_CANDIDATE_KEY, true, StorageScope.GLOBAL);

if (!isCandidate) {
storageService.store(NPSContribution.SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
return;
}

const message = nls.localize('surveyQuestion', "Do you mind taking a quick feedback survey?");

const takeSurveyAction = new Action('nps.takeSurvey', nls.localize('takeSurvey', "Take Survey"), '', true, () => {
shell.openExternal(product.npsSurveyUrl);
storageService.store(NPSContribution.SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
return TPromise.as(null);
});

const remindMeLaterAction = new Action('nps.later', nls.localize('remindLater', "Remind Me later"), '', true, () => {
storageService.store(NPSContribution.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);
return TPromise.as(null);
});

const actions = [takeSurveyAction, remindMeLaterAction, neverAgainAction];
messageService.show(Severity.Info, { message, actions });
}

getId(): string {
return 'nps';
}
}

if (product.npsSurveyUrl) {
const workbenchRegistry = <IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(NPSContribution);
}
1 change: 1 addition & 0 deletions src/vs/workbench/workbench.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import 'vs/workbench/parts/welcome/electron-browser/electronGettingStarted.contr
import 'vs/workbench/parts/update/electron-browser/update.contribution';

import 'vs/workbench/electron-browser/darwin/cli.contribution';
import 'vs/workbench/electron-browser/nps.contribution';

import 'vs/workbench/api/node/extHost.contribution';

Expand Down

0 comments on commit 5bcde31

Please sign in to comment.