mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
Added: picgo-core-ipc & fixed dynamic require bug in picgo
This commit is contained in:
parent
cb32d43be4
commit
aea0c3661d
@ -7,6 +7,7 @@ import pasteTemplate from './utils/pasteTemplate'
|
||||
import updateChecker from './utils/updateChecker'
|
||||
import pkg from '../../package.json'
|
||||
import picBed from '../datastore/pic-bed'
|
||||
import picgoCoreIPC from './utils/picgoCoreIPC'
|
||||
/**
|
||||
* Set `__static` path to static files in production
|
||||
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
||||
@ -255,7 +256,8 @@ const createSettingWindow = () => {
|
||||
transparent: true,
|
||||
titleBarStyle: 'hidden',
|
||||
webPreferences: {
|
||||
backgroundThrottling: false
|
||||
backgroundThrottling: false,
|
||||
webSecurity: false
|
||||
}
|
||||
}
|
||||
if (process.platform !== 'darwin') {
|
||||
@ -398,6 +400,8 @@ const updateDefaultPicBed = () => {
|
||||
}
|
||||
}
|
||||
|
||||
picgoCoreIPC(app, ipcMain)
|
||||
|
||||
ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
||||
const img = await uploader(file, 'imgFromClipboard', window.webContents)
|
||||
if (img !== false) {
|
||||
|
32
src/main/utils/picgoCoreIPC.js
Normal file
32
src/main/utils/picgoCoreIPC.js
Normal file
@ -0,0 +1,32 @@
|
||||
import path from 'path'
|
||||
|
||||
// eslint-disable-next-line
|
||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||
const PicGo = requireFunc('picgo')
|
||||
|
||||
export default (app, ipcMain) => {
|
||||
const STORE_PATH = app.getPath('userData')
|
||||
const CONFIG_PATH = path.join(STORE_PATH, '/data.json')
|
||||
const picgo = new PicGo(CONFIG_PATH)
|
||||
|
||||
ipcMain.on('getPluginList', event => {
|
||||
const pluginList = picgo.pluginLoader.getList()
|
||||
const list = []
|
||||
for (let i in pluginList) {
|
||||
const pluginPath = path.join(STORE_PATH, `/node_modules/${pluginList[i]}`)
|
||||
const pluginPKG = requireFunc(path.join(pluginPath, 'package.json'))
|
||||
const obj = {
|
||||
name: pluginList[i],
|
||||
author: pluginPKG.author,
|
||||
description: pluginPKG.description,
|
||||
logo: path.join(pluginPath, 'logo.png').split(path.sep).join('/'),
|
||||
config: {
|
||||
plugin: picgo.pluginLoader.getPlugin(pluginList[i]).config ? picgo.pluginLoader.getPlugin(pluginList[i]).config(picgo) : []
|
||||
},
|
||||
enabled: picgo.getConfig(`plugins.${pluginList[i]}`)
|
||||
}
|
||||
list.push(obj)
|
||||
}
|
||||
event.sender.send('pluginList', list)
|
||||
})
|
||||
}
|
@ -4,10 +4,13 @@ import {
|
||||
BrowserWindow,
|
||||
ipcMain
|
||||
} from 'electron'
|
||||
import PicGo from 'picgo'
|
||||
import path from 'path'
|
||||
import fecha from 'fecha'
|
||||
|
||||
// eslint-disable-next-line
|
||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||
const PicGo = requireFunc('picgo')
|
||||
|
||||
const renameURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080/#rename-page` : `file://${__dirname}/index.html#rename-page`
|
||||
|
||||
const createRenameWindow = () => {
|
||||
|
@ -10,33 +10,34 @@
|
||||
size="small"
|
||||
></el-input>
|
||||
</el-row>
|
||||
<el-row :gutter="20" class="plugin-list">
|
||||
<el-col :span="12">
|
||||
<el-row :gutter="10" class="plugin-list">
|
||||
<el-col :span="12" v-for="(item, index) in pluginList" :key="item.name">
|
||||
<div class="plugin-item">
|
||||
<img class="plugin-item__logo" src="https://user-images.githubusercontent.com/12621342/33876119-85a5148e-df5f-11e7-8843-46224e595d52.png">
|
||||
<img class="plugin-item__logo" :src="'file://' + item.logo">
|
||||
<div class="plugin-item__content">
|
||||
<div class="plugin-item__name">
|
||||
Uploader-SMMS2
|
||||
{{ item.name }}
|
||||
</div>
|
||||
<div class="plugin-item__desc">
|
||||
saldfjlsajf,ajsldfjasljfk,asmfjsalkfjsakfmasldfjlsajf,ajsfdljsalfjslafdj
|
||||
{{ item.description }}
|
||||
</div>
|
||||
<div class="plugin-item__info-bar">
|
||||
<span class="plugin-item__author">
|
||||
XXXXXXXX
|
||||
{{ item.author }}
|
||||
</span>
|
||||
<span class="plugin-item__config">
|
||||
<i class="el-icon-setting"></i>
|
||||
<span class="plugin-item__config" >
|
||||
<span class="reload-button" v-if="item.reload" @click="reloadApp">
|
||||
重启
|
||||
</span>
|
||||
<i
|
||||
class="el-icon-setting"
|
||||
@click="buildContextMenu(item)"
|
||||
></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<div class="plugin-item">
|
||||
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
@ -45,7 +46,54 @@ export default {
|
||||
name: 'plugin',
|
||||
data () {
|
||||
return {
|
||||
searchText: ''
|
||||
searchText: '',
|
||||
pluginList: [],
|
||||
menu: null
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.$electron.ipcRenderer.on('pluginList', (evt, list) => {
|
||||
this.pluginList = list.map(item => {
|
||||
item.reload = false
|
||||
return item
|
||||
})
|
||||
})
|
||||
this.getPluginList()
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.which === 123) {
|
||||
this.$electron.remote.getCurrentWindow().toggleDevTools()
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
buildContextMenu (plugin) {
|
||||
const _this = this
|
||||
let menu = [{
|
||||
label: '启用插件',
|
||||
enabled: !plugin.enabled,
|
||||
click () {
|
||||
_this.$db.read().set(`plugins.${plugin.name}`, true).write()
|
||||
plugin.enabled = true
|
||||
plugin.reload = true
|
||||
}
|
||||
}, {
|
||||
label: '禁用插件',
|
||||
enabled: plugin.enabled,
|
||||
click () {
|
||||
_this.$db.read().set(`plugins.${plugin.name}`, false).write()
|
||||
plugin.enabled = false
|
||||
plugin.reload = true
|
||||
}
|
||||
}]
|
||||
this.menu = this.$electron.remote.Menu.buildFromTemplate(menu)
|
||||
this.menu.popup(this.$electron.remote.getCurrentWindow())
|
||||
},
|
||||
getPluginList () {
|
||||
this.$electron.ipcRenderer.send('getPluginList')
|
||||
},
|
||||
reloadApp () {
|
||||
this.$electron.remote.app.relaunch()
|
||||
this.$electron.remote.app.exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,6 +118,7 @@ export default {
|
||||
user-select text
|
||||
transition all .2s ease-in-out
|
||||
cursor pointer
|
||||
margin-bottom 10px
|
||||
&:hover
|
||||
background #333
|
||||
&__logo
|
||||
@ -78,7 +127,7 @@ export default {
|
||||
float left
|
||||
&__content
|
||||
float left
|
||||
width calc(100% - 74px)
|
||||
width calc(100% - 72px)
|
||||
height 64px
|
||||
color #aaa
|
||||
margin-left 8px
|
||||
@ -100,6 +149,7 @@ export default {
|
||||
font-size 14px
|
||||
height 21px
|
||||
line-height 28px
|
||||
position relative
|
||||
&__author
|
||||
overflow hidden
|
||||
text-overflow ellipsis
|
||||
@ -107,4 +157,15 @@ export default {
|
||||
&__config
|
||||
float right
|
||||
font-size 16px
|
||||
.reload-button
|
||||
font-size 12px
|
||||
color #ddd
|
||||
background #222
|
||||
padding 1px 8px
|
||||
height 18px
|
||||
line-height 18px
|
||||
text-align center
|
||||
position absolute
|
||||
top 4px
|
||||
right 20px
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user