import { commands , MessageItem , Uri , window } from 'vscode' ; import { callWithTelemetryAndErrorHandling , IActionContext } from "vscode-azureextensionui" ; import { ext } from "./extensionVariables" ; import { assert } from './fixed_assert' ; import { minutesToMs , weeksToMs } from "./util/time" ; interface ISettings { delayBetweenAttempts : number ; } const defaultSettings = { delayBetweenAttempts : weeksToMs ( 1 ) , } ; const debugSettings = { delayBetweenAttempts : minutesToMs ( 1 ) , } ; export class TimedMessage { private _settings : ISettings = defaultSettings ; private _alreadyCheckedThisSession : boolean = false ; public constructor ( private _postponeUntilTimeKey , private _debugSettingKey , private _message , private _learnMoreUri ) { } /**
     * Called whenever the user is interacting with the extension (thus gets called a lot)
     */ public registerActiveUseNoThrow ( ) { if ( this . _alreadyCheckedThisSession ) { return ; } this . _alreadyCheckedThisSession = true ; callWithTelemetryAndErrorHandling ( "considerShowingMessage" , async ( context ) => { context . errorHandling . suppressDisplay = true ; context . telemetry . properties . message = this . _message ; await this . checkForDebugMode ( ) ; const postponeUntilTime = ext . context . globalState . get < number > ( this . _postponeUntilTimeKey ) ?? 0 ; if ( postponeUntilTime < 0 ) { context . telemetry . properties . status = 'NeverShowAgain' ; return ; } else if ( Date . now ( ) < postponeUntilTime ) { context . telemetry . properties . status = "TooEarly" ; return ; } else if ( postponeUntilTime === 0 ) { await this . postpone ( ) ; context . telemetry . properties . status = "FirstDelay" ; return ; } await this . postpone ( ) ; const neverAskAgain = { title : "Never ask again" } ; const moreInfo = { title : "More Info" } ; const response = await window . showInformationMessage ( this . _message , moreInfo , neverAskAgain ) ?? neverAskAgain ; context . telemetry . properties . response = String ( response . title ) ; await this . neverShowAgain ( ) ; if ( response === moreInfo ) { await commands . executeCommand ( 'vscode.open' , this . _learnMoreUri ) ; } else { assert ( response === neverAskAgain ) ; } } ) . catch ( err => { assert . fail ( "callWithTelemetryAndErrorHandling in TimedMessage.registerActiveUseNoThrow shouldn't throw" ) ; } ) ; } private async checkForDebugMode ( ) { if ( ext . configuration . get < boolean > ( this . _debugSettingKey ) ) { this . _settings = debugSettings ; } } public async neverShowAgain ( ) { this . _alreadyCheckedThisSession = true ; await ext . context . globalState . update ( this . _postponeUntilTimeKey , - 1 ) ; } private async postpone ( ) { await ext . context . globalState . update ( this . _postponeUntilTimeKey , Date . now ( ) + this . _settings . delayBetweenAttempts ) ; } }