import path = require ( "path" ) ; import * as semver from "semver" ; import * as vscode from "vscode" ; import { ContentProvider } from "./ContentProvider" ; import { WhatsNewPageBuilder } from "./PageBuilder" ; export class WhatsNewManager { private extensionName : string ; private context : vscode . ExtensionContext ; private contentProvider : ContentProvider ; private extension : vscode . Extension < any > ; constructor ( context ) { this . context = context ; } public registerContentProvider ( extensionName , contentProvider ) { this . extensionName = extensionName ; this . contentProvider = contentProvider ; return this ; } public showPageInActivation ( ) { this . extension = vscode . extensions . getExtension ( `killerall.${ this . extensionName }` ) ; const previousExtensionVersion = this . context . globalState . get < string > ( `${ this . extensionName }.version` ) ; this . showPageIfVersionDiffers ( this . extension . packageJSON . version , previousExtensionVersion ) ; } public showPage ( ) { const panel = vscode . window . createWebviewPanel ( `${ this . extensionName }.whatsNew` , `What's New in ${ this . extension . packageJSON . displayName }` , vscode . ViewColumn . One , { enableScripts : true } ) ; const onDiskPath = vscode . Uri . file ( path . join ( this . context . extensionPath , "vscode-whats-new" , "ui" , "whats-new.html" ) ) ; const pageUri = onDiskPath . with ( { scheme : "vscode-resource" } ) ; const cssPathOnDisk = vscode . Uri . file ( path . join ( this . context . extensionPath , "vscode-whats-new" , "ui" , "main.css" ) ) ; const cssUri = cssPathOnDisk . with ( { scheme : "vscode-resource" } ) ; const logoPathOnDisk = vscode . Uri . file ( path . join ( this . context . extensionPath , "images" , "logo_vscode.png" ) ) ; const logoUri = logoPathOnDisk . with ( { scheme : "vscode-resource" } ) ; vscode . commands . executeCommand ( "workbench.action.closePanel" ) . then ( ( ) => { panel . webview . html = this . getWebviewContentLocal ( pageUri . fsPath , cssUri . toString ( ) , logoUri . toString ( ) ) ; } ) ; } public showPageIfVersionDiffers ( currentVersion , previousVersion ) { if ( previousVersion ) { const differs = semver . diff ( currentVersion , previousVersion ) ; if ( ! differs ) { return ; } } this . context . globalState . update ( `${ this . extensionName }.version` , currentVersion ) ; this . showPage ( ) ; } private getWebviewContentLocal ( htmlFile , cssUrl , logoUrl ) { return WhatsNewPageBuilder . newBuilder ( htmlFile ) . updateExtensionDisplayName ( this . extension . packageJSON . displayName ) . updateExtensionName ( this . extensionName ) . updateExtensionVersion ( this . extension . packageJSON . version ) . updateRepositoryUrl ( this . extension . packageJSON . repository . url . slice ( 0 , this . extension . packageJSON . repository . url . length - 4 ) ) . updateRepositoryIssues ( this . extension . packageJSON . bugs . url ) . updateRepositoryHomepage ( this . extension . packageJSON . homepage ) . updateCSS ( cssUrl ) . updateHeader ( this . contentProvider . provideHeader ( logoUrl ) ) . updateChangeLog ( this . contentProvider . provideChangeLog ( ) ) . updateSponsors ( this . contentProvider . provideSponsors ( ) ) . build ( ) ; } }