import { TreeNode } from './providers/BaseProvider' ; import ExploreProvider from './providers/ExploreProvider' ; import * as vscode from 'vscode' ; import topicItemClick from './commands/topicItemClick' ; import login , { LoginResult } from './commands/login' ; import G from './global' ; import { EOL } from 'os' ; import CustomProvider from './providers/CustomProvider' ; import addNode from './commands/addNode' ; import removeNode from './commands/removeNode' ; import CollectionProvider from './providers/CollectionProvider' ; import { V2ex , DailyRes } from './v2ex' ; import search from './commands/search' ; export function activate ( context ) { G . context = context ; V2ex . getAllNodes ( ) ; V2ex . checkCookie ( G . getCookie ( ) ! ) . then ( ( isLoginValid ) => { console . log ( `登录是否有效：${ isLoginValid }` ) ; if ( isLoginValid ) { V2ex . daily ( ) . then ( ( res ) => { console . log ( `每日签到结果：${ res }` ) ; if ( res === DailyRes . success ) { vscode . window . showInformationMessage ( '签到成功' ) ; } } ) ; } } ) ; const exploreProvider = new ExploreProvider ( ) ; vscode . window . createTreeView ( 'v2ex-explore' , { treeDataProvider : exploreProvider , showCollapseAll : true } ) ; const customProvider = new CustomProvider ( ) ; vscode . window . createTreeView ( 'v2ex-custom' , { treeDataProvider : customProvider , showCollapseAll : true } ) ; const collectionProvider = new CollectionProvider ( ) ; vscode . window . createTreeView ( 'v2ex-collection' , { treeDataProvider : collectionProvider , showCollapseAll : true } ) ; let cDisposable1 = vscode . commands . registerCommand ( 'v2ex.login' , async ( ) => { const loginResult = await login ( ) ; if ( loginResult === LoginResult . success || loginResult === LoginResult . logout ) { collectionProvider . refreshNodeList ( ) ; } } ) ; let cDisposable2 = vscode . commands . registerCommand ( 'v2ex.copyLink' , ( item ) => vscode . env . clipboard . writeText ( item . link ) ) ; let cDisposable3 = vscode . commands . registerCommand ( 'v2ex.copyTitleLink' , ( item ) => vscode . env . clipboard . writeText ( item . label + EOL + item . link ) ) ; let cDisposable4 = vscode . commands . registerCommand ( 'v2ex.viewInBrowser' , ( item ) => vscode . env . openExternal ( vscode . Uri . parse ( item . link ) ) ) ; let cDisposable5 = vscode . commands . registerCommand ( 'v2ex.topicItemClick' , ( item ) => topicItemClick ( item ) ) ; let homeDisposable1 = vscode . commands . registerCommand ( 'v2ex-explore.search' , ( ) => search ( ) ) ; let homeDisposable2 = vscode . commands . registerCommand ( 'v2ex-explore.refreshAll' , ( ) => exploreProvider . refreshAll ( ) ) ; let homeDisposable3 = vscode . commands . registerCommand ( 'v2ex-explore.refreshNode' , ( root ) => exploreProvider . refreshRoot ( root ) ) ; let cusDisposable1 = vscode . commands . registerCommand ( 'v2ex-explore.addNode' , async ( ) => { const isAdd = await addNode ( ) ; isAdd && customProvider . refreshNodeList ( ) ; } ) ; let cusDisposable2 = vscode . commands . registerCommand ( 'v2ex-custom.refreshAll' , ( ) => customProvider . refreshAll ( ) ) ; let cusDisposable3 = vscode . commands . registerCommand ( 'v2ex-custom.refreshNode' , ( root ) => customProvider . refreshRoot ( root ) ) ; let cusDisposable4 = vscode . commands . registerCommand ( 'v2ex-custom.removeNode' , ( root ) => { removeNode ( root ) ; customProvider . refreshNodeList ( ) ; } ) ; let colDisposable1 = vscode . commands . registerCommand ( 'v2ex-collection.refreshAll' , ( ) => collectionProvider . refreshAll ( ) ) ; let colDisposable2 = vscode . commands . registerCommand ( 'v2ex-collection.refreshNode' , ( root ) => collectionProvider . refreshRoot ( root ) ) ; context . subscriptions . push ( cDisposable1 , cDisposable2 , cDisposable3 , cDisposable4 , cDisposable5 , homeDisposable1 , homeDisposable2 , homeDisposable3 , cusDisposable1 , cusDisposable2 , cusDisposable3 , cusDisposable4 , colDisposable1 , colDisposable2 ) ; } export function deactivate ( ) { G . context = undefined ; }