mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import './security-restrictions';
|
|
|
|
import { app } from 'electron';
|
|
|
|
import { restoreOrCreateWindow } from './main-window';
|
|
import { registerProtocol } from './protocol';
|
|
|
|
/**
|
|
* Prevent multiple instances
|
|
*/
|
|
const isSingleInstance = app.requestSingleInstanceLock();
|
|
if (!isSingleInstance) {
|
|
app.quit();
|
|
process.exit(0);
|
|
}
|
|
|
|
app.on('second-instance', restoreOrCreateWindow);
|
|
|
|
/**
|
|
* Disable Hardware Acceleration for more power-save
|
|
*/
|
|
app.disableHardwareAcceleration();
|
|
|
|
/**
|
|
* Shout down background process if all windows was closed
|
|
*/
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
/**
|
|
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
|
|
*/
|
|
app.on('activate', restoreOrCreateWindow);
|
|
|
|
/**
|
|
* Create app window when background process will be ready
|
|
*/
|
|
app
|
|
.whenReady()
|
|
.then(registerProtocol)
|
|
.then(restoreOrCreateWindow)
|
|
.catch(e => console.error('Failed create window:', e));
|
|
|
|
/**
|
|
* Check new app version in production mode only
|
|
*/
|
|
// FIXME: add me back later
|
|
// if (import.meta.env.PROD) {
|
|
// app
|
|
// .whenReady()
|
|
// .then(() => import('electron-updater'))
|
|
// .then(({ autoUpdater }) => autoUpdater.checkForUpdatesAndNotify())
|
|
// .catch(e => console.error('Failed check updates:', e));
|
|
// }
|