1
1
// The module 'vscode' contains the VS Code extensibility API
2
2
// Import the module and reference it with the alias vscode in your code below
3
3
import * as vscode from 'vscode' ;
4
+ ( global as any ) . WebSocket = require ( 'ws' ) ;
5
+
6
+ const path = require ( 'path' ) ;
7
+ require ( './proxy' ) ;
8
+
9
+ require ( 'dotenv' ) . config ( { path : path . resolve ( __dirname , '../.env' ) } ) ;
10
+
11
+ const sleep = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
12
+
13
+ import PTT from 'ptt-client' ;
14
+
15
+ const ptt = new PTT ( {
16
+ url : 'ws://127.0.0.1:9770' ,
17
+ } ) ;
18
+
19
+ let firstTime = true ;
4
20
5
21
// this method is called when your extension is activated
6
22
// your extension is activated the very first time the command is executed
@@ -13,11 +29,31 @@ export function activate(context: vscode.ExtensionContext) {
13
29
// The command has been defined in the package.json file
14
30
// Now provide the implementation of the command with registerCommand
15
31
// The commandId parameter must match the command field in package.json
16
- let disposable = vscode . commands . registerCommand ( 'extension.helloWorld' , ( ) => {
17
- // The code you place here will be executed every time your command is executed
32
+ let disposable = vscode . commands . registerCommand ( 'extension.helloWorld' , async ( ) => {
33
+
34
+ // The code you place here will be executed every time your command is executed
35
+ if ( firstTime ) {
36
+ // !FIXME: workaround for PTT not get initialized properly
37
+ await sleep ( 1000 ) ;
38
+ firstTime = false ;
39
+ }
40
+
41
+ const isLogin = await ptt . login ( process . env . USERNAME , process . env . PASSWORD )
42
+ if ( ! isLogin ) {
43
+ // TODO: handle this
44
+
45
+ return ;
46
+ }
47
+
48
+ // get last 20 articles from specific board
49
+ let articles = await ptt . getArticles ( 'C_Chat' ) ;
50
+ console . log ( articles ) ;
51
+ // // get the content of specific article
52
+ // let article = await ptt.getArticle('C_Chat', articles[articles.length-1].sn);
53
+ // console.log(article);
18
54
19
55
// Display a message box to the user
20
- vscode . window . showInformationMessage ( 'Hello World!' ) ;
56
+ // vscode.window.showInformationMessage('Hello World!');
21
57
} ) ;
22
58
23
59
context . subscriptions . push ( disposable ) ;
0 commit comments