mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 16:58:55 -05:00
Allow machne id generation in main process (#167449)
This commit is contained in:
@@ -20,7 +20,6 @@ import { IProcessEnvironment, isLinux, isLinuxSnap, isMacintosh, isWindows, OS }
|
||||
import { assertType } from 'vs/base/common/types';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { getMachineId } from 'vs/base/node/id';
|
||||
import { registerContextMenuListener } from 'vs/base/parts/contextmenu/electron-main/contextmenu';
|
||||
import { getDelayedChannel, ProxyChannel, StaticRouter } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { Server as ElectronIPCServer } from 'vs/base/parts/ipc/electron-main/ipc.electron';
|
||||
@@ -71,7 +70,7 @@ import { IStateMainService } from 'vs/platform/state/electron-main/state';
|
||||
import { StorageDatabaseChannel } from 'vs/platform/storage/electron-main/storageIpc';
|
||||
import { ApplicationStorageMainService, IApplicationStorageMainService, IStorageMainService, StorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
|
||||
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
|
||||
import { ITelemetryService, machineIdKey, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
|
||||
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
|
||||
import { getPiiPathsFromEnvironment, getTelemetryLevel, isInternalTelemetry, NullTelemetryService, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
@@ -109,6 +108,7 @@ import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/e
|
||||
import { UserDataTransientProfilesHandler } from 'vs/platform/userDataProfile/electron-main/userDataTransientProfilesHandler';
|
||||
import { ProfileStorageChangesListenerChannel } from 'vs/platform/userDataProfile/electron-main/userDataProfileStorageIpc';
|
||||
import { Promises, RunOnceScheduler, runWhenIdle } from 'vs/base/common/async';
|
||||
import { resolveMachineId } from 'vs/platform/telemetry/electron-main/telemetryUtils';
|
||||
|
||||
/**
|
||||
* The main VS Code application. There will only ever be one instance,
|
||||
@@ -524,7 +524,7 @@ export class CodeApplication extends Disposable {
|
||||
|
||||
// Resolve unique machine ID
|
||||
this.logService.trace('Resolving machine identifier...');
|
||||
const machineId = await this.resolveMachineId();
|
||||
const machineId = await resolveMachineId(this.stateMainService);
|
||||
this.logService.trace(`Resolved machine identifier: ${machineId}`);
|
||||
|
||||
// Shared process
|
||||
@@ -561,20 +561,6 @@ export class CodeApplication extends Disposable {
|
||||
this._register(instantiationService.createInstance(UserDataTransientProfilesHandler));
|
||||
}
|
||||
|
||||
private async resolveMachineId(): Promise<string> {
|
||||
|
||||
// We cache the machineId for faster lookups on startup
|
||||
// and resolve it only once initially if not cached or we need to replace the macOS iBridge device
|
||||
let machineId = this.stateMainService.getItem<string>(machineIdKey);
|
||||
if (!machineId || (isMacintosh && machineId === '6c9d2bc8f91b89624add29c0abeae7fb42bf539fa1cdb2e3e57cd668fa9bcead')) {
|
||||
machineId = await getMachineId();
|
||||
|
||||
this.stateMainService.setItem(machineIdKey, machineId);
|
||||
}
|
||||
|
||||
return machineId;
|
||||
}
|
||||
|
||||
private setupSharedProcess(machineId: string): { sharedProcess: SharedProcess; sharedProcessReady: Promise<MessagePortClient>; sharedProcessClient: Promise<MessagePortClient> } {
|
||||
const sharedProcess = this._register(this.mainInstantiationService.createInstance(SharedProcess, machineId, this.userEnv));
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ import { RequestService } from 'vs/platform/request/node/requestService';
|
||||
import { IStateService } from 'vs/platform/state/node/state';
|
||||
import { StateService } from 'vs/platform/state/node/stateService';
|
||||
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
|
||||
import { ITelemetryService, machineIdKey } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
|
||||
import { supportsTelemetry, NullTelemetryService, getPiiPathsFromEnvironment, isInternalTelemetry, ITelemetryAppender } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
|
||||
@@ -60,6 +60,7 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
|
||||
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
|
||||
import { IUserDataProfilesService, PROFILES_ENABLEMENT_CONFIG } from 'vs/platform/userDataProfile/common/userDataProfile';
|
||||
import { UserDataProfilesService } from 'vs/platform/userDataProfile/node/userDataProfile';
|
||||
import { resolveMachineId } from 'vs/platform/telemetry/node/telemetryUtils';
|
||||
|
||||
class CliMain extends Disposable {
|
||||
|
||||
@@ -205,8 +206,7 @@ class CliMain extends Disposable {
|
||||
commonProperties: (async () => {
|
||||
let machineId: string | undefined = undefined;
|
||||
try {
|
||||
const storageContents = await Promises.readFile(environmentService.stateResource.fsPath);
|
||||
machineId = JSON.parse(storageContents.toString())[machineIdKey];
|
||||
machineId = await resolveMachineId(stateService);
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
logService.error(error);
|
||||
|
||||
15
src/vs/platform/telemetry/electron-main/telemetryUtils.ts
Normal file
15
src/vs/platform/telemetry/electron-main/telemetryUtils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IStateMainService } from 'vs/platform/state/electron-main/state';
|
||||
import { machineIdKey } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { resolveMachineId as resolveNodeMachineId } from 'vs/platform/telemetry/node/telemetryUtils';
|
||||
|
||||
export async function resolveMachineId(stateService: IStateMainService) {
|
||||
// Call the node layers implementation to avoid code duplication
|
||||
const machineId = resolveNodeMachineId(stateService);
|
||||
stateService.setItem(machineIdKey, machineId);
|
||||
return machineId;
|
||||
}
|
||||
21
src/vs/platform/telemetry/node/telemetryUtils.ts
Normal file
21
src/vs/platform/telemetry/node/telemetryUtils.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { isMacintosh } from 'vs/base/common/platform';
|
||||
import { getMachineId } from 'vs/base/node/id';
|
||||
import { IStateService } from 'vs/platform/state/node/state';
|
||||
import { machineIdKey } from 'vs/platform/telemetry/common/telemetry';
|
||||
|
||||
|
||||
export async function resolveMachineId(stateService: IStateService) {
|
||||
// We cache the machineId for faster lookups
|
||||
// and resolve it only once initially if not cached or we need to replace the macOS iBridge device
|
||||
let machineId = stateService.getItem<string>(machineIdKey);
|
||||
if (!machineId || (isMacintosh && machineId === '6c9d2bc8f91b89624add29c0abeae7fb42bf539fa1cdb2e3e57cd668fa9bcead')) {
|
||||
machineId = await getMachineId();
|
||||
}
|
||||
|
||||
return machineId;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { IProtocolMainService } from 'vs/platform/protocol/electron-main/protocol';
|
||||
import { resolveMarketplaceHeaders } from 'vs/platform/externalServices/common/marketplace';
|
||||
import { IApplicationStorageMainService, IStorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
|
||||
import { ITelemetryService, machineIdKey } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
|
||||
import { IThemeMainService } from 'vs/platform/theme/electron-main/themeMainService';
|
||||
import { getMenuBarVisibility, getTitleBarStyle, IFolderToOpen, INativeWindowConfiguration, IWindowSettings, IWorkspaceToOpen, MenuBarVisibility, useWindowControlsOverlay, WindowMinimumSize, zoomLevelToZoomFactor } from 'vs/platform/window/common/window';
|
||||
@@ -49,6 +49,7 @@ import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry
|
||||
import { getPiiPathsFromEnvironment, isInternalTelemetry, ITelemetryAppender, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
|
||||
import { hostname, release } from 'os';
|
||||
import { resolveMachineId } from 'vs/platform/telemetry/electron-main/telemetryUtils';
|
||||
|
||||
export interface IWindowCreationOptions {
|
||||
state: IWindowState;
|
||||
@@ -782,11 +783,12 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
}
|
||||
|
||||
const { installSourcePath } = this.environmentMainService;
|
||||
const machineId = await resolveMachineId(this.stateMainService);
|
||||
|
||||
const config: ITelemetryServiceConfig = {
|
||||
appenders,
|
||||
sendErrorTelemetry: false,
|
||||
commonProperties: resolveCommonProperties(this.fileService, release(), hostname(), process.arch, this.productService.commit, this.productService.version, this.stateMainService.getItem<string>(machineIdKey), isInternal, installSourcePath),
|
||||
commonProperties: resolveCommonProperties(this.fileService, release(), hostname(), process.arch, this.productService.commit, this.productService.version, machineId, isInternal, installSourcePath),
|
||||
piiPaths: getPiiPathsFromEnvironment(this.environmentMainService)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user