@@ -13,6 +13,7 @@ import { uploadImage } from '../commands/upload-image/upload-image';
1313import { ImageUploadStatusId } from '../models/image-upload-status' ;
1414import { openPostFile } from '../commands/posts-list/open-post-file' ;
1515import { parseWebviewHtml } from 'src/services/parse-webview-html' ;
16+ import path from 'path' ;
1617
1718const panels : Map < string , vscode . WebviewPanel > = new Map ( ) ;
1819
@@ -35,7 +36,7 @@ export namespace postConfigurationPanel {
3536 export const buildPanelId = ( postId : number , postTitle : string ) : string => `${ postId } -${ postTitle } ` ;
3637 export const findPanelById = ( panelId : string ) => panels . get ( panelId ) ;
3738 export const open = async ( option : PostConfigurationPanelOpenOption ) => {
38- const { post, breadcrumbs } = option ;
39+ const { post, breadcrumbs, localFileUri } = option ;
3940 const panelTitle = option . panelTitle ? option . panelTitle : `博文设置 - ${ post . title } ` ;
4041 await openPostFile ( post , {
4142 viewColumn : vscode . ViewColumn . One ,
@@ -47,22 +48,28 @@ export namespace postConfigurationPanel {
4748 const disposables : ( vscode . Disposable | undefined ) [ ] = [ ] ;
4849 panel = await createPanel ( panelTitle , post ) ;
4950 const { webview } = panel ;
50- // eslint-disable-next-line @typescript-eslint/no-floating-promises
51- webview . postMessage ( {
52- command : webviewCommands . UiCommands . setFluentIconBaseUrl ,
53- baseUrl : webview . asWebviewUri ( Uri . joinPath ( resourceRootUri ( ) , 'fonts' ) ) . toString ( ) + '/' ,
54- } as webviewMessage . SetFluentIconBaseUrlMessage ) ;
55- // eslint-disable-next-line @typescript-eslint/no-floating-promises
56- webview . postMessage ( {
57- command : webviewCommands . UiCommands . editPostConfiguration ,
58- post : cloneDeep ( post ) ,
59- activeTheme : vscode . window . activeColorTheme . kind ,
60- personalCategories : cloneDeep ( await postCategoryService . fetchCategories ( ) ) ,
61- siteCategories : cloneDeep ( await siteCategoryService . fetchAll ( ) ) ,
62- tags : cloneDeep ( await postTagService . fetchTags ( ) ) ,
63- breadcrumbs,
64- } as webviewMessage . EditPostConfigurationMessage ) ;
51+
6552 disposables . push (
53+ webview . onDidReceiveMessage ( async ( { command } : webviewMessage . Message ) => {
54+ if ( command === webviewCommands . ExtensionCommands . refreshPost ) {
55+ await webview . postMessage ( {
56+ command : webviewCommands . UiCommands . setFluentIconBaseUrl ,
57+ baseUrl : webview . asWebviewUri ( Uri . joinPath ( resourceRootUri ( ) , 'fonts' ) ) . toString ( ) + '/' ,
58+ } as webviewMessage . SetFluentIconBaseUrlMessage ) ;
59+ await webview . postMessage ( {
60+ command : webviewCommands . UiCommands . editPostConfiguration ,
61+ post : cloneDeep ( post ) ,
62+ activeTheme : vscode . window . activeColorTheme . kind ,
63+ personalCategories : cloneDeep ( await postCategoryService . fetchCategories ( ) ) ,
64+ siteCategories : cloneDeep ( await siteCategoryService . fetchAll ( ) ) ,
65+ tags : cloneDeep ( await postTagService . fetchTags ( ) ) ,
66+ breadcrumbs,
67+ fileName : localFileUri
68+ ? path . basename ( localFileUri . fsPath , path . extname ( localFileUri ?. fsPath ) )
69+ : '' ,
70+ } as webviewMessage . EditPostConfigurationMessage ) ;
71+ }
72+ } ) ,
6673 observeWebviewMessages ( panel , option ) ,
6774 observeActiveColorSchemaChange ( panel ) ,
6875 observerPanelDisposeEvent ( panel , disposables )
0 commit comments