Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/externalServices/common/serviceMachineId.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { VSBuffer } from '../../../base/common/buffer.js';
7
import { generateUuid, isUUID } from '../../../base/common/uuid.js';
8
import { IEnvironmentService } from '../../environment/common/environment.js';
9
import { IFileService } from '../../files/common/files.js';
10
import { IStorageService, StorageScope, StorageTarget } from '../../storage/common/storage.js';
11
12
export async function getServiceMachineId(environmentService: IEnvironmentService, fileService: IFileService, storageService: IStorageService | undefined): Promise<string> {
13
let uuid: string | null = storageService ? storageService.get('storage.serviceMachineId', StorageScope.APPLICATION) || null : null;
14
if (uuid) {
15
return uuid;
16
}
17
try {
18
const contents = await fileService.readFile(environmentService.serviceMachineIdResource);
19
const value = contents.value.toString();
20
uuid = isUUID(value) ? value : null;
21
} catch (e) {
22
uuid = null;
23
}
24
25
if (!uuid) {
26
uuid = generateUuid();
27
try {
28
await fileService.writeFile(environmentService.serviceMachineIdResource, VSBuffer.fromString(uuid));
29
} catch (error) {
30
//noop
31
}
32
}
33
34
storageService?.store('storage.serviceMachineId', uuid, StorageScope.APPLICATION, StorageTarget.MACHINE);
35
36
return uuid;
37
}
38
39