2023-01-06 04:21:27 -05:00
|
|
|
import { isReactive, isRef, toRaw, unref } from 'vue'
|
2023-09-02 10:38:04 -04:00
|
|
|
import { ipcRenderer } from 'electron'
|
2023-08-27 10:48:08 -04:00
|
|
|
import { OPEN_URL } from '~/universal/events/constants'
|
2023-01-06 04:21:27 -05:00
|
|
|
|
2023-10-12 22:11:49 -04:00
|
|
|
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)
|
|
|
|
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
|
|
|
|
2023-09-02 10:38:04 -04:00
|
|
|
function sendToMain (channel: string, ...args: any[]) {
|
|
|
|
const data = getRawData(args)
|
|
|
|
ipcRenderer.send(channel, ...data)
|
|
|
|
}
|
|
|
|
|
2023-08-27 10:48:08 -04:00
|
|
|
export const openURL = (url: string) => {
|
|
|
|
sendToMain(OPEN_URL, url)
|
|
|
|
}
|