style: 整理代码格式

This commit is contained in:
2026-07-19 17:15:28 +08:00
parent 6bd13851d9
commit 78797dee86
15 changed files with 1354 additions and 874 deletions
+26 -24
View File
@@ -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;
}