mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-19 14:22:19 +01:00
Send machineId to main process (fixes #22169)
This commit is contained in:
@@ -99,13 +99,12 @@ export function _futureMachineIdExperiment(): string {
|
||||
|
||||
let machineId: TPromise<string>;
|
||||
export function getMachineId(): TPromise<string> {
|
||||
return machineId || (machineId = getStableMachineId()
|
||||
return machineId || (machineId = getMacMachineId()
|
||||
.then(id => id || uuid.generateUuid())); // fallback, generate a UUID
|
||||
}
|
||||
|
||||
let stableMachineId: TPromise<string>;
|
||||
export function getStableMachineId(): TPromise<string> {
|
||||
return stableMachineId || (stableMachineId = new TPromise<string>(resolve => {
|
||||
function getMacMachineId(): TPromise<string> {
|
||||
return new TPromise<string>(resolve => {
|
||||
try {
|
||||
getmac.getMac((error, macAddress) => {
|
||||
if (!error) {
|
||||
@@ -118,5 +117,5 @@ export function getStableMachineId(): TPromise<string> {
|
||||
errors.onUnexpectedError(err);
|
||||
resolve(undefined);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { ITelemetryAppenderChannel, TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
|
||||
import { TelemetryService, ITelemetryServiceConfig } from 'vs/platform/telemetry/common/telemetryService';
|
||||
import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
|
||||
import { resolveCommonProperties, machineIdStorageKey, machineIdIpcChannel } from 'vs/platform/telemetry/node/commonProperties';
|
||||
import { getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import product from 'vs/platform/node/product';
|
||||
import pkg from 'vs/platform/node/package';
|
||||
@@ -94,6 +94,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
|
||||
const environmentService = accessor.get(IEnvironmentService);
|
||||
const lifecycleService = accessor.get(ILifecycleService);
|
||||
const configurationService = accessor.get(IConfigurationService) as ConfigurationService<any>;
|
||||
const storageService = accessor.get(IStorageService);
|
||||
let windowsMainService: IWindowsMainService;
|
||||
|
||||
// We handle uncaught exceptions here to prevent electron from opening a dialog to the user
|
||||
@@ -118,6 +119,11 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
|
||||
}
|
||||
});
|
||||
|
||||
ipc.on(machineIdIpcChannel, (event, machineId: string) => {
|
||||
logService.log('IPC#vscode-machineId');
|
||||
storageService.setItem(machineIdStorageKey, machineId);
|
||||
});
|
||||
|
||||
logService.log('Starting VS Code in verbose mode');
|
||||
logService.log(`from: ${environmentService.appRoot}`);
|
||||
logService.log('args:', environmentService.args);
|
||||
@@ -159,7 +165,11 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
|
||||
if (environmentService.isBuilt && !environmentService.isExtensionDevelopment && !!product.enableTelemetry) {
|
||||
const channel = getDelayedChannel<ITelemetryAppenderChannel>(sharedProcessClient.then(c => c.getChannel('telemetryAppender')));
|
||||
const appender = new TelemetryAppenderClient(channel);
|
||||
const commonProperties = resolveCommonProperties(product.commit, pkg.version);
|
||||
const commonProperties = resolveCommonProperties(product.commit, pkg.version)
|
||||
.then(result => Object.defineProperty(result, 'common.machineId', {
|
||||
get: () => storageService.getItem(machineIdStorageKey),
|
||||
enumerable: true
|
||||
}));
|
||||
const piiPaths = [environmentService.appRoot, environmentService.extensionsPath];
|
||||
const config: ITelemetryServiceConfig = { appender, commonProperties, piiPaths };
|
||||
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, config));
|
||||
|
||||
@@ -7,7 +7,9 @@ import * as Platform from 'vs/base/common/platform';
|
||||
import * as os from 'os';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import * as uuid from 'vs/base/common/uuid';
|
||||
import { getStableMachineId } from 'vs/base/node/id';
|
||||
|
||||
export const machineIdStorageKey = 'telemetry.machineId';
|
||||
export const machineIdIpcChannel = 'vscode:machineId';
|
||||
|
||||
export function resolveCommonProperties(commit: string, version: string): TPromise<{ [name: string]: string; }> {
|
||||
const result: { [name: string]: string; } = Object.create(null);
|
||||
@@ -17,7 +19,6 @@ export function resolveCommonProperties(commit: string, version: string): TPromi
|
||||
result['version'] = version;
|
||||
result['common.osVersion'] = os.release();
|
||||
result['common.platform'] = Platform.Platform[Platform.platform];
|
||||
const promise = getStableMachineId().then(value => result['common.mainProcess.machineId'] = value);
|
||||
|
||||
// dynamic properties which value differs on each call
|
||||
let seq = 0;
|
||||
@@ -37,5 +38,5 @@ export function resolveCommonProperties(commit: string, version: string): TPromi
|
||||
}
|
||||
});
|
||||
|
||||
return promise.then(() => result);
|
||||
return TPromise.as(result);
|
||||
}
|
||||
@@ -10,7 +10,8 @@ import * as errors from 'vs/base/common/errors';
|
||||
import * as uuid from 'vs/base/common/uuid';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { getMachineId, virtualMachineHint } from 'vs/base/node/id';
|
||||
import { resolveCommonProperties } from '../node/commonProperties';
|
||||
import { resolveCommonProperties, machineIdStorageKey, machineIdIpcChannel } from '../node/commonProperties';
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
|
||||
const SQM_KEY: string = '\\Software\\Microsoft\\SQMClient';
|
||||
|
||||
@@ -50,15 +51,22 @@ function getOrCreateInstanceId(storageService: IStorageService): TPromise<string
|
||||
}
|
||||
|
||||
function getOrCreateMachineId(storageService: IStorageService): TPromise<string> {
|
||||
const key = 'telemetry.machineId';
|
||||
let result = storageService.get(key);
|
||||
return _getOrCreateMachineId(storageService)
|
||||
.then(value => {
|
||||
ipc.send(machineIdIpcChannel, value);
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
function _getOrCreateMachineId(storageService: IStorageService): TPromise<string> {
|
||||
let result = storageService.get(machineIdStorageKey);
|
||||
|
||||
if (result) {
|
||||
return TPromise.as(result);
|
||||
}
|
||||
|
||||
return getMachineId().then(result => {
|
||||
storageService.store(key, result);
|
||||
storageService.store(machineIdStorageKey, result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user