🚧 WIP: add uploader config list menu & rebuild multi-config communication way

This commit is contained in:
PiEgg
2022-12-31 20:44:19 +08:00
parent f0787d3ec2
commit 5969daedac
14 changed files with 247 additions and 53 deletions

View File

@@ -1,7 +1,8 @@
import { Component, Vue } from 'vue-property-decorator'
import { ipcRenderer, IpcRendererEvent } from 'electron'
import { PICGO_SAVE_CONFIG, PICGO_GET_CONFIG, FORCE_UPDATE } from '#/events/constants'
import { PICGO_SAVE_CONFIG, PICGO_GET_CONFIG, FORCE_UPDATE, RPC_ACTIONS } from '#/events/constants'
import { uuid } from 'uuidv4'
import { IRPCActionType } from '~/universal/types/enum'
@Component
export default class extends Vue {
created () {
@@ -34,6 +35,23 @@ export default class extends Vue {
})
}
/**
* trigger RPC action
*/
triggerRPC<T> (action: IRPCActionType, ...args: any[]): Promise<T | undefined> {
return new Promise((resolve) => {
const callbackId = uuid()
const callback = (event: IpcRendererEvent, data: T | undefined, returnActionType: IRPCActionType, returnCallbackId: string) => {
if (returnCallbackId === callbackId && returnActionType === action) {
resolve(data)
ipcRenderer.removeListener(RPC_ACTIONS, callback)
}
}
ipcRenderer.on(RPC_ACTIONS, callback)
ipcRenderer.send(RPC_ACTIONS, action, args, callbackId)
})
}
forceUpdate () {
this.$bus.$emit(FORCE_UPDATE)
}