Skip to content

Commit

Permalink
feat(publisher-main): 加载插件菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 14, 2023
1 parent 22b7b67 commit a621fbf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions plugins/publisher-main/public/i18n/en_US.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"publishTool": "Publish Tool",
"setting": "Setting",
"settingMenuTips": "Let creation return to fun",
"cancel": "Cancel",
"save": "Save"
}
1 change: 1 addition & 0 deletions plugins/publisher-main/public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"publishTool": "发布工具",
"setting": "设置",
"settingMenuTips": "让创作回归乐趣",
"cancel": "取消",
"save": "保存"
}
55 changes: 49 additions & 6 deletions plugins/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin, showMessage, confirm, Dialog, Menu, isMobile, openTab, adaptHotkey } from "siyuan"
import { Dialog, isMobile, Menu, Plugin } from "siyuan"
import App from "./App.svelte"

const STORAGE_NAME = "menu-config"
Expand All @@ -7,20 +7,63 @@ const SETTING_CONTAINER = "publish-tool-setting"
// https://github.com/sveltejs/svelte-preprocess/issues/91#issuecomment-548527600
export default class PublishTool extends Plugin {
// lifecycle
onload() {
public onload() {
this._addTopBar()
console.log(`Publish Tool loaded ${new Date().getTime()}`)
}

onunload() {
public onunload() {
console.log("Publish Tool unloaded")
}

openSetting() {
this._show_setting_dialog()
public openSetting() {
this._showSettingDialog()
}

// private functions
_show_setting_dialog() {
private _addTopBar() {
const topBarElement = this.addTopBar({
icon: "iconForward",
title: this.i18n.publishTool,
position: "right",
callback: () => {
this._addMenu(topBarElement.getBoundingClientRect())
},
})
}

private async _addMenu(rect: DOMRect) {
if (!this.data) {
await this.loadData(STORAGE_NAME)
}

const menu = new Menu("topBarSample")
menu.addItem({
icon: "iconInfo",
label: this.i18n.setting,
click: () => {
this._showSettingDialog()
},
})

menu.addSeparator()
menu.addItem({
icon: "iconSparkles",
label: this.data[STORAGE_NAME] || this.i18n.settingMenuTips,
type: "readonly",
})
if (isMobile()) {
menu.fullscreen()
} else {
menu.open({
x: rect.right,
y: rect.bottom,
isLeft: true,
})
}
}

private _showSettingDialog() {
new Dialog({
title: `${this.i18n.setting} - ${this.i18n.publishTool}`,
content: `<div id="${SETTING_CONTAINER}"></div>`,
Expand Down

0 comments on commit a621fbf

Please sign in to comment.