LaiTool/src/preload/discordIndex.js
2025-02-10 11:44:51 +08:00

29 lines
852 B
JavaScript

import { contextBridge, ipcRenderer } from 'electron'
import { DEFINE_STRING } from '../define/define_string.js';
// Custom APIs for renderer
let events = [];
const api = {
// 创建MJ消息
CreateMessage: (value) => ipcRenderer.send(DEFINE_STRING.DISCORD.CREATE_MESSAGE, value),
// MJ消息更新
UpdateMessage: (value) => ipcRenderer.send(DEFINE_STRING.DISCORD.UPDATE_MESSAGE, value),
// MJ消息删除
DeleteMessage: (value) => ipcRenderer.send(DEFINE_STRING.DISCORD.DELETE_MESSAGE, value),
}
// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('api', api)
} catch (error) {
console.error(error)
}
} else {
window.api = api
}