@@ -26,9 +26,41 @@ export class GitPanelViewProvider implements vscode.WebviewViewProvider {
2626 this . _commits = this . storageService . getCommits ( )
2727 }
2828
29+ public async refreshHistory ( forceRefresh : boolean = false ) {
30+ if ( ! this . _view )
31+ return
32+
33+ try {
34+ if ( this . _commits . length === 0 || forceRefresh ) {
35+ const history = await this . gitService . getHistory ( )
36+
37+ this . _commits = history . all . map ( commit => ( {
38+ ...commit ,
39+ authorName : commit . author_name ,
40+ authorEmail : commit . author_email ,
41+ body : commit . body || '' ,
42+ } ) )
43+
44+ this . storageService . saveCommits ( this . _commits )
45+ }
46+
47+ this . _view . webview . postMessage ( {
48+ command : CHANNEL . HISTORY ,
49+ commits : this . _commits ,
50+ } )
51+ }
52+ catch ( error ) {
53+ this . _view . webview . postMessage ( {
54+ command : 'Failed to get git history' ,
55+ message : `${ error } ` ,
56+ } )
57+ }
58+ }
59+
2960 public resolveWebviewView (
3061 webviewView : vscode . WebviewView ,
3162 ) {
63+ this . _view = webviewView
3264 webviewView . webview . options = {
3365 enableScripts : true ,
3466 localResourceRoots : [
@@ -43,31 +75,7 @@ export class GitPanelViewProvider implements vscode.WebviewViewProvider {
4375 webviewView . webview . onDidReceiveMessage ( async ( message ) => {
4476 switch ( message . command ) {
4577 case WEBVIEW_CHANNEL . GET_HISTORY :
46- try {
47- if ( this . _commits . length === 0 || message . forceRefresh ) {
48- const history = await this . gitService . getHistory ( )
49-
50- this . _commits = history . all . map ( commit => ( {
51- ...commit ,
52- authorName : commit . author_name ,
53- authorEmail : commit . author_email ,
54- body : commit . body || '' ,
55- } ) )
56-
57- this . storageService . saveCommits ( this . _commits )
58- }
59-
60- webviewView . webview . postMessage ( {
61- command : CHANNEL . HISTORY ,
62- commits : this . _commits ,
63- } )
64- }
65- catch ( error ) {
66- webviewView . webview . postMessage ( {
67- command : 'Failed to get git history' ,
68- message : `${ error } ` ,
69- } )
70- }
78+ await this . refreshHistory ( message . forceRefresh )
7179 break
7280
7381 case WEBVIEW_CHANNEL . SHOW_COMMIT_DETAILS :
0 commit comments