@@ -13,6 +13,7 @@ import { uploadImage } from '../commands/upload-image/upload-image';
13
13
import { ImageUploadStatusId } from '../models/image-upload-status' ;
14
14
import { openPostFile } from '../commands/posts-list/open-post-file' ;
15
15
import { parseWebviewHtml } from 'src/services/parse-webview-html' ;
16
+ import path from 'path' ;
16
17
17
18
const panels : Map < string , vscode . WebviewPanel > = new Map ( ) ;
18
19
@@ -35,7 +36,7 @@ export namespace postConfigurationPanel {
35
36
export const buildPanelId = ( postId : number , postTitle : string ) : string => `${ postId } -${ postTitle } ` ;
36
37
export const findPanelById = ( panelId : string ) => panels . get ( panelId ) ;
37
38
export const open = async ( option : PostConfigurationPanelOpenOption ) => {
38
- const { post, breadcrumbs } = option ;
39
+ const { post, breadcrumbs, localFileUri } = option ;
39
40
const panelTitle = option . panelTitle ? option . panelTitle : `博文设置 - ${ post . title } ` ;
40
41
await openPostFile ( post , {
41
42
viewColumn : vscode . ViewColumn . One ,
@@ -47,22 +48,28 @@ export namespace postConfigurationPanel {
47
48
const disposables : ( vscode . Disposable | undefined ) [ ] = [ ] ;
48
49
panel = await createPanel ( panelTitle , post ) ;
49
50
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
+
65
52
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
+ } ) ,
66
73
observeWebviewMessages ( panel , option ) ,
67
74
observeActiveColorSchemaChange ( panel ) ,
68
75
observerPanelDisposeEvent ( panel , disposables )
0 commit comments