lint
This commit is contained in:
1 parent
fc250c54ed
commit
5eec516459
62 files changed
+3912
-3376
No files matched your search
+28
-27
@@ -1,9 +1,10 @@
|
||||
import log from 'electron-log/renderer'
|
||||
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'
|
||||
import type { IpcRendererEvent } from 'electron';
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import log from 'electron-log/renderer';
|
||||
|
||||
// Initialize renderer logger
|
||||
log.transports.console.level = 'silly'
|
||||
log.transports.console.format = '{h}:{i}:{s}.{ms} {text}'
|
||||
log.transports.console.level = 'silly';
|
||||
log.transports.console.format = '{h}:{i}:{s}.{ms} {text}';
|
||||
|
||||
// Whitelist of valid channels used for IPC communication (Send message from Renderer to Main)
|
||||
const mainAvailChannels: string[] = [
|
||||
@@ -18,70 +19,70 @@ const mainAvailChannels: string[] = [
|
||||
'msgFindFilesInFolder',
|
||||
'msgCheckForUpdates',
|
||||
'msgDownloadUpdate',
|
||||
'msgInstallUpdate'
|
||||
]
|
||||
'msgInstallUpdate',
|
||||
];
|
||||
const rendererAvailChannels: string[] = [
|
||||
'update-checking',
|
||||
'update-available',
|
||||
'update-not-available',
|
||||
'update-download-progress',
|
||||
'update-downloaded',
|
||||
'update-error'
|
||||
]
|
||||
'update-error',
|
||||
];
|
||||
|
||||
contextBridge.exposeInMainWorld('mainApi', {
|
||||
send: (channel: string, ...data: any[]): void => {
|
||||
if (mainAvailChannels.includes(channel)) {
|
||||
ipcRenderer.send.apply(null, [channel, ...data])
|
||||
ipcRenderer.send.apply(null, [channel, ...data]);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
log.silly(`[IPC_SEND::${channel}]`, { request: data })
|
||||
log.silly(`[IPC_SEND::${channel}]`, { request: data });
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`)
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`);
|
||||
}
|
||||
},
|
||||
on: (
|
||||
channel: string,
|
||||
listener: (event: IpcRendererEvent, ...args: any[]) => void
|
||||
listener: (event: IpcRendererEvent, ...args: any[]) => void,
|
||||
): void => {
|
||||
if (rendererAvailChannels.includes(channel)) {
|
||||
ipcRenderer.on(channel, listener)
|
||||
ipcRenderer.on(channel, listener);
|
||||
} else {
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`)
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`);
|
||||
}
|
||||
},
|
||||
once: (
|
||||
channel: string,
|
||||
listener: (event: IpcRendererEvent, ...args: any[]) => void
|
||||
listener: (event: IpcRendererEvent, ...args: any[]) => void,
|
||||
): void => {
|
||||
if (rendererAvailChannels.includes(channel)) {
|
||||
ipcRenderer.once(channel, listener)
|
||||
ipcRenderer.once(channel, listener);
|
||||
} else {
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`)
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`);
|
||||
}
|
||||
},
|
||||
off: (
|
||||
channel: string,
|
||||
listener: (event: IpcRendererEvent, ...args: any[]) => void
|
||||
listener: (event: IpcRendererEvent, ...args: any[]) => void,
|
||||
): void => {
|
||||
if (rendererAvailChannels.includes(channel)) {
|
||||
ipcRenderer.off(channel, listener)
|
||||
ipcRenderer.off(channel, listener);
|
||||
} else {
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`)
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`);
|
||||
}
|
||||
},
|
||||
invoke: async (channel: string, ...data: any[]): Promise<any> => {
|
||||
if (mainAvailChannels.includes(channel)) {
|
||||
const result = await ipcRenderer.invoke.apply(null, [channel, ...data])
|
||||
const result = await ipcRenderer.invoke.apply(null, [channel, ...data]);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
log.silly(`[IPC_INVOKE::${channel}]`, {
|
||||
request: data,
|
||||
result
|
||||
})
|
||||
result,
|
||||
});
|
||||
}
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`)
|
||||
}
|
||||
})
|
||||
throw new Error(`Unknown ipc channel name: ${channel}`);
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user