diff --git a/manifest.json b/manifest.json index a632449..ef28100 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/src/main.ts b/src/main.ts index a2ffaf7..036e4e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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('无法创建视图面板'); - } } + } } \ No newline at end of file