mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
114 lines
2.9 KiB
JavaScript
114 lines
2.9 KiB
JavaScript
process.on("uncaughtException", (err) => {
|
|
console.error("Uncaught exception:", err);
|
|
app.quit();
|
|
});
|
|
|
|
process.on("unhandledRejection", (reason) => {
|
|
console.error("Unhandled rejection:", reason);
|
|
app.quit();
|
|
});
|
|
|
|
const { app } = require("electron");
|
|
|
|
/**
|
|
* True if this is the primary instance (lock acquired successfully)
|
|
*/
|
|
const isPrimaryInstance = app.requestSingleInstanceLock();
|
|
|
|
/**
|
|
* If we are on a second instance
|
|
*/
|
|
if (!isPrimaryInstance) {
|
|
app.quit();
|
|
process.exit(0);
|
|
}
|
|
|
|
/**
|
|
* Load the app
|
|
*/
|
|
const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./app/splashManager");
|
|
const path = require("path");
|
|
|
|
const { logger, logSessionStart, logSessionEnd } = require("./server/logger");
|
|
const { initAutoUpdater } = require("./app/autoUpdater");
|
|
const { startRPC, stopRPC } = require("./app/discordRPC");
|
|
|
|
const { configFeatures } = require("./config");
|
|
const config = require("./config");
|
|
const { initThemes } = require("./app/themeManager");
|
|
|
|
const { checkNativeDependencies } = require("./app/dependencyCheck");
|
|
const { updateYtDlp } = require("./app/ytDlpUpdater");
|
|
const { createMainWindow, getMainWindow } = require("./app/windowManager");
|
|
const { registerIpcHandlers } = require("./app/ipcHandlers");
|
|
const { userThemesPath, initUserThemes } = require("./server/helpers/path.helpers");
|
|
|
|
app.setName("Freedom Loader");
|
|
app.setAppUserModelId("com.masteracnolo.freedomloader");
|
|
app.disableHardwareAcceleration();
|
|
|
|
|
|
/**
|
|
* If another instance want to run
|
|
*/
|
|
app.on("second-instance", () => {
|
|
logger.info("Second instance detected");
|
|
|
|
const mainWindow = require("./app/windowManager").getMainWindow();
|
|
|
|
if (!mainWindow) return;
|
|
|
|
if (mainWindow.isMinimized()) mainWindow.restore();
|
|
|
|
mainWindow.show();
|
|
mainWindow.focus();
|
|
});
|
|
|
|
app.whenReady().then(async () => {
|
|
logSessionStart();
|
|
|
|
createSplashWindow();
|
|
|
|
if (!config.devMode && !checkNativeDependencies()) return;
|
|
|
|
const { userYtDlp } = require("./server/helpers/path.helpers");
|
|
updateYtDlp(userYtDlp);
|
|
|
|
try {
|
|
setSplashProgress(0); // Checking dependencies
|
|
await require("./server/server").startServer();
|
|
|
|
setSplashProgress(1); // Starting server
|
|
registerIpcHandlers(getMainWindow);
|
|
|
|
setSplashProgress(2); // Loading themes
|
|
initUserThemes();
|
|
await initThemes(userThemesPath);
|
|
|
|
setSplashProgress(3); // Almost ready
|
|
await createMainWindow();
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
|
|
closeSplashWindow();
|
|
getMainWindow().show();
|
|
if (configFeatures.discordRPC) startRPC();
|
|
|
|
if (configFeatures.autoUpdate) initAutoUpdater(getMainWindow());
|
|
|
|
} catch (err) {
|
|
logger.error("Boot error:", err);
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
app.on("window-all-closed", () => {
|
|
logger.info("Shutting down...");
|
|
app.quit();
|
|
});
|
|
|
|
app.on("before-quit", async () => {
|
|
await stopRPC();
|
|
logger.info("All services stopped. Have a nice day!");
|
|
logSessionEnd();
|
|
}); |