'use strict' ; import * as vscode from 'vscode' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { LogType } from 'ibm-blockchain-platform-common' ; export class ExtensionData { public activationCount : number ; public version : string ; public migrationCheck : number ; public generatorVersion : string ; public preReqPageShown : boolean ; public dockerForWindows : boolean ; public createOneOrgLocalFabric : boolean ; public deletedOneOrgLocalFabric : boolean ; public shownFirstSubmissionSurveyURL : boolean ; } export const EXTENSION_DATA_KEY = 'ibm-blockchain-platform-extension-data' ; export const DEFAULT_EXTENSION_DATA = { activationCount : 0 , version : null , migrationCheck : 0 , generatorVersion : null , preReqPageShown : false , dockerForWindows : false , createOneOrgLocalFabric : true , deletedOneOrgLocalFabric : false , shownFirstSubmissionSurveyURL : false } ; export class GlobalState { public static context : vscode . ExtensionContext ; public static getExtensionContext ( ) { return GlobalState . context ; } public static setExtensionContext ( context ) { GlobalState . context = context ; } public static get ( ) { try { const extensionData = GlobalState . context . globalState . get < ExtensionData > ( EXTENSION_DATA_KEY , DEFAULT_EXTENSION_DATA ) ; return extensionData ; } catch ( error ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . ERROR , `Unable to get extension's global state: ${ error . message }` , `Unable to get extension's global state: ${ error . toString ( ) }` ) ; throw error ; } } public static async update ( extensionData ) { try { await GlobalState . context . globalState . update ( EXTENSION_DATA_KEY , extensionData ) ; } catch ( error ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . ERROR , `Unable to update extension's global state: ${ error . message }` , `Unable to update extension's global state: ${ error . toString ( ) }` ) ; throw error ; } } public static async reset ( ) { await this . update ( DEFAULT_EXTENSION_DATA ) ; } }