From 65b078d306f38421719d5da2ec961b10006f5f67 Mon Sep 17 00:00:00 2001 From: terwer Date: Fri, 17 Feb 2023 14:35:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#319=20PicGO=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=95=8C=E9=9D=A2-=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=8D=B8=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../picgo/setting/PicgoPluginSetting.vue | 68 ++++++++++++++++++- locales/en_US.ts | 1 + locales/zh_CN.ts | 1 + public/lib/siyuan/publish-helper.js | 12 +++- scripts/scriptutils.py | 12 ++++ utils/otherlib/picgoUtil.js | 29 ++++---- utils/otherlib/siyuanBrowserUtil.js | 3 +- utils/platform/picgo/picgoPlugin.ts | 31 +++++++++ 8 files changed, 141 insertions(+), 16 deletions(-) create mode 100644 utils/platform/picgo/picgoPlugin.ts diff --git a/components/picgo/setting/PicgoPluginSetting.vue b/components/picgo/setting/PicgoPluginSetting.vue index 5b4d131c..5e2ad4a0 100644 --- a/components/picgo/setting/PicgoPluginSetting.vue +++ b/components/picgo/setting/PicgoPluginSetting.vue @@ -162,6 +162,7 @@ import { goToPage } from "~/utils/otherlib/ChromeUtil" import sysUtil from "~/utils/otherlib/sysUtil" import { debounce, DebouncedFunc } from "lodash" import { useI18n } from "vue-i18n" +import { PicgoPageMenuType } from "~/utils/platform/picgo/picgoPlugin" const logger = LogFactory.getLogger( "components/picgo/setting/PicgoPluginSetting.vue" @@ -243,7 +244,20 @@ function installPlugin(item: IPicGoPlugin) { } async function buildContextMenu(plugin: IPicGoPlugin) { - picgoUtil.buildPluginMenu(plugin) + picgoUtil.buildPluginMenu(plugin, _getI18nMessage) +} + +function _getI18nMessage(key: PicgoPageMenuType) { + const retArr = [] + switch (key) { + case PicgoPageMenuType.PicgoPageMenuType_Uninstall: + retArr["setting.picgo.plugin.uninstall"] = t( + "setting.picgo.plugin.uninstall" + ) + break + } + + return retArr } function _getSearchResult(val: string) { @@ -342,6 +356,8 @@ onBeforeMount(() => { const body = data.rawArgs.body const success = data.rawArgs.success + const errMsg = data.rawArgs.errMsg + pluginData.pluginList.forEach((item) => { if (item.fullName === body) { item.ing = false @@ -351,6 +367,56 @@ onBeforeMount(() => { if (success) { ElMessage.success(t("setting.picgo.plugin.install.success")) + } else { + ElMessage.error(errMsg) + } + }) + + picgoUtil.ipcRegisterEvent("picgoHandlePluginIng", (evt, data) => { + const fullName: string = data.rawArgs + + pluginData.pluginList.forEach((item) => { + if (item.fullName === fullName || item.name === fullName) { + item.ing = true + } + }) + loading.value = true + }) + + picgoUtil.ipcRegisterEvent("uninstallSuccess", (evt, data) => { + loading.value = false + logger.info( + "PicgoPluginSetting接收到installPluginFinished事件,data=>", + data + ) + + const fullName = data.rawArgs.body + const success = data.rawArgs.success + const errMsg = data.rawArgs.errMsg + + pluginData.pluginList = pluginData.pluginList.filter((item) => { + if (item.fullName === fullName) { + // restore Uploader & Transformer after uninstalling + if (item.config.transformer.name) { + alert("handle transformer") + // handleRestoreState('transformer', item.config.transformer.name) + } + if (item.config.uploader.name) { + alert("handle uploader") + // handleRestoreState('uploader', item.config.uploader.name) + } + // getPicBeds() + } + return item.fullName !== fullName + }) + pluginData.pluginNameList = pluginData.pluginNameList.filter( + (item) => item !== fullName + ) + + if (success) { + ElMessage.success(t("setting.picgo.plugin.install.success")) + } else { + ElMessage.error(errMsg) } }) diff --git a/locales/en_US.ts b/locales/en_US.ts index 0e6f9289..1182f419 100644 --- a/locales/en_US.ts +++ b/locales/en_US.ts @@ -478,4 +478,5 @@ export default { "setting.picgo.plugin.install.success": "The plug -in has been successfully installed, please clear the search keyword refresh list. Click the plug -in corresponding [Settings] icon to view the plug -in details and customize the plug -in", "syp.about": "About me", + "setting.picgo.plugin.uninstall": "Uninstall plugin", } diff --git a/locales/zh_CN.ts b/locales/zh_CN.ts index 3e0cf562..18cd5226 100644 --- a/locales/zh_CN.ts +++ b/locales/zh_CN.ts @@ -477,4 +477,5 @@ export default { "setting.picgo.plugin.install.success": "插件已经成功安装,请清除搜索关键字刷新列表。点击插件对应【设置】图标可查看插件详情,并对插件进行自定义设置。如果是图床扩展,请关闭重新打开,然后启用图床并进行设置。", "syp.about": "关于作者", + "setting.picgo.plugin.uninstall": "卸载插件", } diff --git a/public/lib/siyuan/publish-helper.js b/public/lib/siyuan/publish-helper.js index 4dbc87d4..39b04d77 100644 --- a/public/lib/siyuan/publish-helper.js +++ b/public/lib/siyuan/publish-helper.js @@ -98,8 +98,14 @@ const initPublishHelper = () => { * @param pageId 文章ID * @param pageUrl 页面地址 * @param mainWin 可选(打开此页面的Window对象) + * @param isDev 可选(是否调试模式) */ - window.syp.renderPublishHelper = (pageId, pageUrl, mainWin = window) => { + window.syp.renderPublishHelper = ( + pageId, + pageUrl, + mainWin = window, + isDev = false + ) => { const { app, BrowserWindow, getCurrentWindow } = mainWin.require("@electron/remote") const remote = mainWin @@ -261,7 +267,9 @@ const initPublishHelper = () => { { content: html }, (response) => { newWin.loadURL(response.data.url) - // newWin.webContents.openDevTools() + if (isDev) { + newWin.webContents.openDevTools() + } } ) }) diff --git a/scripts/scriptutils.py b/scripts/scriptutils.py index 620bce0a..597814d0 100644 --- a/scripts/scriptutils.py +++ b/scripts/scriptutils.py @@ -28,6 +28,7 @@ import pathlib import shutil import sys +import time import zipfile from distutils import dir_util from distutils import file_util @@ -211,3 +212,14 @@ def iter_subtree(path, layer=0): iter_subtree(root_path) zipf.close() + +def get_filename_from_time(): + """ + 根据时间命名文件 + :return: 根据时间生成的名称 + """ + # 获取当前的时间 + now_time = time.localtime() + # 使用strftime函数把时间转换成想要的格式 + filename = time.strftime("%Y%m%d%H%M%S", now_time) # 输出结果为:20210126095555 + return filename \ No newline at end of file diff --git a/utils/otherlib/picgoUtil.js b/utils/otherlib/picgoUtil.js index f6126c7c..32314caa 100644 --- a/utils/otherlib/picgoUtil.js +++ b/utils/otherlib/picgoUtil.js @@ -28,6 +28,7 @@ import { isInSiyuanOrSiyuanNewWin } from "~/utils/platform/siyuan/siyuanUtil" import idUtil from "~/utils/idUtil" import strUtil from "~/utils/strUtil" import siyuanBrowserUtil from "~/utils/otherlib/siyuanBrowserUtil" +import { PicgoPageMenuType } from "~/utils/platform/picgo/picgoPlugin" // Pico上传Api封装 const picGoUploadApi = new PicGoUploadApi() @@ -463,24 +464,28 @@ const ipcRegisterEvent = (channel, data = {}) => { * 构建插件菜单 * * @param plugin 插件对象 - * + * @param i18nFunc 获取国际化资源的回调 * @author terwer * @since 0.7.0 */ -const buildPluginMenu = (plugin) => { +const buildPluginMenu = (plugin, i18nFunc) => { // 根据插件构造菜单 const syWin = siyuanBrowserUtil.getSiyuanWindow() - const template = [ - { - label: "卸载插件", - click() { - // const window = windowManager.get(IWindowList.SETTING_WINDOW)! - // window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName) - // picgoCoreIPC.handlePluginUninstall(plugin.fullName) - alert("卸载插件") - }, + const template = [] + + // 卸载插件菜单 + const uninstallI18n = i18nFunc(PicgoPageMenuType.PicgoPageMenuType_Uninstall) + const uninstallItem = { + label: uninstallI18n["setting.picgo.plugin.uninstall"], + click() { + // 卸载中事件 + ipcHandleEvent("picgoHandlePluginIng", plugin.fullName) + // 处理卸载事件 + ipcHandleEvent("uninstallPlugin", plugin.fullName) }, - ] + } + template.push(uninstallItem) + const menu = syWin.syp.buildMenu(template, syWin) // 显示菜单 diff --git a/utils/otherlib/siyuanBrowserUtil.js b/utils/otherlib/siyuanBrowserUtil.js index 83e5aeb2..4e762197 100644 --- a/utils/otherlib/siyuanBrowserUtil.js +++ b/utils/otherlib/siyuanBrowserUtil.js @@ -27,6 +27,7 @@ import { ElMessage } from "element-plus" import { isInSiyuanWidget } from "~/utils/platform/siyuan/siyuanUtil" +import envUtil from "~/utils/envUtil" /** * 是否在思源浏览器 @@ -76,7 +77,7 @@ export const doOpenExportWin = async (pageId, pageUrl) => { if (syWin.syp && syWin.syp.renderPublishHelper) { // 打开弹窗 - syWin.syp.renderPublishHelper(pageId, pageUrl, syWin) + syWin.syp.renderPublishHelper(pageId, pageUrl, syWin, envUtil.isDev) } else { ElMessage.warning( "renderPublishHelper失败,未找到hook方法,请在自定义js片段添加 import('/widgets/sy-post-publisher/lib/siyuanhook.js') ,并重启思源笔记" diff --git a/utils/platform/picgo/picgoPlugin.ts b/utils/platform/picgo/picgoPlugin.ts new file mode 100644 index 00000000..ed102d25 --- /dev/null +++ b/utils/platform/picgo/picgoPlugin.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +/** + * PicGO菜单类型通用枚举 + */ +export enum PicgoPageMenuType { + PicgoPageMenuType_Uninstall = "uninstall", +}