Merge pull request #21 from Yeban8090/1.0.6

1.0.6
This commit is contained in:
Yeban8090 2025-08-21 10:55:51 +08:00 committed by GitHub
commit 571e8b2ecb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 55 deletions

View file

@ -1,7 +1,7 @@
{
"id": "mp-preview",
"name": "MP Preview",
"version": "1.0.5",
"version": "1.0.6",
"minAppVersion": "0.15.0",
"description": "Preview and convert Markdown files to MP format",
"author": "Yeban",

View file

@ -6,72 +6,77 @@ import { MPConverter } from './converter';
import { DonateManager } from './donateManager';
import { MPSettingTab } from './settings/MPSettingTab';
export default class MPPlugin extends Plugin {
settingsManager: SettingsManager;
templateManager: TemplateManager;
async onload() {
// 初始化设置管理器
this.settingsManager = new SettingsManager(this);
await this.settingsManager.loadSettings();
settingsManager: SettingsManager;
templateManager: TemplateManager;
async onload() {
// 初始化设置管理器
this.settingsManager = new SettingsManager(this);
await this.settingsManager.loadSettings();
// 初始化模板管理器
this.templateManager = new TemplateManager(this.app, this.settingsManager);
// 初始化模板管理器
this.templateManager = new TemplateManager(this.app, this.settingsManager);
// 初始化转换器
MPConverter.initialize(this.app);
// 初始化转换器
MPConverter.initialize(this.app);
DonateManager.initialize(this.app, this);
DonateManager.initialize(this.app, this);
// 注册视图
this.registerView(
VIEW_TYPE_MP,
(leaf) => new MPView(leaf, this.templateManager, this.settingsManager)
);
// 注册视图
this.registerView(
VIEW_TYPE_MP,
(leaf) => new MPView(leaf, this.templateManager, this.settingsManager)
);
// 自动打开视图但不聚焦
this.app.workspace.onLayoutReady(() => {
const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_MP);
if (leaves.length === 0) {
const rightLeaf = this.app.workspace.getRightLeaf(false);
if (rightLeaf) {
rightLeaf.setViewState({
type: VIEW_TYPE_MP,
active: false,
});
}
}
});
// 自动打开视图但不聚焦
// this.app.workspace.onLayoutReady(() => {
// const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_MP);
// if (leaves.length === 0) {
// const rightLeaf = this.app.workspace.getRightLeaf(false);
// if (rightLeaf) {
// rightLeaf.setViewState({
// type: VIEW_TYPE_MP,
// active: false,
// });
// }
// }
// });
// 添加命令到命令面板
this.addCommand({
// 添加一个功能按钮用于打开所有面板
this.addRibbonIcon("eye", "打开公众号预览", () => {
this.activateView();
});
// 添加命令到命令面板
this.addCommand({
id: 'open-mp-preview',
name: '打开公众号预览插件',
callback: async () => {
await this.activateView();
callback: async () => {
await this.activateView();
}
});
});
// 在插件的 onload 方法中添加:
this.addSettingTab(new MPSettingTab(this.app, this));
// 在插件的 onload 方法中添加:
this.addSettingTab(new MPSettingTab(this.app, this));
}
async activateView() {
// 如果视图已经存在,激活它
const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_MP);
if (leaves.length > 0) {
this.app.workspace.revealLeaf(leaves[0]);
return;
}
async activateView() {
// 如果视图已经存在,激活它
const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_MP);
if (leaves.length > 0) {
this.app.workspace.revealLeaf(leaves[0]);
return;
}
// 创建新视图
const rightLeaf = this.app.workspace.getRightLeaf(false);
if (rightLeaf) {
await rightLeaf.setViewState({
type: VIEW_TYPE_MP,
active: true,
});
} else {
// 如果无法获取右侧面板,显示错误提示
// 创建新视图
const rightLeaf = this.app.workspace.getRightLeaf(false);
if (rightLeaf) {
await rightLeaf.setViewState({
type: VIEW_TYPE_MP,
active: true,
});
} else {
// 如果无法获取右侧面板,显示错误提示
new Notice('无法创建视图面板');
}
}
}
}