style: 整理代码格式
This commit is contained in:
+26
-24
@@ -1,8 +1,9 @@
|
||||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import { electronAPI } from '@electron-toolkit/preload';
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
|
||||
// 服务器管理
|
||||
getServers: () => ipcRenderer.invoke('mqtt:get-servers'),
|
||||
addServer: (config) => ipcRenderer.invoke('mqtt:add-server', config),
|
||||
@@ -34,43 +35,44 @@ const api = {
|
||||
|
||||
// 事件监听
|
||||
onStatusChange: (callback) => {
|
||||
const handler = (_, data) => callback(data)
|
||||
ipcRenderer.on('mqtt:status-change', handler)
|
||||
return () => ipcRenderer.removeListener('mqtt:status-change', handler)
|
||||
const handler = (_, data) => callback(data);
|
||||
ipcRenderer.on('mqtt:status-change', handler);
|
||||
return () => ipcRenderer.removeListener('mqtt:status-change', handler);
|
||||
},
|
||||
onMessage: (callback) => {
|
||||
const handler = (_, data) => callback(data)
|
||||
ipcRenderer.on('mqtt:message', handler)
|
||||
return () => ipcRenderer.removeListener('mqtt:message', handler)
|
||||
const handler = (_, data) => callback(data);
|
||||
ipcRenderer.on('mqtt:message', handler);
|
||||
return () => ipcRenderer.removeListener('mqtt:message', handler);
|
||||
},
|
||||
onSubscriptionChange: (callback) => {
|
||||
const handler = (_, data) => callback(data)
|
||||
ipcRenderer.on('mqtt:subscription-change', handler)
|
||||
return () => ipcRenderer.removeListener('mqtt:subscription-change', handler)
|
||||
const handler = (_, data) => callback(data);
|
||||
ipcRenderer.on('mqtt:subscription-change', handler);
|
||||
return () => ipcRenderer.removeListener('mqtt:subscription-change', handler);
|
||||
},
|
||||
onSubscriptionError: (callback) => {
|
||||
const handler = (_, data) => callback(data)
|
||||
ipcRenderer.on('mqtt:subscription-error', handler)
|
||||
return () => ipcRenderer.removeListener('mqtt:subscription-error', handler)
|
||||
const handler = (_, data) => callback(data);
|
||||
ipcRenderer.on('mqtt:subscription-error', handler);
|
||||
return () => ipcRenderer.removeListener('mqtt:subscription-error', handler);
|
||||
},
|
||||
onPublishError: (callback) => {
|
||||
const handler = (_, data) => callback(data)
|
||||
ipcRenderer.on('mqtt:publish-error', handler)
|
||||
return () => ipcRenderer.removeListener('mqtt:publish-error', handler)
|
||||
}
|
||||
}
|
||||
const handler = (_, data) => callback(data);
|
||||
ipcRenderer.on('mqtt:publish-error', handler);
|
||||
return () => ipcRenderer.removeListener('mqtt:publish-error', handler);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// 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('electron', electronAPI)
|
||||
contextBridge.exposeInMainWorld('api', api)
|
||||
contextBridge.exposeInMainWorld('electron', electronAPI);
|
||||
contextBridge.exposeInMainWorld('api', api);
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.error(error);
|
||||
}
|
||||
} else {
|
||||
window.electron = electronAPI
|
||||
window.api = api
|
||||
window.electron = electronAPI;
|
||||
window.api = api;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user