From a621fbf722cc04f5a18adca71524e33a7b43d4ab Mon Sep 17 00:00:00 2001 From: terwer Date: Sun, 14 May 2023 12:51:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(publisher-main):=20=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/publisher-main/public/i18n/en_US.json | 1 + plugins/publisher-main/public/i18n/zh_CN.json | 1 + plugins/publisher-main/src/index.ts | 55 +++++++++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/plugins/publisher-main/public/i18n/en_US.json b/plugins/publisher-main/public/i18n/en_US.json index a0273127..efd2d037 100644 --- a/plugins/publisher-main/public/i18n/en_US.json +++ b/plugins/publisher-main/public/i18n/en_US.json @@ -1,6 +1,7 @@ { "publishTool": "Publish Tool", "setting": "Setting", + "settingMenuTips": "Let creation return to fun", "cancel": "Cancel", "save": "Save" } \ No newline at end of file diff --git a/plugins/publisher-main/public/i18n/zh_CN.json b/plugins/publisher-main/public/i18n/zh_CN.json index 6774f1e0..c07f1ff2 100644 --- a/plugins/publisher-main/public/i18n/zh_CN.json +++ b/plugins/publisher-main/public/i18n/zh_CN.json @@ -1,6 +1,7 @@ { "publishTool": "发布工具", "setting": "设置", + "settingMenuTips": "让创作回归乐趣", "cancel": "取消", "save": "保存" } \ No newline at end of file diff --git a/plugins/publisher-main/src/index.ts b/plugins/publisher-main/src/index.ts index 83701851..5c0ce31a 100644 --- a/plugins/publisher-main/src/index.ts +++ b/plugins/publisher-main/src/index.ts @@ -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" @@ -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: `
`,