Files
electron-egg/electronts/preload/lifecycle.ts
2025-01-02 19:20:41 +08:00

49 lines
1.1 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 { getConfig, Config } from 'ee-core/config';
import { getMainWindow } from 'ee-core/electron';
class Lifecycle {
/**
* Core app has been loaded
*/
async ready(): Promise<void> {
// Do some things
console.log('[lifecycle] ready');
}
/**
* Electron app is ready
*/
async electronAppReady(): Promise<void> {
// Do some things
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: Config = 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 };