Skip to content

Commit

Permalink
fix: 修复重启可能出现的图标不加载问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 2, 2023
1 parent 93fc165 commit aab8d7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
18 changes: 7 additions & 11 deletions siyuan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
* questions.
*/

import { App, getFrontend, IObject, Plugin } from "siyuan"
import { SiyuanConfig, SiyuanKernelApi } from "zhi-siyuan-api"
import { createSiyuanAppLogger } from "./appLogger"
import { WidgetInvoke } from "./invoke/widgetInvoke"
import { Topbar } from "./topbar"
import {App, getFrontend, IObject, Plugin} from "siyuan"
import {SiyuanConfig, SiyuanKernelApi} from "zhi-siyuan-api"
import {createSiyuanAppLogger} from "./appLogger"
import {WidgetInvoke} from "./invoke/widgetInvoke"
import {Topbar} from "./topbar"

import "./index.styl"
import { ConfigManager } from "./store/config"

export default class PublisherPlugin extends Plugin {
private logger
Expand All @@ -39,7 +38,6 @@ export default class PublisherPlugin extends Plugin {
public isMobile: boolean
public kernelApi: SiyuanKernelApi
private widgetInvoke
private cfg

constructor(options: { app: App; id: string; name: string; i18n: IObject }) {
super(options)
Expand All @@ -60,10 +58,8 @@ export default class PublisherPlugin extends Plugin {
this.widgetInvoke.showPublisherPublishSettingDialog()
}

async onload() {
// 预加载数据
this.cfg = await ConfigManager.loadConfig(this)
onload() {
// 初始化菜单
await this.topbar.initTopbar()
this.topbar.initTopbar()
}
}
26 changes: 17 additions & 9 deletions siyuan/topbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { WidgetInvoke } from "./invoke/widgetInvoke"
import { PluginInvoke } from "./invoke/pluginInvoke"
import { ObjectUtil } from "zhi-common"
import { DYNAMIC_CONFIG_KEY } from "./Constants"
import { ConfigManager } from "~/siyuan/store/config.ts"

/**
* 顶部按钮
Expand All @@ -50,27 +51,34 @@ export class Topbar {
this.widgetInvoke = new WidgetInvoke(pluginInstance)
}

public async initTopbar() {
const quickMenus = await this.getQuickMenus()
const extendMenus = await this.getExtendMenus()
public initTopbar() {
const self = this
const topBarElement = this.pluginInstance.addTopBar({
icon: icons.iconPlane,
title: this.pluginInstance.i18n.publishTool,
position: "left",
callback: () => {
this.addMenu(topBarElement.getBoundingClientRect(), quickMenus, extendMenus)
},
callback: () => {},
})
topBarElement.addEventListener("click", async () => {
// 预加载数据
const setting = await ConfigManager.loadConfig(self.pluginInstance)
// 快速发布
const quickMenus = self.getQuickMenus(setting)
// 扩展菜单
const extendMenus = await self.getExtendMenus()
// 初始化菜单
this.addMenu(topBarElement.getBoundingClientRect(), quickMenus, extendMenus)
self.logger.info("publisher menu loaded")
})
}

private async getQuickMenus() {
private getQuickMenus(setting: any) {
const submenus = <IMenuItemOption[]>[]
// 读取配置
if (ObjectUtil.isEmptyObject(this.pluginInstance.cfg)) {
if (ObjectUtil.isEmptyObject(setting)) {
// 配置错误,直接返回空
return submenus
}
const setting = this.pluginInstance.cfg
const dynJsonCfg = setting[DYNAMIC_CONFIG_KEY] as any
this.logger.info("dynJsonCfg =>", dynJsonCfg.totalCfg)
// 构造发布菜单
Expand Down

0 comments on commit aab8d7f

Please sign in to comment.