| // Copyright 2024 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // Manages information needed by analytics (e.g. UUID, OS and arch) |
| |
| import * as vscode from 'vscode'; |
| import * as os from 'os'; |
| import * as persistent_status from './persistent_status'; |
| |
| import { isInternalUser } from './internal'; |
| |
| export class AnalyticsInfo { |
| private static instanceInternal: AnalyticsInfo; |
| |
| private uuidInternal?: string; |
| private isRunInProductionModeInternal: boolean = false; |
| private extensionVersionInternal?: string; |
| private osInternal?: string; |
| private archInternal?: string; |
| private isInternalUserInternal: boolean = false; |
| |
| |
| /* Singleton */ |
| private constructor() { } |
| |
| private static get instance() { |
| if (!AnalyticsInfo.instanceInternal) { |
| AnalyticsInfo.instanceInternal = new AnalyticsInfo(); |
| } |
| |
| return AnalyticsInfo.instanceInternal; |
| } |
| |
| /* Exposed info */ |
| static get uuid() { |
| return AnalyticsInfo.instance.uuidInternal; |
| } |
| |
| static get isRunInProductionMode() { |
| return AnalyticsInfo.instance.isRunInProductionModeInternal; |
| } |
| |
| static get extensionVersion() { |
| return AnalyticsInfo.instance.extensionVersionInternal; |
| } |
| |
| static get os() { |
| return AnalyticsInfo.instance.osInternal; |
| } |
| |
| static get arch() { |
| return AnalyticsInfo.instance.archInternal; |
| } |
| |
| static get isInternalUser() { |
| return AnalyticsInfo.instance.isInternalUserInternal; |
| } |
| |
| static async init(context: vscode.ExtensionContext): Promise<void> { |
| await AnalyticsInfo.instance.initInternal(context); |
| } |
| |
| private initInternal(context: vscode.ExtensionContext): void { |
| const packageJson = context.extension.packageJSON; |
| this.extensionVersionInternal = packageJson.version; |
| this.osInternal = os.type(); |
| this.archInternal = os.machine(); |
| this.isRunInProductionModeInternal = |
| (context.extensionMode === vscode.ExtensionMode.Production); |
| this.isInternalUserInternal = isInternalUser(); |
| } |
| |
| static async readUuid(): Promise<void> { |
| AnalyticsInfo.instance.uuidInternal = await persistent_status.getUuid(); |
| } |
| } |