2023-01-02 01:13:27 -05:00
|
|
|
import { ipcMain, IpcMainEvent } from 'electron'
|
|
|
|
import { IRPCActionType } from '~/universal/types/enum'
|
|
|
|
import { RPC_ACTIONS } from '#/events/constants'
|
|
|
|
import {
|
|
|
|
deleteUploaderConfig,
|
|
|
|
getUploaderConfigList,
|
2023-03-24 01:32:16 -04:00
|
|
|
resetUploaderConfig,
|
2023-01-02 01:13:27 -05:00
|
|
|
selectUploaderConfig,
|
|
|
|
updateUploaderConfig
|
2023-01-02 01:16:52 -05:00
|
|
|
} from '~/main/utils/handleUploaderConfig'
|
2023-01-02 01:13:27 -05:00
|
|
|
|
|
|
|
class RPCServer {
|
|
|
|
start () {
|
|
|
|
ipcMain.on(RPC_ACTIONS, (event: IpcMainEvent, action: IRPCActionType, args: any[], callbackId: string) => {
|
|
|
|
try {
|
|
|
|
switch (action) {
|
|
|
|
case IRPCActionType.GET_PICBED_CONFIG_LIST: {
|
|
|
|
const configList = this.getPicBedConfigList(args as IGetUploaderConfigListArgs)
|
|
|
|
this.sendBack(event, action, configList, callbackId)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
case IRPCActionType.DELETE_PICBED_CONFIG: {
|
|
|
|
const res = this.deleteUploaderConfig(args as IDeleteUploaderConfigArgs)
|
|
|
|
this.sendBack(event, action, res, callbackId)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
case IRPCActionType.SELECT_UPLOADER: {
|
|
|
|
this.selectUploaderConfig(args as ISelectUploaderConfigArgs)
|
|
|
|
this.sendBack(event, action, true, callbackId)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
case IRPCActionType.UPDATE_UPLOADER_CONFIG: {
|
|
|
|
this.updateUploaderConfig(args as IUpdateUploaderConfigArgs)
|
|
|
|
this.sendBack(event, action, true, callbackId)
|
|
|
|
break
|
|
|
|
}
|
2023-03-24 01:32:16 -04:00
|
|
|
case IRPCActionType.RESET_UPLOADER_CONFIG: {
|
|
|
|
this.resetUploaderConfig(args as IResetUploaderConfigArgs)
|
|
|
|
this.sendBack(event, action, true, callbackId)
|
|
|
|
break
|
|
|
|
}
|
2023-01-02 01:13:27 -05:00
|
|
|
default: {
|
|
|
|
this.sendBack(event, action, null, callbackId)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.sendBack(event, action, null, callbackId)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* if sendback data is null, then it means that the action is not supported or error occurs
|
|
|
|
*/
|
|
|
|
private sendBack (event: IpcMainEvent, action: IRPCActionType, data: any, callbackId: string) {
|
|
|
|
event.sender.send(RPC_ACTIONS, data, action, callbackId)
|
|
|
|
}
|
|
|
|
|
|
|
|
private getPicBedConfigList (args: IGetUploaderConfigListArgs) {
|
|
|
|
const [type] = args
|
|
|
|
const config = getUploaderConfigList(type)
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
private deleteUploaderConfig (args: IDeleteUploaderConfigArgs) {
|
|
|
|
const [type, id] = args
|
|
|
|
const config = deleteUploaderConfig(type, id)
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
private selectUploaderConfig (args: ISelectUploaderConfigArgs) {
|
|
|
|
const [type, id] = args
|
|
|
|
const config = selectUploaderConfig(type, id)
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateUploaderConfig (args: IUpdateUploaderConfigArgs) {
|
|
|
|
const [type, id, config] = args
|
|
|
|
const res = updateUploaderConfig(type, id, config)
|
|
|
|
return res
|
|
|
|
}
|
2023-03-24 01:32:16 -04:00
|
|
|
|
|
|
|
private resetUploaderConfig (args: IResetUploaderConfigArgs) {
|
|
|
|
const [type, id] = args
|
|
|
|
const res = resetUploaderConfig(type, id)
|
|
|
|
return res
|
|
|
|
}
|
2023-01-02 01:13:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const rpcServer = new RPCServer()
|
|
|
|
|
|
|
|
export {
|
|
|
|
rpcServer
|
|
|
|
}
|