Added: plugin install & uninstall handler

This commit is contained in:
Molunerfinn
2018-10-09 17:01:33 +08:00
parent dc1ba57a97
commit 13c63ba66d
3 changed files with 69 additions and 32 deletions

View File

@@ -35,6 +35,7 @@ const handleConfigWithFunction = config => {
const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
ipcMain.on('getPluginList', event => {
console.log(CONFIG_PATH)
const picgo = new PicGo(CONFIG_PATH)
const pluginList = picgo.pluginLoader.getList()
const list = []
@@ -76,8 +77,8 @@ 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)
picgo.on('installSuccess', notice => {
event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
})
pluginHandler.install([`picgo-plugin-${msg}`])
})
@@ -87,9 +88,8 @@ const handlePluginUninstall = (ipcMain, STORE_PATH, CONFIG_PATH) => {
ipcMain.on('uninstallPlugin', (event, msg) => {
const picgo = new PicGo(CONFIG_PATH)
const pluginHandler = new PluginHandler(picgo)
console.log(msg, 123)
picgo.on('uninstallSuccess', (plugin) => {
console.log(plugin)
picgo.on('uninstallSuccess', notice => {
event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
})
pluginHandler.uninstall([`picgo-plugin-${msg}`])
})

View File

@@ -31,18 +31,27 @@
</span>
<span class="plugin-item__config" >
<template v-if="searchText">
<span class="config-button install" v-if="!item.hasInstall" @click="installPlugin(item.name)">
安装
</span>
<template v-if="!item.hasInstall">
<span class="config-button install" v-if="!item.installing" @click="installPlugin(item)">
安装
</span>
<span v-else="item.installing" class="config-button installing">
安装中
</span>
<span class="config-button reload" v-if="item.reload" @click="reloadApp">
重启
</span>
</template>
</template>
<template v-else>
<span class="config-button" v-if="item.reload" @click="reloadApp">
重启
</span>
<i
class="el-icon-setting"
@click="buildContextMenu(item)"
></i>
</template>
<i
v-else
class="el-icon-setting"
@click="buildContextMenu(item)"
></i>
</span>
</div>
</div>
@@ -115,6 +124,24 @@ export default {
this.pluginNameList = list.map(item => item.name)
this.loading = false
})
this.$electron.ipcRenderer.on('installSuccess', (evt, plugin) => {
this.loading = false
this.pluginList.forEach(item => {
if (item.name === plugin) {
item.installing = false
item.reload = true
}
})
})
this.$electron.ipcRenderer.on('uninstallSuccess', (evt, plugin) => {
this.loading = false
this.pluginList.forEach(item => {
if (item.name === plugin) {
item.reload = true
item.hasInstall = false
}
})
})
this.getPluginList()
this.getSearchResult = debounce(this.getSearchResult, 250)
},
@@ -164,8 +191,9 @@ export default {
getPluginList () {
this.$electron.ipcRenderer.send('getPluginList')
},
installPlugin (val) {
this.$electron.ipcRenderer.send('installPlugin', val)
installPlugin (item) {
item.installing = true
this.$electron.ipcRenderer.send('installPlugin', item.name)
},
uninstallPlugin (val) {
this.$electron.ipcRenderer.send('uninstallPlugin', val)
@@ -204,7 +232,6 @@ export default {
getSearchResult: function (val) {
this.$http.get(`https://api.npms.io/v2/search?q=${val}`)
.then(res => {
console.log(res.data.results)
this.pluginList = res.data.results.map(item => {
return this.handleSearchResult(item)
})
@@ -223,7 +250,7 @@ export default {
logo: `https://cdn.jsdelivr.net/npm/${item.package.name}/logo.png`,
config: {},
homepage: item.package.links ? item.package.links.homepage : '',
hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name),
hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name.replace(/picgo-plugin-/, '')),
installing: false,
reload: false
}
@@ -321,9 +348,13 @@ export default {
top 4px
right 20px
transition all .2s ease-in-out
&:hover
background: #1B9EF3
color #fff
&.reload
right 0px
&.installing
right 0px
&.install
right 0px
&:hover
background: #1B9EF3
color #fff
</style>

View File

@@ -2063,9 +2063,9 @@ combine-lists@^1.0.0:
dependencies:
lodash "^4.5.0"
combined-stream@1.0.6, combined-stream@~1.0.6:
combined-stream@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818"
resolved "http://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818"
dependencies:
delayed-stream "~1.0.0"
@@ -2075,6 +2075,12 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
dependencies:
delayed-stream "~1.0.0"
combined-stream@~1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.7.tgz#2d1d24317afb8abe95d6d2c0b07b57813539d828"
dependencies:
delayed-stream "~1.0.0"
commander@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/commander/-/commander-1.0.4.tgz#5edeb1aee23c4fb541a6b70d692abef19669a2d3"
@@ -2098,8 +2104,8 @@ commander@2.9.0, commander@2.9.x, commander@~2.9.0:
graceful-readlink ">= 1.0.0"
commander@^2.17.0:
version "2.18.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.18.0.tgz#2bf063ddee7c7891176981a2cc798e5754bc6970"
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
commondir@^1.0.1:
version "1.0.1"
@@ -2553,8 +2559,8 @@ dateformat@^3.0.3:
resolved "http://registry.npm.taobao.org/dateformat/download/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
dayjs@^1.7.4:
version "1.7.5"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.7.5.tgz#14715cb565d1f8cb556a8531cb14bf1fc33067cc"
version "1.7.7"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.7.7.tgz#8df20f78ac2476e3f5348ef49f8f22ebc3016370"
de-indent@^1.0.2:
version "1.0.2"
@@ -2617,8 +2623,8 @@ deepmerge@^1.2.0:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753"
deepmerge@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.1.1.tgz#e862b4e45ea0555072bf51e7fd0d9845170ae768"
version "2.2.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
deepmerge@~2.0.1:
version "2.0.1"
@@ -6195,8 +6201,8 @@ performance-now@^2.1.0:
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
picgo@^1.1.8:
version "1.1.8"
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.1.8.tgz#0a2bc8b71b8783c5bf7046802f55e9254277a6e1"
version "1.1.9"
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.1.9.tgz#0fb495a49f83fee759391966aca7dc0d6e8feac9"
dependencies:
chalk "^2.4.1"
commander "^2.17.0"
@@ -7318,8 +7324,8 @@ rx-lite@*, rx-lite@^4.0.8:
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"
rxjs@^6.1.0:
version "6.3.2"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.2.tgz#6a688b16c4e6e980e62ea805ec30648e1c60907f"
version "6.3.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz#3c6a7fa420e844a81390fb1158a9ec614f4bad55"
dependencies:
tslib "^1.9.0"