From 392af6c617f64fc256e601aea1d4df10487dd225 Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Fri, 28 Sep 2018 17:31:22 +0800 Subject: [PATCH] Added: plugin handler but with bugs --- package.json | 2 +- src/main/utils/picgoCoreIPC.js | 28 +++- .../components/SettingView/Plugin.vue | 123 +++++++++++++++--- yarn.lock | 6 +- 4 files changed, 130 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 30ee1b1..3c44511 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "lowdb": "^1.0.0", "md5": "^2.2.1", "melody.css": "^1.0.2", - "picgo": "^1.1.7", + "picgo": "^1.1.8", "qiniu": "^7.1.1", "request": "^2.83.0", "request-promise": "^4.2.2", diff --git a/src/main/utils/picgoCoreIPC.js b/src/main/utils/picgoCoreIPC.js index cbe2937..b0bc482 100644 --- a/src/main/utils/picgoCoreIPC.js +++ b/src/main/utils/picgoCoreIPC.js @@ -3,6 +3,7 @@ import path from 'path' // eslint-disable-next-line const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require const PicGo = requireFunc('picgo') +const PluginHandler = requireFunc('picgo/lib/PluginHandler') // get uploader or transformer config const getConfig = (name, type, ctx) => { @@ -32,10 +33,7 @@ const handleConfigWithFunction = config => { return config } -export default (app, ipcMain) => { - const STORE_PATH = app.getPath('userData') - const CONFIG_PATH = path.join(STORE_PATH, '/data.json') - +const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => { ipcMain.on('getPluginList', event => { const picgo = new PicGo(CONFIG_PATH) const pluginList = picgo.pluginLoader.getList() @@ -50,7 +48,7 @@ export default (app, ipcMain) => { name: pluginList[i].replace(/picgo-plugin-/, ''), author: pluginPKG.author, description: pluginPKG.description, - logo: path.join(pluginPath, 'logo.png').split(path.sep).join('/'), + logo: 'file://' + path.join(pluginPath, 'logo.png').split(path.sep).join('/'), config: { plugin: { name: pluginList[i].replace(/picgo-plugin-/, ''), @@ -66,10 +64,28 @@ export default (app, ipcMain) => { } }, enabled: picgo.getConfig(`plugins.${pluginList[i]}`), - pkg: pluginPKG + homepage: pluginPKG.homepage ? pluginPKG.homepage : '' } list.push(obj) } event.sender.send('pluginList', list) }) } + +const handlePluginInstall = (ipcMain, STORE_PATH, CONFIG_PATH) => { + ipcMain.on('installPlugin', (event, msg) => { + const picgo = new PicGo(CONFIG_PATH) + const pluginHandler = new PluginHandler(picgo) + picgo.on('installSuccess', (plugin) => { + console.log(plugin) + }) + pluginHandler.install([`picgo-plugin-${msg}`]) + }) +} + +export default (app, ipcMain) => { + const STORE_PATH = app.getPath('userData') + const CONFIG_PATH = path.join(STORE_PATH, '/data.json') + handleGetPluginList(ipcMain, STORE_PATH, CONFIG_PATH) + handlePluginInstall(ipcMain, STORE_PATH, CONFIG_PATH) +} diff --git a/src/renderer/components/SettingView/Plugin.vue b/src/renderer/components/SettingView/Plugin.vue index 0dc8cba..8518745 100644 --- a/src/renderer/components/SettingView/Plugin.vue +++ b/src/renderer/components/SettingView/Plugin.vue @@ -3,17 +3,21 @@
插件设置
- + + > + + - +
- +
{{ item.name }} @@ -26,10 +30,16 @@ {{ item.author }} - + @@ -61,6 +71,7 @@ \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index df01859..e4fc5c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6194,9 +6194,9 @@ performance-now@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" -picgo@^1.1.7: - version "1.1.7" - resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.1.7.tgz#04e6e9a4fdd97a7f1efc8cfc75ad869610f7c120" +picgo@^1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.1.8.tgz#0a2bc8b71b8783c5bf7046802f55e9254277a6e1" dependencies: chalk "^2.4.1" commander "^2.17.0"