diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index 8b1a745eb63..962080a3528 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -169,6 +169,7 @@ export interface IWindowService { onDidChangeFocus: Event; + getConfiguration(): IWindowConfiguration; getCurrentWindowId(): number; pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise; pickFileAndOpen(options: INativeOpenDialogOptions): TPromise; diff --git a/src/vs/platform/windows/electron-browser/windowService.ts b/src/vs/platform/windows/electron-browser/windowService.ts index 32f28c1fde9..ded9d8f8a9a 100644 --- a/src/vs/platform/windows/electron-browser/windowService.ts +++ b/src/vs/platform/windows/electron-browser/windowService.ts @@ -7,7 +7,7 @@ import Event, { filterEvent, mapEvent, anyEvent } from 'vs/base/common/event'; import { TPromise } from 'vs/base/common/winjs.base'; -import { IWindowService, IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult } from 'vs/platform/windows/common/windows'; +import { IWindowService, IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration } from 'vs/platform/windows/common/windows'; import { remote } from 'electron'; import { IRecentlyOpened } from 'vs/platform/history/common/history'; import { ICommandAction } from 'vs/platform/actions/common/actions'; @@ -23,6 +23,7 @@ export class WindowService implements IWindowService { constructor( private windowId: number, + private configuration: IWindowConfiguration, @IWindowsService private windowsService: IWindowsService ) { const onThisWindowFocus = mapEvent(filterEvent(windowsService.onWindowFocus, id => id === windowId), _ => true); @@ -34,6 +35,10 @@ export class WindowService implements IWindowService { return this.windowId; } + getConfiguration(): IWindowConfiguration { + return this.configuration; + } + pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise { options.windowId = this.windowId; diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index a999993a3cc..1a23414798d 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -30,7 +30,6 @@ import ErrorTelemetry from 'vs/platform/telemetry/browser/errorTelemetry'; import { ElectronWindow } from 'vs/workbench/electron-browser/window'; import { resolveWorkbenchCommonProperties, getOrCreateMachineId } from 'vs/platform/telemetry/node/workbenchCommonProperties'; import { machineIdIpcChannel } from 'vs/platform/telemetry/node/commonProperties'; -import { WorkspaceStats } from 'vs/workbench/services/telemetry/node/workspaceStats'; import { IWindowsService, IWindowService, IWindowConfiguration } from 'vs/platform/windows/common/windows'; import { WindowService } from 'vs/platform/windows/electron-browser/windowService'; import { MessageService } from 'vs/workbench/services/message/electron-browser/messageService'; @@ -249,11 +248,6 @@ export class WorkbenchShell { this.telemetryService.publicLog('startupTime', this.timerService.startupMetrics); }); - // Telemetry: workspace tags - const workspaceStats: WorkspaceStats = this.workbench.getInstantiationService().createInstance(WorkspaceStats); - workspaceStats.reportWorkspaceTags(this.configuration); - workspaceStats.reportCloudStats(); - // Root Warning if ((platform.isLinux || platform.isMacintosh) && process.getuid() === 0) { this.messageService.show(Severity.Warning, nls.localize('runningAsRoot', "It is recommended not to run Code as 'root'.")); @@ -285,7 +279,7 @@ export class WorkbenchShell { this.broadcastService = new BroadcastService(currentWindow.id); serviceCollection.set(IBroadcastService, this.broadcastService); - serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, currentWindow.id)); + serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, currentWindow.id, this.configuration)); const sharedProcess = (serviceCollection.get(IWindowsService)).whenSharedProcessReady() .then(() => connectNet(this.environmentService.sharedIPCHandle, `window:${currentWindow.id}`)); diff --git a/src/vs/workbench/parts/stats/node/stats.contribution.ts b/src/vs/workbench/parts/stats/node/stats.contribution.ts new file mode 100644 index 00000000000..973f0a65d56 --- /dev/null +++ b/src/vs/workbench/parts/stats/node/stats.contribution.ts @@ -0,0 +1,14 @@ +/*--------------------------------------------------------------------------------------------- + * 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 { Registry } from 'vs/platform/registry/common/platform'; +import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; +import { WorkspaceStatsReporter } from 'vs/workbench/parts/stats/node/workspaceStats'; +import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; + +// Register Workspace Stats Contribution +Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(WorkspaceStatsReporter, LifecyclePhase.Running); \ No newline at end of file diff --git a/src/vs/workbench/services/telemetry/node/workspaceStats.ts b/src/vs/workbench/parts/stats/node/workspaceStats.ts similarity index 94% rename from src/vs/workbench/services/telemetry/node/workspaceStats.ts rename to src/vs/workbench/parts/stats/node/workspaceStats.ts index 8c122d88bdb..d77c076250b 100644 --- a/src/vs/workbench/services/telemetry/node/workspaceStats.ts +++ b/src/vs/workbench/parts/stats/node/workspaceStats.ts @@ -13,7 +13,9 @@ import { IFileService, IFileStat } from 'vs/platform/files/common/files'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { IWindowConfiguration } from 'vs/platform/windows/common/windows'; +import { IWindowConfiguration, IWindowService } from 'vs/platform/windows/common/windows'; +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/; const SshUrlMatcher = /^([^@:]+@)?([^:]+):(.+)$/; @@ -131,7 +133,7 @@ export function getHashedRemotes(text: string): string[] { }); } -export class WorkspaceStats { +class WorkspaceStats { constructor( @IFileService private fileService: IFileService, @IWorkspaceContextService private contextService: IWorkspaceContextService, @@ -414,3 +416,24 @@ export class WorkspaceStats { } } } + +// Telemetry: workspace tags +export class WorkspaceStatsReporter implements IWorkbenchContribution { + + constructor( + @IInstantiationService private instantiationService: IInstantiationService, + @IWindowService private windowService: IWindowService + ) { + this.reportWorkspaceStats(); + } + + public getId(): string { + return 'vs.backup.backupModelTracker'; + } + + private reportWorkspaceStats(): void { + const workspaceStats: WorkspaceStats = this.instantiationService.createInstance(WorkspaceStats); + workspaceStats.reportWorkspaceTags(this.windowService.getConfiguration()); + workspaceStats.reportCloudStats(); + } +} \ No newline at end of file diff --git a/src/vs/workbench/services/telemetry/test/workspaceStats.test.ts b/src/vs/workbench/parts/stats/test/workspaceStats.test.ts similarity index 99% rename from src/vs/workbench/services/telemetry/test/workspaceStats.test.ts rename to src/vs/workbench/parts/stats/test/workspaceStats.test.ts index 7bb6e7d3d8f..3c2b03c1434 100644 --- a/src/vs/workbench/services/telemetry/test/workspaceStats.test.ts +++ b/src/vs/workbench/parts/stats/test/workspaceStats.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import * as crypto from 'crypto'; -import { getDomainsOfRemotes, getRemotes, getHashedRemotes } from 'vs/workbench/services/telemetry/node/workspaceStats'; +import { getDomainsOfRemotes, getRemotes, getHashedRemotes } from 'vs/workbench/parts/stats/node/workspaceStats'; function hash(value: string): string { return crypto.createHash('sha1').update(value.toString()).digest('hex'); diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 92fef733058..b9035fdf152 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -46,7 +46,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; -import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult } from 'vs/platform/windows/common/windows'; +import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration } from 'vs/platform/windows/common/windows'; import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; @@ -890,6 +890,10 @@ export class TestWindowService implements IWindowService { return TPromise.as(false); } + getConfiguration(): IWindowConfiguration { + return Object.create(null); + } + getCurrentWindowId(): number { return 0; } diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index bfd4680bc86..91c1568b216 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -42,6 +42,8 @@ import 'vs/workbench/parts/files/browser/files.contribution'; import 'vs/workbench/parts/backup/common/backup.contribution'; +import 'vs/workbench/parts/stats/node/stats.contribution'; + import 'vs/workbench/parts/search/browser/search.contribution'; import 'vs/workbench/parts/search/browser/searchViewlet'; // can be packaged separately import 'vs/workbench/parts/search/browser/openAnythingHandler'; // can be packaged separately diff --git a/tslint.json b/tslint.json index 3a591068174..23e3b8f5899 100644 --- a/tslint.json +++ b/tslint.json @@ -421,7 +421,7 @@ }, { "target": "{**/**.test.ts,**/test/**}", - "restrictions": "{**/vs/**,assert,sinon}" + "restrictions": "{**/vs/**,assert,sinon,crypto}" }, { "target": "**/{common,browser,workbench}/**",