mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
Co-authored-by: Hongtao Lye <codert.sn@gmail.com> Co-authored-by: liuyi <forehalo@gmail.com> Co-authored-by: LongYinan <lynweklm@gmail.com> Co-authored-by: X1a0t <405028157@qq.com> Co-authored-by: JimmFly <yangjinfei001@gmail.com> Co-authored-by: Peng Xiao <pengxiao@outlook.com> Co-authored-by: xiaodong zuo <53252747+zuoxiaodong0815@users.noreply.github.com> Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: Qi <474021214@qq.com> Co-authored-by: danielchim <kahungchim@gmail.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { app, BrowserWindow } from 'electron';
|
|
|
|
import { applicationMenuEvents } from './application-menu';
|
|
import { logger } from './logger';
|
|
import { uiEvents } from './ui';
|
|
import { updaterEvents } from './updater/event';
|
|
|
|
export const allEvents = {
|
|
applicationMenu: applicationMenuEvents,
|
|
updater: updaterEvents,
|
|
ui: uiEvents,
|
|
};
|
|
|
|
function getActiveWindows() {
|
|
return BrowserWindow.getAllWindows().filter(win => !win.isDestroyed());
|
|
}
|
|
|
|
export function registerEvents() {
|
|
// register events
|
|
for (const [namespace, namespaceEvents] of Object.entries(allEvents)) {
|
|
for (const [key, eventRegister] of Object.entries(namespaceEvents)) {
|
|
const subscription = eventRegister((...args: any[]) => {
|
|
const chan = `${namespace}:${key}`;
|
|
logger.info(
|
|
'[ipc-event]',
|
|
chan,
|
|
args.filter(
|
|
a =>
|
|
a !== undefined &&
|
|
typeof a !== 'function' &&
|
|
typeof a !== 'object'
|
|
)
|
|
);
|
|
getActiveWindows().forEach(win => win.webContents.send(chan, ...args));
|
|
});
|
|
app.on('before-quit', () => {
|
|
subscription();
|
|
});
|
|
}
|
|
}
|
|
}
|