Skip to content

Commit

Permalink
web - move surveys to browser
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 16, 2019
1 parent e81ee53 commit 1d072c6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
Expand Up @@ -10,14 +10,13 @@ import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions as
import { Registry } from 'vs/platform/registry/common/platform';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import pkg from 'vs/platform/product/node/package';
import product from 'vs/platform/product/node/product';
import { ISurveyData } from 'vs/platform/product/common/product';
import { ISurveyData, IProductService } from 'vs/platform/product/common/product';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Severity, INotificationService } from 'vs/platform/notification/common/notification';
import { ITextFileService, StateChange } from 'vs/workbench/services/textfile/common/textfiles';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { URI } from 'vs/base/common/uri';
import { platform } from 'vs/base/common/process';

class LanguageSurvey {

Expand All @@ -28,7 +27,8 @@ class LanguageSurvey {
telemetryService: ITelemetryService,
modelService: IModelService,
textFileService: ITextFileService,
openerService: IOpenerService
openerService: IOpenerService,
productService: IProductService
) {
const SESSION_COUNT_KEY = `${data.surveyId}.sessionCount`;
const LAST_SESSION_DATE_KEY = `${data.surveyId}.lastSessionDate`;
Expand Down Expand Up @@ -82,7 +82,7 @@ class LanguageSurvey {
storageService.store(IS_CANDIDATE_KEY, isCandidate, StorageScope.GLOBAL);

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

Expand All @@ -97,9 +97,9 @@ class LanguageSurvey {
run: () => {
telemetryService.publicLog(`${data.surveyId}.survey/takeShortSurvey`);
telemetryService.getTelemetryInfo().then(info => {
openerService.open(URI.parse(`${data.surveyUrl}?o=${encodeURIComponent(process.platform)}&v=${encodeURIComponent(pkg.version)}&m=${encodeURIComponent(info.machineId)}`));
openerService.open(URI.parse(`${data.surveyUrl}?o=${encodeURIComponent(platform)}&v=${encodeURIComponent(productService.version)}&m=${encodeURIComponent(info.machineId)}`));
storageService.store(IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, productService.version, StorageScope.GLOBAL);
});
}
}, {
Expand All @@ -114,7 +114,7 @@ class LanguageSurvey {
run: () => {
telemetryService.publicLog(`${data.surveyId}.survey/dontShowAgain`);
storageService.store(IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, productService.version, StorageScope.GLOBAL);
}
}],
{ sticky: true }
Expand All @@ -130,15 +130,20 @@ class LanguageSurveysContribution implements IWorkbenchContribution {
@ITelemetryService telemetryService: ITelemetryService,
@IModelService modelService: IModelService,
@ITextFileService textFileService: ITextFileService,
@IOpenerService openerService: IOpenerService
@IOpenerService openerService: IOpenerService,
@IProductService productService: IProductService
) {
product.surveys!
if (!productService.surveys) {
return;
}

productService.surveys
.filter(surveyData => surveyData.surveyId && surveyData.editCount && surveyData.languageId && surveyData.surveyUrl && surveyData.userProbability)
.map(surveyData => new LanguageSurvey(surveyData, storageService, notificationService, telemetryService, modelService, textFileService, openerService));
.map(surveyData => new LanguageSurvey(surveyData, storageService, notificationService, telemetryService, modelService, textFileService, openerService, productService));
}
}

if (language === 'en' && product.surveys && product.surveys.length) {
if (language === 'en') {
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(LanguageSurveysContribution, LifecyclePhase.Restored);
}
Expand Up @@ -9,12 +9,12 @@ import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions as
import { Registry } from 'vs/platform/registry/common/platform';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import pkg from 'vs/platform/product/node/package';
import product from 'vs/platform/product/node/product';
import { IProductService } from 'vs/platform/product/common/product';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Severity, INotificationService } from 'vs/platform/notification/common/notification';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { URI } from 'vs/base/common/uri';
import { platform } from 'vs/base/common/process';

const PROBABILITY = 0.15;
const SESSION_COUNT_KEY = 'nps/sessionCount';
Expand All @@ -28,8 +28,13 @@ class NPSContribution implements IWorkbenchContribution {
@IStorageService storageService: IStorageService,
@INotificationService notificationService: INotificationService,
@ITelemetryService telemetryService: ITelemetryService,
@IOpenerService openerService: IOpenerService
@IOpenerService openerService: IOpenerService,
@IProductService productService: IProductService
) {
if (!productService.npsSurveyUrl) {
return;
}

const skipVersion = storageService.get(SKIP_VERSION_KEY, StorageScope.GLOBAL, '');
if (skipVersion) {
return;
Expand All @@ -56,7 +61,7 @@ class NPSContribution implements IWorkbenchContribution {
storageService.store(IS_CANDIDATE_KEY, isCandidate, StorageScope.GLOBAL);

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

Expand All @@ -67,9 +72,9 @@ class NPSContribution implements IWorkbenchContribution {
label: nls.localize('takeSurvey', "Take Survey"),
run: () => {
telemetryService.getTelemetryInfo().then(info => {
openerService.open(URI.parse(`${product.npsSurveyUrl}?o=${encodeURIComponent(process.platform)}&v=${encodeURIComponent(pkg.version)}&m=${encodeURIComponent(info.machineId)}`));
openerService.open(URI.parse(`${productService.npsSurveyUrl}?o=${encodeURIComponent(platform)}&v=${encodeURIComponent(productService.version)}&m=${encodeURIComponent(info.machineId)}`));
storageService.store(IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, productService.version, StorageScope.GLOBAL);
});
}
}, {
Expand All @@ -79,15 +84,15 @@ class NPSContribution implements IWorkbenchContribution {
label: nls.localize('neverAgain', "Don't Show Again"),
run: () => {
storageService.store(IS_CANDIDATE_KEY, false, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, pkg.version, StorageScope.GLOBAL);
storageService.store(SKIP_VERSION_KEY, productService.version, StorageScope.GLOBAL);
}
}],
{ sticky: true }
);
}
}

if (language === 'en' && product.npsSurveyUrl) {
if (language === 'en') {
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(NPSContribution, LifecyclePhase.Restored);
}
4 changes: 4 additions & 0 deletions src/vs/workbench/workbench.common.main.ts
Expand Up @@ -229,6 +229,10 @@ import 'vs/workbench/contrib/update/browser/update.contribution';
// Watermark
import 'vs/workbench/contrib/watermark/browser/watermark';

// Surveys
import 'vs/workbench/contrib/surveys/browser/nps.contribution';
import 'vs/workbench/contrib/surveys/browser/languageSurveys.contribution';

// Welcome
import 'vs/workbench/contrib/welcome/overlay/browser/welcomeOverlay';
import 'vs/workbench/contrib/welcome/page/browser/welcomePage.contribution';
Expand Down
4 changes: 0 additions & 4 deletions src/vs/workbench/workbench.desktop.main.ts
Expand Up @@ -121,10 +121,6 @@ import 'vs/workbench/contrib/externalTerminal/node/externalTerminalService';
// Update
import 'vs/workbench/contrib/update/electron-browser/update.contribution';

// Surveys
import 'vs/workbench/contrib/surveys/electron-browser/nps.contribution';
import 'vs/workbench/contrib/surveys/electron-browser/languageSurveys.contribution';

// Performance
import 'vs/workbench/contrib/performance/electron-browser/performance.contribution';

Expand Down

0 comments on commit 1d072c6

Please sign in to comment.