Skip to content

Commit

Permalink
feat: #319 PicGO图形化配置界面-插件卸载
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Feb 17, 2023
1 parent 8b4d5d8 commit 65b078d
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 16 deletions.
68 changes: 67 additions & 1 deletion components/picgo/setting/PicgoPluginSetting.vue
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
})
Expand Down
1 change: 1 addition & 0 deletions locales/en_US.ts
Expand Up @@ -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",
}
1 change: 1 addition & 0 deletions locales/zh_CN.ts
Expand Up @@ -477,4 +477,5 @@ export default {
"setting.picgo.plugin.install.success":
"插件已经成功安装,请清除搜索关键字刷新列表。点击插件对应【设置】图标可查看插件详情,并对插件进行自定义设置。如果是图床扩展,请关闭重新打开,然后启用图床并进行设置。",
"syp.about": "关于作者",
"setting.picgo.plugin.uninstall": "卸载插件",
}
12 changes: 10 additions & 2 deletions public/lib/siyuan/publish-helper.js
Expand Up @@ -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
Expand Down Expand Up @@ -261,7 +267,9 @@ const initPublishHelper = () => {
{ content: html },
(response) => {
newWin.loadURL(response.data.url)
// newWin.webContents.openDevTools()
if (isDev) {
newWin.webContents.openDevTools()
}
}
)
})
Expand Down
12 changes: 12 additions & 0 deletions scripts/scriptutils.py
Expand Up @@ -28,6 +28,7 @@
import pathlib
import shutil
import sys
import time
import zipfile
from distutils import dir_util
from distutils import file_util
Expand Down Expand Up @@ -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
29 changes: 17 additions & 12 deletions utils/otherlib/picgoUtil.js
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

// 显示菜单
Expand Down
3 changes: 2 additions & 1 deletion utils/otherlib/siyuanBrowserUtil.js
Expand Up @@ -27,6 +27,7 @@

import { ElMessage } from "element-plus"
import { isInSiyuanWidget } from "~/utils/platform/siyuan/siyuanUtil"
import envUtil from "~/utils/envUtil"

/**
* 是否在思源浏览器
Expand Down Expand Up @@ -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') ,并重启思源笔记"
Expand Down
31 changes: 31 additions & 0 deletions 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",
}

0 comments on commit 65b078d

Please sign in to comment.