From 1d072c60afea274b082b0773f404e048e16c6c63 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sun, 15 Sep 2019 10:32:23 +0200 Subject: [PATCH] web - move surveys to browser --- .../languageSurveys.contribution.ts | 29 +++++++++++-------- .../nps.contribution.ts | 21 +++++++++----- src/vs/workbench/workbench.common.main.ts | 4 +++ src/vs/workbench/workbench.desktop.main.ts | 4 --- 4 files changed, 34 insertions(+), 24 deletions(-) rename src/vs/workbench/contrib/surveys/{electron-browser => browser}/languageSurveys.contribution.ts (87%) rename src/vs/workbench/contrib/surveys/{electron-browser => browser}/nps.contribution.ts (81%) diff --git a/src/vs/workbench/contrib/surveys/electron-browser/languageSurveys.contribution.ts b/src/vs/workbench/contrib/surveys/browser/languageSurveys.contribution.ts similarity index 87% rename from src/vs/workbench/contrib/surveys/electron-browser/languageSurveys.contribution.ts rename to src/vs/workbench/contrib/surveys/browser/languageSurveys.contribution.ts index c6ebcc56aa3..21ceff9b800 100644 --- a/src/vs/workbench/contrib/surveys/electron-browser/languageSurveys.contribution.ts +++ b/src/vs/workbench/contrib/surveys/browser/languageSurveys.contribution.ts @@ -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 { @@ -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`; @@ -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; } @@ -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); }); } }, { @@ -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 } @@ -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(WorkbenchExtensions.Workbench); workbenchRegistry.registerWorkbenchContribution(LanguageSurveysContribution, LifecyclePhase.Restored); } diff --git a/src/vs/workbench/contrib/surveys/electron-browser/nps.contribution.ts b/src/vs/workbench/contrib/surveys/browser/nps.contribution.ts similarity index 81% rename from src/vs/workbench/contrib/surveys/electron-browser/nps.contribution.ts rename to src/vs/workbench/contrib/surveys/browser/nps.contribution.ts index 5e4433ce2ad..baefeb799c1 100644 --- a/src/vs/workbench/contrib/surveys/electron-browser/nps.contribution.ts +++ b/src/vs/workbench/contrib/surveys/browser/nps.contribution.ts @@ -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'; @@ -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; @@ -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; } @@ -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); }); } }, { @@ -79,7 +84,7 @@ 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 } @@ -87,7 +92,7 @@ class NPSContribution implements IWorkbenchContribution { } } -if (language === 'en' && product.npsSurveyUrl) { +if (language === 'en') { const workbenchRegistry = Registry.as(WorkbenchExtensions.Workbench); workbenchRegistry.registerWorkbenchContribution(NPSContribution, LifecyclePhase.Restored); } diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index 4285b9a9b90..4af9d2cad50 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -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'; diff --git a/src/vs/workbench/workbench.desktop.main.ts b/src/vs/workbench/workbench.desktop.main.ts index 17ba99841f7..014864a31e8 100644 --- a/src/vs/workbench/workbench.desktop.main.ts +++ b/src/vs/workbench/workbench.desktop.main.ts @@ -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';