mirror of
https://github.com/woodchen-ink/obsidian-publish-to-discourse.git
synced 2025-07-17 21:32:05 +08:00
修复 activeFile 处理逻辑,增强文件选择和模态框稳定性
- 在打开类别模态框前确保 activeFile 正确初始化 - 添加对未选择文件场景的错误处理 - 在类别选择模态框中增加 activeFile 存在性检查 - 提升插件在不同文件选择状态下的健壮性
This commit is contained in:
parent
9ca83b1d15
commit
d3b678fc81
24
src/main.ts
24
src/main.ts
@ -517,6 +517,23 @@ export default class DiscourseSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
private async openCategoryModal() {
|
||||
// 确保activeFile已设置
|
||||
if (!this.activeFile) {
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
if (!activeFile) {
|
||||
new NotifyUser(this.app, t('NO_ACTIVE_FILE')).open();
|
||||
return;
|
||||
}
|
||||
|
||||
const content = await this.app.vault.read(activeFile);
|
||||
const fm = this.getFrontMatter(content);
|
||||
this.activeFile = {
|
||||
name: activeFile.basename,
|
||||
content: content,
|
||||
postId: fm?.discourse_post_id
|
||||
};
|
||||
}
|
||||
|
||||
const [categories, tags] = await Promise.all([
|
||||
this.fetchCategories(),
|
||||
this.fetchTags()
|
||||
@ -616,6 +633,13 @@ export class SelectCategoryModal extends Modal {
|
||||
contentEl.empty();
|
||||
contentEl.addClass('discourse-sync-modal');
|
||||
|
||||
// 确保activeFile存在
|
||||
if (!this.plugin.activeFile) {
|
||||
contentEl.createEl("h1", { text: t('ERROR') });
|
||||
contentEl.createEl("p", { text: t('NO_ACTIVE_FILE') });
|
||||
return;
|
||||
}
|
||||
|
||||
const isUpdate = this.plugin.activeFile.postId !== undefined;
|
||||
contentEl.createEl("h1", { text: isUpdate ? t('UPDATE_POST') : t('PUBLISH_TO_DISCOURSE') });
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user