mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-08 21:38:13 -05:00
🔨 Refactor: plugin name -> fullName to support scope packages
This commit is contained in:
parent
064f37d1a6
commit
2129f86266
@ -11,6 +11,7 @@ import PicGoCore from '~/universal/types/picgo'
|
|||||||
import { IPicGoHelperType } from '#/types/enum'
|
import { IPicGoHelperType } from '#/types/enum'
|
||||||
import shortKeyHandler from '../apis/app/shortKey/shortKeyHandler'
|
import shortKeyHandler from '../apis/app/shortKey/shortKeyHandler'
|
||||||
import picgo from '@core/picgo'
|
import picgo from '@core/picgo'
|
||||||
|
import { handleStreamlinePluginName } from '~/universal/utils/common'
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
|
||||||
@ -77,7 +78,8 @@ const handleGetPluginList = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const obj: IPicGoPlugin = {
|
const obj: IPicGoPlugin = {
|
||||||
name: pluginList[i].replace(/picgo-plugin-/, ''),
|
name: handleStreamlinePluginName(pluginList[i]),
|
||||||
|
fullName: pluginList[i],
|
||||||
author: pluginPKG.author.name || pluginPKG.author,
|
author: pluginPKG.author.name || pluginPKG.author,
|
||||||
description: pluginPKG.description,
|
description: pluginPKG.description,
|
||||||
logo: 'file://' + path.join(pluginPath, 'logo.png').split(path.sep).join('/'),
|
logo: 'file://' + path.join(pluginPath, 'logo.png').split(path.sep).join('/'),
|
||||||
@ -85,7 +87,8 @@ const handleGetPluginList = () => {
|
|||||||
gui,
|
gui,
|
||||||
config: {
|
config: {
|
||||||
plugin: {
|
plugin: {
|
||||||
name: pluginList[i].replace(/picgo-plugin-/, ''),
|
fullName: pluginList[i],
|
||||||
|
name: handleStreamlinePluginName(pluginList[i]),
|
||||||
config: plugin.config ? handleConfigWithFunction(plugin.config(picgo)) : []
|
config: plugin.config ? handleConfigWithFunction(plugin.config(picgo)) : []
|
||||||
},
|
},
|
||||||
uploader: {
|
uploader: {
|
||||||
@ -113,7 +116,7 @@ const handlePluginInstall = () => {
|
|||||||
ipcMain.on('installPlugin', async (event: IpcMainEvent, msg: string) => {
|
ipcMain.on('installPlugin', async (event: IpcMainEvent, msg: string) => {
|
||||||
const dispose = handleNPMError()
|
const dispose = handleNPMError()
|
||||||
picgo.once('installSuccess', (notice: PicGoNotice) => {
|
picgo.once('installSuccess', (notice: PicGoNotice) => {
|
||||||
event.sender.send('installSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
|
event.sender.send('installSuccess', notice.body[0])
|
||||||
shortKeyHandler.registerPluginShortKey(notice.body[0])
|
shortKeyHandler.registerPluginShortKey(notice.body[0])
|
||||||
picgo.removeAllListeners('installFailed')
|
picgo.removeAllListeners('installFailed')
|
||||||
dispose()
|
dispose()
|
||||||
@ -131,7 +134,7 @@ const handlePluginUninstall = () => {
|
|||||||
ipcMain.on('uninstallPlugin', async (event: IpcMainEvent, msg: string) => {
|
ipcMain.on('uninstallPlugin', async (event: IpcMainEvent, msg: string) => {
|
||||||
const dispose = handleNPMError()
|
const dispose = handleNPMError()
|
||||||
picgo.once('uninstallSuccess', (notice: PicGoNotice) => {
|
picgo.once('uninstallSuccess', (notice: PicGoNotice) => {
|
||||||
event.sender.send('uninstallSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
|
event.sender.send('uninstallSuccess', notice.body[0])
|
||||||
shortKeyHandler.unregisterPluginShortKey(notice.body[0])
|
shortKeyHandler.unregisterPluginShortKey(notice.body[0])
|
||||||
picgo.removeAllListeners('uninstallFailed')
|
picgo.removeAllListeners('uninstallFailed')
|
||||||
dispose()
|
dispose()
|
||||||
@ -149,7 +152,7 @@ const handlePluginUpdate = () => {
|
|||||||
ipcMain.on('updatePlugin', async (event: IpcMainEvent, msg: string) => {
|
ipcMain.on('updatePlugin', async (event: IpcMainEvent, msg: string) => {
|
||||||
const dispose = handleNPMError()
|
const dispose = handleNPMError()
|
||||||
picgo.once('updateSuccess', (notice: { body: string[], title: string }) => {
|
picgo.once('updateSuccess', (notice: { body: string[], title: string }) => {
|
||||||
event.sender.send('updateSuccess', notice.body[0].replace(/picgo-plugin-/, ''))
|
event.sender.send('updateSuccess', notice.body[0])
|
||||||
picgo.removeAllListeners('updateFailed')
|
picgo.removeAllListeners('updateFailed')
|
||||||
dispose()
|
dispose()
|
||||||
})
|
})
|
||||||
@ -195,7 +198,7 @@ const handleGetPicBedConfig = () => {
|
|||||||
|
|
||||||
const handlePluginActions = () => {
|
const handlePluginActions = () => {
|
||||||
ipcMain.on('pluginActions', (event: IpcMainEvent, name: string, label: string) => {
|
ipcMain.on('pluginActions', (event: IpcMainEvent, name: string, label: string) => {
|
||||||
const plugin = picgo.pluginLoader.getPlugin(`picgo-plugin-${name}`)
|
const plugin = picgo.pluginLoader.getPlugin(name)
|
||||||
const guiApi = new GuiApi()
|
const guiApi = new GuiApi()
|
||||||
if (plugin.guiMenu && plugin.guiMenu(picgo).length > 0) {
|
if (plugin.guiMenu && plugin.guiMenu(picgo).length > 0) {
|
||||||
const menu: GuiMenuItem[] = plugin.guiMenu(picgo)
|
const menu: GuiMenuItem[] = plugin.guiMenu(picgo)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
</el-input>
|
</el-input>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row :gutter="10" class="plugin-list" v-loading="loading">
|
<el-row :gutter="10" class="plugin-list" v-loading="loading">
|
||||||
<el-col :span="12" v-for="item in pluginList" :key="item.name">
|
<el-col :span="12" v-for="item in pluginList" :key="item.fullName">
|
||||||
<div class="plugin-item" :class="{ 'darwin': os === 'darwin' }">
|
<div class="plugin-item" :class="{ 'darwin': os === 'darwin' }">
|
||||||
<div class="cli-only-badge" v-if="!item.gui" title="CLI only">CLI</div>
|
<div class="cli-only-badge" v-if="!item.gui" title="CLI only">CLI</div>
|
||||||
<img class="plugin-item__logo" :src="item.logo"
|
<img class="plugin-item__logo" :src="item.logo"
|
||||||
@ -106,6 +106,7 @@ import {
|
|||||||
remote,
|
remote,
|
||||||
IpcRendererEvent
|
IpcRendererEvent
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
|
import { handleStreamlinePluginName } from '~/universal/utils/common'
|
||||||
const { Menu } = remote
|
const { Menu } = remote
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -159,13 +160,13 @@ export default class extends Vue {
|
|||||||
this.os = process.platform
|
this.os = process.platform
|
||||||
ipcRenderer.on('pluginList', (evt: IpcRendererEvent, list: IPicGoPlugin[]) => {
|
ipcRenderer.on('pluginList', (evt: IpcRendererEvent, list: IPicGoPlugin[]) => {
|
||||||
this.pluginList = list
|
this.pluginList = list
|
||||||
this.pluginNameList = list.map(item => item.name)
|
this.pluginNameList = list.map(item => item.fullName)
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
ipcRenderer.on('installSuccess', (evt: IpcRendererEvent, plugin: string) => {
|
ipcRenderer.on('installSuccess', (evt: IpcRendererEvent, plugin: string) => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.pluginList.forEach(item => {
|
this.pluginList.forEach(item => {
|
||||||
if (item.name === plugin) {
|
if (item.fullName === plugin) {
|
||||||
item.ing = false
|
item.ing = false
|
||||||
item.hasInstall = true
|
item.hasInstall = true
|
||||||
}
|
}
|
||||||
@ -174,7 +175,7 @@ export default class extends Vue {
|
|||||||
ipcRenderer.on('updateSuccess', (evt: IpcRendererEvent, plugin: string) => {
|
ipcRenderer.on('updateSuccess', (evt: IpcRendererEvent, plugin: string) => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.pluginList.forEach(item => {
|
this.pluginList.forEach(item => {
|
||||||
if (item.name === plugin) {
|
if (item.fullName === plugin) {
|
||||||
item.ing = false
|
item.ing = false
|
||||||
item.hasInstall = true
|
item.hasInstall = true
|
||||||
}
|
}
|
||||||
@ -186,7 +187,7 @@ export default class extends Vue {
|
|||||||
ipcRenderer.on('uninstallSuccess', (evt: IpcRendererEvent, plugin: string) => {
|
ipcRenderer.on('uninstallSuccess', (evt: IpcRendererEvent, plugin: string) => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.pluginList = this.pluginList.filter(item => {
|
this.pluginList = this.pluginList.filter(item => {
|
||||||
if (item.name === plugin) { // restore Uploader & Transformer after uninstalling
|
if (item.fullName === plugin) { // restore Uploader & Transformer after uninstalling
|
||||||
if (item.config.transformer.name) {
|
if (item.config.transformer.name) {
|
||||||
this.handleRestoreState('transformer', item.config.transformer.name)
|
this.handleRestoreState('transformer', item.config.transformer.name)
|
||||||
}
|
}
|
||||||
@ -195,7 +196,7 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
this.getPicBeds()
|
this.getPicBeds()
|
||||||
}
|
}
|
||||||
return item.name !== plugin
|
return item.fullName !== plugin
|
||||||
})
|
})
|
||||||
this.pluginNameList = this.pluginNameList.filter(item => item !== plugin)
|
this.pluginNameList = this.pluginNameList.filter(item => item !== plugin)
|
||||||
})
|
})
|
||||||
@ -210,7 +211,7 @@ export default class extends Vue {
|
|||||||
enabled: !plugin.enabled,
|
enabled: !plugin.enabled,
|
||||||
click () {
|
click () {
|
||||||
_this.letPicGoSaveData({
|
_this.letPicGoSaveData({
|
||||||
[`picgoPlugins.picgo-plugin-${plugin.name}`]: true
|
[`picgoPlugins.${plugin.fullName}`]: true
|
||||||
})
|
})
|
||||||
plugin.enabled = true
|
plugin.enabled = true
|
||||||
_this.getPicBeds()
|
_this.getPicBeds()
|
||||||
@ -220,7 +221,7 @@ export default class extends Vue {
|
|||||||
enabled: plugin.enabled,
|
enabled: plugin.enabled,
|
||||||
click () {
|
click () {
|
||||||
_this.letPicGoSaveData({
|
_this.letPicGoSaveData({
|
||||||
[`picgoPlugins.picgo-plugin-${plugin.name}`]: false
|
[`picgoPlugins.${plugin.fullName}`]: false
|
||||||
})
|
})
|
||||||
plugin.enabled = false
|
plugin.enabled = false
|
||||||
_this.getPicBeds()
|
_this.getPicBeds()
|
||||||
@ -234,21 +235,21 @@ export default class extends Vue {
|
|||||||
}, {
|
}, {
|
||||||
label: '卸载插件',
|
label: '卸载插件',
|
||||||
click () {
|
click () {
|
||||||
_this.uninstallPlugin(plugin.name)
|
_this.uninstallPlugin(plugin.fullName)
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
label: '更新插件',
|
label: '更新插件',
|
||||||
click () {
|
click () {
|
||||||
_this.updatePlugin(plugin.name)
|
_this.updatePlugin(plugin.fullName)
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
for (let i in plugin.config) {
|
for (let i in plugin.config) {
|
||||||
if (plugin.config[i].config.length > 0) {
|
if (plugin.config[i].config.length > 0) {
|
||||||
const obj = {
|
const obj = {
|
||||||
label: `配置${i} - ${plugin.config[i].name}`,
|
label: `配置${i} - ${plugin.config[i].fullName || plugin.config[i].name}`,
|
||||||
click () {
|
click () {
|
||||||
_this.currentType = i
|
_this.currentType = i
|
||||||
_this.configName = plugin.config[i].name
|
_this.configName = plugin.config[i].fullName || plugin.config[i].name
|
||||||
_this.dialogVisible = true
|
_this.dialogVisible = true
|
||||||
_this.config = plugin.config[i].config
|
_this.config = plugin.config[i].config
|
||||||
}
|
}
|
||||||
@ -280,7 +281,7 @@ export default class extends Vue {
|
|||||||
menu.push({
|
menu.push({
|
||||||
label: i.label,
|
label: i.label,
|
||||||
click () {
|
click () {
|
||||||
ipcRenderer.send('pluginActions', plugin.name, i.label)
|
ipcRenderer.send('pluginActions', plugin.fullName, i.label)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -322,7 +323,7 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
updatePlugin (val: string) {
|
updatePlugin (val: string) {
|
||||||
this.pluginList.forEach(item => {
|
this.pluginList.forEach(item => {
|
||||||
if (item.name === val) {
|
if (item.fullName === val) {
|
||||||
item.ing = true
|
item.ing = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -364,7 +365,7 @@ export default class extends Vue {
|
|||||||
switch (this.currentType) {
|
switch (this.currentType) {
|
||||||
case 'plugin':
|
case 'plugin':
|
||||||
this.letPicGoSaveData({
|
this.letPicGoSaveData({
|
||||||
[`picgo-plugin-${this.configName}`]: result
|
[`${this.configName}`]: result
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'uploader':
|
case 'uploader':
|
||||||
@ -407,7 +408,7 @@ export default class extends Vue {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
handleSearchResult (item: INPMSearchResultObject) {
|
handleSearchResult (item: INPMSearchResultObject) {
|
||||||
const name = item.package.name.replace(/picgo-plugin-/, '')
|
const name = handleStreamlinePluginName(item.package.name)
|
||||||
let gui = false
|
let gui = false
|
||||||
if (item.package.keywords && item.package.keywords.length > 0) {
|
if (item.package.keywords && item.package.keywords.length > 0) {
|
||||||
if (item.package.keywords.includes('picgo-gui-plugin')) {
|
if (item.package.keywords.includes('picgo-gui-plugin')) {
|
||||||
@ -416,12 +417,13 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name: name,
|
name: name,
|
||||||
|
fullName: item.package.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`,
|
||||||
config: {},
|
config: {},
|
||||||
homepage: item.package.links ? item.package.links.homepage : '',
|
homepage: item.package.links ? item.package.links.homepage : '',
|
||||||
hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name.replace(/picgo-plugin-/, '')),
|
hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name),
|
||||||
version: item.package.version,
|
version: item.package.version,
|
||||||
gui,
|
gui,
|
||||||
ing: false // installing or uninstalling
|
ing: false // installing or uninstalling
|
||||||
|
2
src/universal/types/types.d.ts
vendored
2
src/universal/types/types.d.ts
vendored
@ -123,6 +123,7 @@ interface IBounds {
|
|||||||
type ICtx = import('picgo')
|
type ICtx = import('picgo')
|
||||||
interface IPicGoPlugin {
|
interface IPicGoPlugin {
|
||||||
name: string
|
name: string
|
||||||
|
fullName: string
|
||||||
author: string
|
author: string
|
||||||
description: string
|
description: string
|
||||||
logo: string
|
logo: string
|
||||||
@ -145,6 +146,7 @@ interface IPicGoPlugin {
|
|||||||
|
|
||||||
interface IPluginMenuConfig {
|
interface IPluginMenuConfig {
|
||||||
name: string
|
name: string
|
||||||
|
fullName?: string
|
||||||
config: any[]
|
config: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,3 +15,18 @@ export const handleUrlEncode = (url: string): string => {
|
|||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* streamline the full plugin name to a simple one
|
||||||
|
* for example:
|
||||||
|
* 1. picgo-plugin-xxx -> xxx
|
||||||
|
* 2. @xxx/picgo-plugin-yyy -> yyy
|
||||||
|
* @param name pluginFullName
|
||||||
|
*/
|
||||||
|
export const handleStreamlinePluginName = (name: string) => {
|
||||||
|
if (/^@[^/]+\/picgo-plugin-/.test(name)) {
|
||||||
|
return name.replace(/^@[^/]+\/picgo-plugin-/, '')
|
||||||
|
} else {
|
||||||
|
return name.replace(/picgo-plugin-/, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user