mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-07 08:26:57 +08:00
Added: plugin reload state in localstorage
This commit is contained in:
@@ -512,6 +512,8 @@ if (process.env.XDG_CURRENT_DESKTOP && process.env.XDG_CURRENT_DESKTOP.includes(
|
|||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
createWindow()
|
createWindow()
|
||||||
createSettingWindow()
|
createSettingWindow()
|
||||||
|
// reset localstorage state
|
||||||
|
settingWindow.webContents.executeJavaScript(`localStorage.setItem('plugins', '')`)
|
||||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
if (process.platform === 'darwin' || process.platform === 'win32') {
|
||||||
createTray()
|
createTray()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import ConfigForm from '@/components/ConfigForm'
|
import ConfigForm from '@/components/ConfigForm'
|
||||||
import { debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
|
import LS from '@/utils/LS'
|
||||||
export default {
|
export default {
|
||||||
name: 'plugin',
|
name: 'plugin',
|
||||||
components: {
|
components: {
|
||||||
@@ -119,9 +120,15 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
console.log(this.pluginState)
|
||||||
this.$electron.ipcRenderer.on('pluginList', (evt, list) => {
|
this.$electron.ipcRenderer.on('pluginList', (evt, list) => {
|
||||||
|
const plugins = LS.get('plugins')
|
||||||
this.pluginList = list.map(item => {
|
this.pluginList = list.map(item => {
|
||||||
item.reload = false
|
if (plugins && plugins[item.name] && plugins[item.name].reload) {
|
||||||
|
item.reload = true
|
||||||
|
} else {
|
||||||
|
item.reload = false
|
||||||
|
}
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
this.pluginNameList = list.map(item => item.name)
|
this.pluginNameList = list.map(item => item.name)
|
||||||
@@ -133,6 +140,7 @@ export default {
|
|||||||
if (item.name === plugin) {
|
if (item.name === plugin) {
|
||||||
item.installing = false
|
item.installing = false
|
||||||
item.reload = true
|
item.reload = true
|
||||||
|
this.handlePluginState(plugin, { reload: true })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -142,6 +150,7 @@ export default {
|
|||||||
if (item.name === plugin) {
|
if (item.name === plugin) {
|
||||||
item.reload = true
|
item.reload = true
|
||||||
item.hasInstall = false
|
item.hasInstall = false
|
||||||
|
this.handlePluginState(plugin, { reload: true })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -157,7 +166,8 @@ export default {
|
|||||||
click () {
|
click () {
|
||||||
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, true).write()
|
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, true).write()
|
||||||
plugin.enabled = true
|
plugin.enabled = true
|
||||||
// plugin.reload = true
|
plugin.reload = true
|
||||||
|
this.handlePluginState(plugin.name, { reload: true })
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
label: '禁用插件',
|
label: '禁用插件',
|
||||||
@@ -165,7 +175,8 @@ export default {
|
|||||||
click () {
|
click () {
|
||||||
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, false).write()
|
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, false).write()
|
||||||
plugin.enabled = false
|
plugin.enabled = false
|
||||||
// plugin.reload = true
|
plugin.reload = true
|
||||||
|
this.handlePluginState(plugin.name, { reload: true })
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
label: '卸载插件',
|
label: '卸载插件',
|
||||||
@@ -202,6 +213,7 @@ export default {
|
|||||||
this.$electron.ipcRenderer.send('uninstallPlugin', val)
|
this.$electron.ipcRenderer.send('uninstallPlugin', val)
|
||||||
},
|
},
|
||||||
reloadApp () {
|
reloadApp () {
|
||||||
|
LS.set('plugins', '')
|
||||||
this.$electron.remote.app.relaunch()
|
this.$electron.remote.app.relaunch()
|
||||||
this.$electron.remote.app.exit(0)
|
this.$electron.remote.app.exit(0)
|
||||||
},
|
},
|
||||||
@@ -247,8 +259,9 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleSearchResult (item) {
|
handleSearchResult (item) {
|
||||||
|
const name = item.package.name.replace(/picgo-plugin-/, '')
|
||||||
return {
|
return {
|
||||||
name: item.package.name.replace(/picgo-plugin-/, ''),
|
name: name,
|
||||||
author: item.package.author.name,
|
author: item.package.author.name,
|
||||||
description: item.package.description,
|
description: item.package.description,
|
||||||
logo: `https://cdn.jsdelivr.net/npm/${item.package.name}/logo.png`,
|
logo: `https://cdn.jsdelivr.net/npm/${item.package.name}/logo.png`,
|
||||||
@@ -259,6 +272,11 @@ export default {
|
|||||||
installing: false,
|
installing: false,
|
||||||
reload: false
|
reload: false
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
handlePluginState (name, state) {
|
||||||
|
const plugins = LS.get('plugins')
|
||||||
|
plugins[name] = state
|
||||||
|
LS.set('plugins', plugins)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
class LS {
|
||||||
|
get (name) {
|
||||||
|
if (localStorage.getItem(name)) {
|
||||||
|
return JSON.parse(localStorage.getItem(name))
|
||||||
|
} else {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set (name, value) {
|
||||||
|
return localStorage.setItem(name, JSON.stringify(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new LS()
|
||||||
Reference in New Issue
Block a user