import { Node } from './v2ex' ; import { ExtensionContext , Webview , Uri } from 'vscode' ; export default class G { static context : ExtensionContext | undefined ; param webview static getWebViewContextPath ( webview ) { return webview . asWebviewUri ( Uri . file ( this . context ! . extensionPath ) ) . toString ( ) ; } param cookie static async setCookie ( cookie ) { await this . context ?. globalState . update ( 'cookie' , cookie ) ; } /**
     * 获取cookie
     */ static getCookie ( ) { return this . context ?. globalState . get ( 'cookie' ) ; } /**
     * 获取自定义节点
     */ static getCustomNodes ( ) { return this . context ?. globalState . get < Node [ ] > ( 'nodes' ) || [ ] ; } param newNodes static setCustomNodes ( newNodes ) { this . context ?. globalState . update ( 'nodes' , newNodes ) ; } param node returns static addCustomNode ( node ) { const nodes = this . getCustomNodes ( ) ; if ( nodes . find ( ( n ) => n . name === node . name ) ) { return false ; } nodes . push ( node ) ; this . setCustomNodes ( nodes ) ; return true ; } param nodeName static removeCustomNode ( nodeName ) { const nodes = this . getCustomNodes ( ) ; const i = nodes . findIndex ( ( n ) => n . name === nodeName ) ; if ( i >= 0 ) { nodes . splice ( i , 1 ) ; } this . setCustomNodes ( nodes ) ; } }