mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
🐛 Fix: fixed issue of plugin system being unable to use
ISSUES CLOSED: #21
This commit is contained in:
parent
8f9b85d467
commit
8bfe9c5194
@ -21,7 +21,6 @@ import { T } from '~/main/i18n'
|
|||||||
import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion'
|
import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion'
|
||||||
import { buildPicBedListMenu } from '~/main/events/remotes/menu'
|
import { buildPicBedListMenu } from '~/main/events/remotes/menu'
|
||||||
let contextMenu: Menu | null
|
let contextMenu: Menu | null
|
||||||
let menu: Menu | null
|
|
||||||
let tray: Tray | null
|
let tray: Tray | null
|
||||||
|
|
||||||
export function createMenu () {
|
export function createMenu () {
|
||||||
|
@ -39,6 +39,7 @@ import { handleCopyUrl } from '~/main/utils/common'
|
|||||||
import { buildMainPageMenu, buildMiniPageMenu, buildPluginPageMenu, buildPicBedListMenu } from './remotes/menu'
|
import { buildMainPageMenu, buildMiniPageMenu, buildPluginPageMenu, buildPicBedListMenu } from './remotes/menu'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { T } from '~/main/i18n'
|
import { T } from '~/main/i18n'
|
||||||
|
import picgo from '../apis/core/picgo'
|
||||||
|
|
||||||
const STORE_PATH = app.getPath('userData')
|
const STORE_PATH = app.getPath('userData')
|
||||||
|
|
||||||
@ -74,6 +75,18 @@ export default {
|
|||||||
uploadClipboardFiles()
|
uploadClipboardFiles()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getStorePath', () => {
|
||||||
|
return STORE_PATH
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('manualRegesterPlugin', (evt: IpcMainEvent, pluginName: string) => {
|
||||||
|
picgo.pluginLoader.registerPlugin(pluginName)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('manualUnRegesterPlugin', (evt: IpcMainEvent, pluginName: string) => {
|
||||||
|
picgo.pluginLoader.unregisterPlugin(pluginName)
|
||||||
|
})
|
||||||
|
|
||||||
ipcMain.on('uploadChoosedFiles', async (evt: IpcMainEvent, files: IFileWithPath[]) => {
|
ipcMain.on('uploadChoosedFiles', async (evt: IpcMainEvent, files: IFileWithPath[]) => {
|
||||||
return uploadChoosedFiles(evt.sender, files)
|
return uploadChoosedFiles(evt.sender, files)
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,6 @@ import { privacyManager } from '~/main/utils/privacyManager'
|
|||||||
import pkg from 'root/package.json'
|
import pkg from 'root/package.json'
|
||||||
import GuiApi from 'apis/gui'
|
import GuiApi from 'apis/gui'
|
||||||
import { PICGO_CONFIG_PLUGIN, PICGO_HANDLE_PLUGIN_DONE, PICGO_HANDLE_PLUGIN_ING, PICGO_TOGGLE_PLUGIN, SHOW_MAIN_PAGE_DONATION, SHOW_MAIN_PAGE_QRCODE } from '~/universal/events/constants'
|
import { PICGO_CONFIG_PLUGIN, PICGO_HANDLE_PLUGIN_DONE, PICGO_HANDLE_PLUGIN_ING, PICGO_TOGGLE_PLUGIN, SHOW_MAIN_PAGE_DONATION, SHOW_MAIN_PAGE_QRCODE } from '~/universal/events/constants'
|
||||||
import picgoCoreIPC from '~/main/events/picgoCoreIPC'
|
|
||||||
import { PicGo as PicGoCore } from 'piclist'
|
import { PicGo as PicGoCore } from 'piclist'
|
||||||
import { T } from '~/main/i18n'
|
import { T } from '~/main/i18n'
|
||||||
import { changeCurrentUploader } from '~/main/utils/handleUploaderConfig'
|
import { changeCurrentUploader } from '~/main/utils/handleUploaderConfig'
|
||||||
@ -222,15 +221,13 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
|
|||||||
label: T('UNINSTALL_PLUGIN'),
|
label: T('UNINSTALL_PLUGIN'),
|
||||||
click () {
|
click () {
|
||||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||||
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
window.webContents.send('uninstallPlugin', plugin.fullName)
|
||||||
picgoCoreIPC.handlePluginUninstall(plugin.fullName)
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
label: T('UPDATE_PLUGIN'),
|
label: T('UPDATE_PLUGIN'),
|
||||||
click () {
|
click () {
|
||||||
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
|
||||||
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
|
window.webContents.send('updatePlugin', plugin.fullName)
|
||||||
picgoCoreIPC.handlePluginUpdate(plugin.fullName)
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
for (const i in plugin.config) {
|
for (const i in plugin.config) {
|
||||||
|
@ -13,17 +13,6 @@
|
|||||||
<Goods />
|
<Goods />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip
|
|
||||||
:content="importLocalPluginToolTip"
|
|
||||||
placement="left"
|
|
||||||
>
|
|
||||||
<el-icon
|
|
||||||
class="el-icon-download"
|
|
||||||
@click="handleImportLocalPlugin"
|
|
||||||
>
|
|
||||||
<Download />
|
|
||||||
</el-icon>
|
|
||||||
</el-tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
<el-row
|
<el-row
|
||||||
class="handle-bar"
|
class="handle-bar"
|
||||||
@ -196,11 +185,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { Close, Download, Goods, Remove, Setting } from '@element-plus/icons-vue'
|
import { Close, Goods, Remove, Setting } from '@element-plus/icons-vue'
|
||||||
import { T as $T } from '@/i18n/index'
|
import { T as $T } from '@/i18n/index'
|
||||||
import ConfigForm from '@/components/ConfigForm.vue'
|
import ConfigForm from '@/components/ConfigForm.vue'
|
||||||
import { debounce, DebouncedFunc } from 'lodash'
|
import { debounce, DebouncedFunc } from 'lodash'
|
||||||
import {
|
import {
|
||||||
|
clipboard,
|
||||||
ipcRenderer,
|
ipcRenderer,
|
||||||
IpcRendererEvent
|
IpcRendererEvent
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
@ -217,7 +207,7 @@ import {
|
|||||||
} from '#/events/constants'
|
} from '#/events/constants'
|
||||||
import { computed, ref, onBeforeMount, onBeforeUnmount, watch, onMounted } from 'vue'
|
import { computed, ref, onBeforeMount, onBeforeUnmount, watch, onMounted } from 'vue'
|
||||||
import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender'
|
import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender'
|
||||||
import { ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
const $confirm = ElMessageBox.confirm
|
const $confirm = ElMessageBox.confirm
|
||||||
const searchText = ref('')
|
const searchText = ref('')
|
||||||
@ -230,7 +220,6 @@ const pluginNameList = ref<string[]>([])
|
|||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const needReload = ref(false)
|
const needReload = ref(false)
|
||||||
const pluginListToolTip = $T('PLUGIN_LIST')
|
const pluginListToolTip = $T('PLUGIN_LIST')
|
||||||
const importLocalPluginToolTip = $T('PLUGIN_IMPORT_LOCAL')
|
|
||||||
// const id = ref('')
|
// const id = ref('')
|
||||||
const os = ref('')
|
const os = ref('')
|
||||||
const defaultLogo = ref(`this.src="file://${__static.replace(/\\/g, '/')}/roundLogo.png"`)
|
const defaultLogo = ref(`this.src="file://${__static.replace(/\\/g, '/')}/roundLogo.png"`)
|
||||||
@ -328,6 +317,59 @@ onBeforeMount(async () => {
|
|||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
config.value = _config
|
config.value = _config
|
||||||
})
|
})
|
||||||
|
ipcRenderer.on('uninstallPlugin', async (evt: IpcRendererEvent, fullName: string) => {
|
||||||
|
const appPath = await ipcRenderer.invoke('getStorePath')
|
||||||
|
const cmd = `cd '${appPath}' && npm uninstall ${fullName}`
|
||||||
|
clipboard.writeText(cmd)
|
||||||
|
ElMessageBox.confirm('命令已复制到剪切板,请前往终端执行', '提示', {
|
||||||
|
confirmButtonText: '执行成功',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
saveConfig(`picgoPlugins.${fullName}`, false)
|
||||||
|
ipcRenderer.send('manualUnRegesterPlugin', fullName)
|
||||||
|
pluginList.value = pluginList.value.filter(item => {
|
||||||
|
if (item.fullName === fullName) { // restore Uploader & Transformer after uninstalling
|
||||||
|
if (item.config.transformer.name) {
|
||||||
|
handleRestoreState('transformer', item.config.transformer.name)
|
||||||
|
}
|
||||||
|
if (item.config.uploader.name) {
|
||||||
|
handleRestoreState('uploader', item.config.uploader.name)
|
||||||
|
}
|
||||||
|
getPicBeds()
|
||||||
|
}
|
||||||
|
return item.fullName !== fullName
|
||||||
|
})
|
||||||
|
pluginNameList.value = pluginNameList.value.filter(item => item !== fullName)
|
||||||
|
ElMessage.success('卸载成功')
|
||||||
|
}).catch(() => {
|
||||||
|
console.log('cancel')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
ipcRenderer.on('updatePlugin', async (evt: IpcRendererEvent, fullName: string) => {
|
||||||
|
const appPath = await ipcRenderer.invoke('getStorePath')
|
||||||
|
const cmd = `cd '${appPath}' && npm update ${fullName}`
|
||||||
|
clipboard.writeText(cmd)
|
||||||
|
ElMessageBox.confirm('命令已复制到剪切板,请前往终端执行', '提示', {
|
||||||
|
confirmButtonText: '执行成功',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
saveConfig(`picgoPlugins.${fullName}`, true)
|
||||||
|
ipcRenderer.send('manualRegesterPlugin', fullName)
|
||||||
|
pluginList.value.forEach(item => {
|
||||||
|
if (item.fullName === fullName) {
|
||||||
|
item.ing = false
|
||||||
|
item.hasInstall = true
|
||||||
|
}
|
||||||
|
getPicBeds()
|
||||||
|
})
|
||||||
|
handleReload()
|
||||||
|
getPluginList()
|
||||||
|
}).catch(() => {
|
||||||
|
console.log('cancel')
|
||||||
|
})
|
||||||
|
})
|
||||||
ipcRenderer.on(PICGO_HANDLE_PLUGIN_ING, (evt: IpcRendererEvent, fullName: string) => {
|
ipcRenderer.on(PICGO_HANDLE_PLUGIN_ING, (evt: IpcRendererEvent, fullName: string) => {
|
||||||
pluginList.value.forEach(item => {
|
pluginList.value.forEach(item => {
|
||||||
if (item.fullName === fullName || (item.name === fullName)) {
|
if (item.fullName === fullName || (item.name === fullName)) {
|
||||||
@ -372,21 +414,42 @@ function getPicBeds () {
|
|||||||
sendToMain(GET_PICBEDS)
|
sendToMain(GET_PICBEDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
function installPlugin (item: IPicGoPlugin) {
|
async function installPluginManually (item: IPicGoPlugin) {
|
||||||
|
const appPath = await ipcRenderer.invoke('getStorePath')
|
||||||
|
const cmd = `npm install ${item.fullName} --prefix '${appPath}'`
|
||||||
|
// 命令复制到剪切板
|
||||||
|
clipboard.writeText(cmd)
|
||||||
|
ElMessageBox.confirm('命令已复制到剪切板,请前往终端执行', '提示', {
|
||||||
|
confirmButtonText: '执行成功',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
saveConfig(`picgoPlugins.${item.fullName}`, true)
|
||||||
|
item.hasInstall = true
|
||||||
|
ipcRenderer.send('manualRegesterPlugin', item.fullName)
|
||||||
|
pluginList.value.forEach(i => {
|
||||||
|
if (i.fullName === item.fullName) {
|
||||||
|
i.ing = false
|
||||||
|
item.hasInstall = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ElMessage.success('安装成功')
|
||||||
|
}).catch(() => {
|
||||||
|
console.log('Install canceled')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installPlugin (item: IPicGoPlugin) {
|
||||||
if (!item.gui) {
|
if (!item.gui) {
|
||||||
$confirm($T('TIPS_PLUGIN_NOT_GUI_IMPLEMENT'), $T('TIPS_NOTICE'), {
|
$confirm($T('TIPS_PLUGIN_NOT_GUI_IMPLEMENT'), $T('TIPS_NOTICE'), {
|
||||||
confirmButtonText: $T('CONFIRM'),
|
confirmButtonText: $T('CONFIRM'),
|
||||||
cancelButtonText: $T('CANCEL'),
|
cancelButtonText: $T('CANCEL'),
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(async () => {
|
||||||
item.ing = true
|
installPluginManually(item)
|
||||||
sendToMain('installPlugin', item.fullName)
|
|
||||||
}).catch(() => {
|
|
||||||
console.log('Install canceled')
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
item.ing = true
|
installPluginManually(item)
|
||||||
sendToMain('installPlugin', item.fullName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,11 +598,6 @@ function goAwesomeList () {
|
|||||||
sendToMain(OPEN_URL, 'https://github.com/PicGo/Awesome-PicGo')
|
sendToMain(OPEN_URL, 'https://github.com/PicGo/Awesome-PicGo')
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleImportLocalPlugin () {
|
|
||||||
sendToMain('importLocalPlugin')
|
|
||||||
loading.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener('resize', handleResize)
|
window.removeEventListener('resize', handleResize)
|
||||||
ipcRenderer.removeAllListeners('pluginList')
|
ipcRenderer.removeAllListeners('pluginList')
|
||||||
@ -548,6 +606,8 @@ onBeforeUnmount(() => {
|
|||||||
ipcRenderer.removeAllListeners('updateSuccess')
|
ipcRenderer.removeAllListeners('updateSuccess')
|
||||||
ipcRenderer.removeAllListeners('hideLoading')
|
ipcRenderer.removeAllListeners('hideLoading')
|
||||||
ipcRenderer.removeAllListeners(PICGO_HANDLE_PLUGIN_DONE)
|
ipcRenderer.removeAllListeners(PICGO_HANDLE_PLUGIN_DONE)
|
||||||
|
ipcRenderer.removeAllListeners('updatePlugin')
|
||||||
|
ipcRenderer.removeAllListeners('uninstallPlugin')
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user