mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
- Added a simple abstraction of persistent storage class.
- Different persistence solutions are provided for web and client.
- web: stored in localStorage
- client: stored in the application directory as `.json` file
- Define persistent app-config schema
- Add a new hook that can interactive with persistent-app-config reactively
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/events';
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
}
|