feat: 语法错误修复

This commit is contained in:
duanshuwen
2025-11-23 15:12:15 +08:00
parent 6013c38fe7
commit 0b1e7a6679
5 changed files with 631 additions and 1183 deletions

View File

@@ -1,15 +1,15 @@
import { ipcMain, BaseWindow } from 'electron'
type Handler = (...args:any[]) => any
type AsyncHandler = (...args:any[]) => Promise<any>
type Handler = (...args: any[]) => any
type AsyncHandler = (...args: any[]) => Promise<any>
export class IPCManager {
private static instance: IPCManager
private handlers: Map<string, Handler>
private asyncHandlers: Map<string,AsyncHandler>
private constructor() {
private asyncHandlers: Map<string, AsyncHandler>
private constructor () {
this.handlers = new Map()
this.asyncHandlers =new Map()
this.asyncHandlers = new Map()
this.initialize()
}
@@ -27,7 +27,7 @@ export class IPCManager {
try {
const handler = this.handlers.get(channel)
if(handler){
if (handler) {
event.returnValue = handler(...args)
} else {
event.returnValue = { success: false, error: `No handler for channel: ${channel}`}
@@ -42,17 +42,17 @@ export class IPCManager {
try {
const handler = this.asyncHandlers.get(channel)
if(handler){
if (handler) {
return await handler(...args)
}
throw new Error(`No async handler for channel: ${channel}`)
// throw new Error(`No async handler for channel: ${channel}`)
} catch (error) {
throw error
// throw error
}
})
ipcMain.handle('get-window-id',(event) => {
ipcMain.handle('get-window-id',(event: any) => {
event.returnValue = event.sender.id
})
}
@@ -71,17 +71,17 @@ export class IPCManager {
public broadcast(channel:string, ...args:any[]):void {
BaseWindow.getAllWindows().forEach(window => {
if (!window.isDestroyed()) {
window.webContents.send(channel, ...args)
(window as any).webContents.send(channel, ...args)
}
})
}
// 发送消息给指定窗口
public sendToWindow(windowId: string, channel:string, ...args:any[]):void {
public sendToWindow(windowId: number, channel:string, ...args:any[]):void {
const window = BaseWindow.fromId(windowId)
if (window && !window.isDestroyed()) {
window.webContents.send(channel, ...args)
(window as any).webContents.send(channel, ...args)
}
}

View File

@@ -10,7 +10,7 @@ instance.interceptors.request.use(
(config) => {
const token = localStorage.getItem('token')
if (token) {
config.headers = { ...(config.headers || {}), Authorization: `Bearer ${token}` }
(config as any).headers = { ...(config.headers || {}), Authorization: `Bearer ${token}` }
}
return config
},