Files
electron-egg/electron/preload/lifecycle.ts
2025-01-08 19:25:00 +08:00

47 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { type AppConfig, getConfig } from 'ee-core/config';
import { getMainWindow } from 'ee-core/electron';
class Lifecycle {
/**
* Core app has been loaded
*/
async ready(): Promise<void> {
console.log('[lifecycle] ready');
}
/**
* Electron app is ready
*/
async electronAppReady(): Promise<void> {
console.log('[lifecycle] electron-app-ready');
}
/**
* Main window has been loaded
*/
async windowReady(): Promise<void> {
console.log('[lifecycle] window-ready');
// Delay loading, no white screen
const config:AppConfig = getConfig();
const { windowsOption } = config;
if (windowsOption?.show === false) {
const win = getMainWindow();
win.once('ready-to-show', () => {
win.show();
win.focus();
});
}
}
/**
* Before app close
*/
async beforeClose(): Promise<void> {
console.log('[lifecycle] before-close');
}
}
// 设置类的toString方法虽然在TypeScript中不常见
Lifecycle.toString = () => '[class Lifecycle]';
export { Lifecycle };