@@ -3,17 +3,13 @@ const RpcWebSocket = require('rpc-websockets').Client;
33const keywords = require ( './keywords.js' ) ;
44
55var g_client ;
6+ var g_updateStatusBar ;
67var g_timerConnect ; // 重连定时器
78var g_timerApply ; // 延迟应用样式
89var g_autoApply = true ; // 是否启用自动应用样式
910var g_valid = true ;
1011var g_host = "localhost" ;
1112var g_port = 61052 ;
12- var g_zh = false ;
13-
14- // 判断当前语言是否中文
15- const vsconfig = process . env [ 'VSCODE_NLS_CONFIG' ] ;
16- if ( vsconfig ) g_zh = JSON . parse ( vsconfig ) . locale . startsWith ( 'zh' ) ;
1713
1814/**
1915 * 初始化关键词
@@ -48,14 +44,17 @@ function startClient() {
4844 } ) ;
4945 g_client . on ( 'open' , function ( ) {
5046 console . log ( 'NodeClient::handleConnected' ) ;
47+ if ( g_updateStatusBar ) g_updateStatusBar ( true ) ;
5148 } ) ;
5249 g_client . on ( 'close' , function ( ) {
5350 console . log ( 'NodeClient::handleDisconnected' ) ;
5451 if ( g_valid && g_timerConnect == undefined ) g_timerConnect = setTimeout ( startClient , 3000 ) ;
52+ if ( g_updateStatusBar ) g_updateStatusBar ( false ) ;
5553 } ) ;
5654 g_client . on ( 'error' , function ( event ) {
5755 console . error ( 'NodeClient::handleError: ' + event . error ) ;
5856 if ( g_valid && g_timerConnect == undefined ) g_timerConnect = setTimeout ( startClient , 3000 ) ;
57+ if ( g_updateStatusBar ) g_updateStatusBar ( false ) ;
5958 } ) ;
6059 g_client . on ( 'addKeywords' , function ( words ) {
6160 console . log ( 'NodeClient::handleKeywordAdd: name=' + words ) ;
@@ -118,14 +117,14 @@ function applyStyle(doc) {
118117function setPort ( ) {
119118 vscode . window . showInputBox ( {
120119 ignoreFocusOut : false ,
121- placeHolder : g_zh ? '请输入端口号' : ' Please input the port number',
122- title : g_zh ? '输入连接端口' : ' Enter the connect port',
120+ placeHolder : vscode . l10n . t ( ' Please input the port number') ,
121+ title : vscode . l10n . t ( ' Enter the connect port') ,
123122 value : '' + vscode . workspace . getConfiguration ( ) . get ( 'qsseditor.serverPort' , '61052' ) ,
124123 validateInput : function ( value ) {
125124 let port = Number ( value ) ;
126125 if ( ! isNaN ( port ) && port != 0 )
127126 return null ;
128- return g_zh ? '端口必须在0到65535之间' : ' the value must be a number (0 < port < 65535)';
127+ return vscode . l10n . t ( ' the value must be a number (0 < port < 65535)') ;
129128 }
130129 } ) . then ( port => {
131130 if ( port == undefined ) return ;
@@ -176,6 +175,14 @@ function onDidSaveTextDocument(document) {
176175 onAutoApply ( document ) ;
177176} ;
178177
178+ /**
179+ * 设置状态栏回调
180+ * @param {function } callback
181+ */
182+ function setStatusBarCallback ( callback ) {
183+ g_updateStatusBar = callback ;
184+ }
185+
179186module . exports = {
180187 initKeywords,
181188 startClient,
@@ -185,4 +192,5 @@ module.exports = {
185192 setPort,
186193 onDidChangeTextDocument,
187194 onDidSaveTextDocument,
195+ setStatusBarCallback,
188196}
0 commit comments