Refacor electron app and add migrations
This commit is contained in:
40
electron/app/lifecycle.ts
Normal file
40
electron/app/lifecycle.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
import {
|
||||
initializeDatabase,
|
||||
destroyDatabase,
|
||||
getDataSource
|
||||
} from '../db/database';
|
||||
import { createWindow } from '../window/create-window';
|
||||
import {
|
||||
setupCqrsHandlers,
|
||||
setupSystemHandlers,
|
||||
setupWindowControlHandlers
|
||||
} from '../ipc';
|
||||
|
||||
export function registerAppLifecycle(): void {
|
||||
app.whenReady().then(async () => {
|
||||
await initializeDatabase();
|
||||
setupCqrsHandlers();
|
||||
setupWindowControlHandlers();
|
||||
setupSystemHandlers();
|
||||
await createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0)
|
||||
createWindow();
|
||||
});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin')
|
||||
app.quit();
|
||||
});
|
||||
|
||||
app.on('before-quit', async (event) => {
|
||||
if (getDataSource()?.isInitialized) {
|
||||
event.preventDefault();
|
||||
await destroyDatabase();
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user