import * as vscode from 'vscode' ; import * as nls from 'vscode-nls' ; import { SimpleBrowserManager } from './simpleBrowserManager' ; import { SimpleBrowserView } from './simpleBrowserView' ; declare class URL { constructor ( input , base ? ) ; hostname : string ; } const localize = nls . loadMessageBundle ( ) ; const openApiCommand = 'simpleBrowser.api.open' ; const showCommand = 'simpleBrowser.show' ; const enabledHosts = new Set < string > ( [ 'localhost' , '127.0.0.1' , '0:0:0:0:0:0:0:1' , '::1' , '0.0.0.0' , '0:0:0:0:0:0:0:0' , '::' ] ) ; const openerId = 'simpleBrowser.open' ; export function activate ( context ) { const manager = new SimpleBrowserManager ( context . extensionUri ) ; context . subscriptions . push ( manager ) ; context . subscriptions . push ( vscode . window . registerWebviewPanelSerializer ( SimpleBrowserView . viewType , { deserializeWebviewPanel : async ( panel , state ) => { manager . restore ( panel , state ) ; } } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( showCommand , async ( url ? ) => { if ( ! url ) { url = await vscode . window . showInputBox ( { placeHolder : localize ( 'simpleBrowser.show.placeholder' , "https://example.com" ) , prompt : localize ( 'simpleBrowser.show.prompt' , "Enter url to visit" ) } ) ; } if ( url ) { manager . show ( url ) ; } } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( openApiCommand , ( url , showOptions ? ) => { manager . show ( url . toString ( ) , showOptions ) ; } ) ) ; context . subscriptions . push ( vscode . window . registerExternalUriOpener ( openerId , { canOpenExternalUri ( uri ) { const originalUri = new URL ( uri . toString ( ) ) ; if ( enabledHosts . has ( originalUri . hostname ) ) { return isWeb ( ) ? vscode . ExternalUriOpenerPriority . Default : vscode . ExternalUriOpenerPriority . Option ; } return vscode . ExternalUriOpenerPriority . None ; } , openExternalUri ( resolveUri ) { return manager . show ( resolveUri . toString ( ) , { viewColumn : vscode . window . activeTextEditor ? vscode . ViewColumn . Beside : vscode . ViewColumn . Active } ) ; } } , { schemes : [ 'http' , 'https' ] , label : localize ( 'openTitle' , "Open in simple browser" ) , } ) ) ; } function isWeb ( ) { return typeof navigator !== 'undefined' && vscode . env . uiKind === vscode . UIKind . Web ; }