2023-09-02 10:38:04 -04:00
|
|
|
import { ipcRenderer } from 'electron'
|
2024-06-08 23:53:07 -04:00
|
|
|
import { isReactive, isRef, toRaw, unref } from 'vue'
|
|
|
|
|
|
|
|
import { OPEN_URL } from '#/events/constants'
|
|
|
|
import { ILogType } from '#/types/enum'
|
2023-01-06 04:21:27 -05:00
|
|
|
|
2023-10-12 22:11:49 -04:00
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
2024-06-09 09:05:30 -04:00
|
|
|
|
2023-10-12 22:11:49 -04:00
|
|
|
export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
|
|
|
|
const { EventId, Label = '', MapKv = {} } = data
|
|
|
|
MapKv.from = window.location.href
|
|
|
|
window.TDAPP.onEvent(EventId, Label, MapKv)
|
|
|
|
if (isDevelopment) {
|
|
|
|
console.log('talkingData', data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
/**
|
|
|
|
* get raw data from reactive or ref
|
|
|
|
*/
|
2023-01-07 07:45:01 -05:00
|
|
|
export const getRawData = (args: any): any => {
|
2023-08-10 03:11:57 -04:00
|
|
|
if (isRef(args)) return unref(args)
|
|
|
|
if (isReactive(args)) return toRaw(args)
|
|
|
|
if (Array.isArray(args)) return args.map(getRawData)
|
2023-02-17 02:42:49 -05:00
|
|
|
if (typeof args === 'object' && args !== null) {
|
2023-05-18 01:22:34 -04:00
|
|
|
const data = {} as Record<string, any>
|
|
|
|
for (const key in args) {
|
|
|
|
data[key] = getRawData(args[key])
|
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
2023-08-27 10:48:08 -04:00
|
|
|
|
2024-06-09 09:05:30 -04:00
|
|
|
export function sendToMain (channel: string, ...args: any[]) {
|
2023-09-02 10:38:04 -04:00
|
|
|
const data = getRawData(args)
|
|
|
|
ipcRenderer.send(channel, ...data)
|
|
|
|
}
|
|
|
|
|
2024-06-09 09:05:30 -04:00
|
|
|
export function invokeToMain (channel: string, ...args: any[]) {
|
|
|
|
const data = getRawData(args)
|
|
|
|
return ipcRenderer.invoke(channel, ...data)
|
|
|
|
}
|
|
|
|
|
2023-08-27 10:48:08 -04:00
|
|
|
export const openURL = (url: string) => {
|
|
|
|
sendToMain(OPEN_URL, url)
|
|
|
|
}
|
2024-05-24 10:27:45 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|