import * as vscode from 'vscode' ; import { CommandName } from './constants' ; export class UriHandler implements vscode . UriHandler { constructor ( disposables ) { disposables . push ( vscode . window . registerUriHandler ( this ) ) ; } public async handleUri ( uri ) { await vscode . commands . executeCommand ( 'workbench.view.extension.bazel-explorer' ) ; switch ( uri . path ) { case '/login' : return this . login ( uri ) ; } } private async login ( uri ) { const query = parseQuery ( uri ) ; const token = query [ 'token' ] ; const release = query [ 'release' ] ; if ( ! ( token && release ) ) { return ; } return vscode . commands . executeCommand ( CommandName . Login , release , token ) ; } } function parseQuery ( uri ) { return uri . query . split ( '&' ) . reduce ( ( prev , current ) => { const queryString = current . split ( '=' ) ; prev [ queryString [ 0 ] ] = queryString [ 1 ] ; return prev ; } , { } ) ; }