mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-11 18:10:32 +08:00
✨ Feature(custom): refactor all main ipc event
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { isReactive, isRef, toRaw, unref } from 'vue'
|
||||
|
||||
import { OPEN_URL } from '#/events/constants'
|
||||
import { ILogType } from '#/types/enum'
|
||||
import { RPC_ACTIONS, RPC_ACTIONS_INVOKE } from '#/events/constants'
|
||||
import { IRPCActionType } from '#/types/enum'
|
||||
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
|
||||
export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
|
||||
const { EventId, Label = '', MapKv = {} } = data
|
||||
MapKv.from = window.location.href
|
||||
window.TDAPP.onEvent(EventId, Label, MapKv)
|
||||
try {
|
||||
window.TDAPP.onEvent(EventId, Label, MapKv)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
if (isDevelopment) {
|
||||
console.log('talkingData', data)
|
||||
}
|
||||
@@ -37,20 +41,26 @@ export function sendToMain (channel: string, ...args: any[]) {
|
||||
ipcRenderer.send(channel, ...data)
|
||||
}
|
||||
|
||||
/**
|
||||
* send a rpc request & do not need to wait for the response
|
||||
*
|
||||
* or the response will be handled by other listener
|
||||
*/
|
||||
export function sendRPC (action: IRPCActionType, ...args: any[]): void {
|
||||
const data = getRawData(args)
|
||||
ipcRenderer.send(RPC_ACTIONS, action, data)
|
||||
}
|
||||
|
||||
export function invokeToMain (channel: string, ...args: any[]) {
|
||||
const data = getRawData(args)
|
||||
return ipcRenderer.invoke(channel, ...data)
|
||||
}
|
||||
|
||||
export const openURL = (url: string) => {
|
||||
sendToMain(OPEN_URL, url)
|
||||
}
|
||||
|
||||
export const deleteLog = (fileName?: string, type?: string, isSuccess = true, msg?: string) => {
|
||||
ipcRenderer.send('logDeleteMsg', msg || `Delete ${fileName} on ${type} success`, isSuccess ? ILogType.success : ILogType.error)
|
||||
}
|
||||
|
||||
export const deleteFailedLog = (fileName: string, type: string, error: any) => {
|
||||
deleteLog(fileName, type, false)
|
||||
ipcRenderer.send('logDeleteMsg', error, ILogType.error)
|
||||
/**
|
||||
* trigger RPC action
|
||||
* TODO: create an isolate rpc handler
|
||||
*/
|
||||
export async function triggerRPC<T> (action: IRPCActionType, ...args: any[]): Promise<T | undefined> {
|
||||
const data = getRawData(args)
|
||||
return await ipcRenderer.invoke(RPC_ACTIONS_INVOKE, action, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user