1- import { commands , ExtensionContext , window } from 'vscode' ;
1+ import { commands , ConfigurationChangeEvent , ExtensionContext , window , workspace } from 'vscode' ;
22import * as nls from 'vscode-nls' ;
3+ import { client } from './client' ;
34import { compose } from './commands/compose' ;
45import { deleteItem } from './commands/deleteItem' ;
56import { editTags } from './commands/editTags' ;
@@ -11,11 +12,13 @@ import { openItemExternal } from './commands/openItemExternal';
1112import { qiitaItemsProvider } from './explorers/qiitaItems' ;
1213
1314nls . config ( process . env . VSCODE_NLS_CONFIG as nls . Options ) ( ) ;
15+ const localize = nls . loadMessageBundle ( ) ;
1416
1517export function activate ( context : ExtensionContext ) {
1618 window . registerTreeDataProvider ( 'qiitaItems' , qiitaItemsProvider ) ;
1719
1820 context . subscriptions . push (
21+ workspace . onDidChangeConfiguration ( refreshUserState ) ,
1922 commands . registerCommand ( 'qiita.openItem' , openItem ( context . storagePath ) ) ,
2023 commands . registerCommand ( 'qiita.editTags' , editTags ) ,
2124 commands . registerCommand ( 'qiita.makePublic' , makePublic ) ,
@@ -25,8 +28,26 @@ export function activate (context: ExtensionContext) {
2528 commands . registerCommand ( 'qiita.editTitle' , editTitle ) ,
2629 commands . registerCommand ( 'qiita.expandItems' , expandItems ) ,
2730 ) ;
31+
32+ if ( ! workspace . getConfiguration ( 'qiita' ) . get ( 'token' ) ) {
33+ window . showInformationMessage ( localize (
34+ 'general.information.unauthorized' ,
35+ 'まだQiitaアカウントを連携していないようです。設定画面からトークンを入力することで利用可能になります。' ,
36+ ) ) ;
37+ }
2838}
2939
3040export function deactivate ( ) {
3141 /* none */
3242}
43+
44+ /**
45+ * 設定が変更されたときにトークンをセットし直してツリーデータをリフレッシュ
46+ * @param e 変更イベント
47+ */
48+ export const refreshUserState = async ( e : ConfigurationChangeEvent ) => {
49+ if ( e . affectsConfiguration ( 'qiita.token' ) ) {
50+ client . setToken ( workspace . getConfiguration ( 'qiita' ) . get ( 'token' ) || '' ) ;
51+ await qiitaItemsProvider . refresh ( ) ;
52+ }
53+ } ;
0 commit comments