mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
Autoupdate + FreedomKiller Démarrage
This commit is contained in:
21
main.js
21
main.js
@@ -3,17 +3,30 @@ const { app, BrowserWindow, ipcMain, dialog, Menu, shell } = require("electron")
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const { logger, logSessionStart, logSessionEnd, logDir } = require("./server/logger");
|
const { logger, logSessionStart, logSessionEnd, logDir } = require("./server/logger");
|
||||||
const { initAutoUpdater } = require("./server/autoupdate.js");
|
const { AutoUpdater } = require("./server/autoupdate.js");
|
||||||
|
const gotLock = app.requestSingleInstanceLock();
|
||||||
|
|
||||||
|
let mainWindow;
|
||||||
|
|
||||||
|
if (!gotLock) {
|
||||||
|
app.quit(); // Une autre instance tourne déjà
|
||||||
|
} else {
|
||||||
|
app.on("second-instance", () => {
|
||||||
|
// Si une autre instance essaie de démarrer, focus la fenêtre existante
|
||||||
|
if (mainWindow) {
|
||||||
|
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||||
|
mainWindow.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.disableHardwareAcceleration(); // safe sur GPU old / soucis Electron
|
app.disableHardwareAcceleration(); // safe sur GPU old / soucis Electron
|
||||||
|
|
||||||
let mainWindow;
|
|
||||||
const logsFolderPath = logDir;
|
const logsFolderPath = logDir;
|
||||||
const defaultDownloadPath = path.join(os.homedir(), "Downloads", "Freedom Loader");
|
const defaultDownloadPath = path.join(os.homedir(), "Downloads", "Freedom Loader");
|
||||||
|
|
||||||
app.setAppUserModelId("com.masteracnolo.freedomloader"); // pour notifications Windows
|
app.setAppUserModelId("com.masteracnolo.freedomloader"); // pour notifications Windows
|
||||||
|
|
||||||
// ---------- FENÊTRE ---------- //
|
|
||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
logger.warn("La fenêtre existe déjà, pas de nouvelle création");
|
logger.warn("La fenêtre existe déjà, pas de nouvelle création");
|
||||||
@@ -106,7 +119,7 @@ app.whenReady().then(async () => {
|
|||||||
startRPC();
|
startRPC();
|
||||||
|
|
||||||
await createWindow();
|
await createWindow();
|
||||||
initAutoUpdater(mainWindow);
|
AutoUpdater(mainWindow);
|
||||||
setupMenu();
|
setupMenu();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Erreur serveur ou fenêtre :", err);
|
logger.error("Erreur serveur ou fenêtre :", err);
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
const { autoUpdater } = require("electron-updater");
|
const { autoUpdater } = require("electron-updater");
|
||||||
const { dialog, app } = require("electron");
|
const { app, Notification } = require("electron");
|
||||||
const { logger } = require("./logger");
|
const { logger } = require("./logger");
|
||||||
|
|
||||||
function initAutoUpdater(mainWindow) {
|
function AutoUpdater() {
|
||||||
|
|
||||||
autoUpdater.on("update-available", (info) => {
|
autoUpdater.on("update-available", (info) => {
|
||||||
logger.info(`Nouvelle version disponible : ${info.version}`);
|
logger.info(`Nouvelle version disponible : ${info.version}`);
|
||||||
if (mainWindow) {
|
new Notification({
|
||||||
mainWindow.webContents.send("update-available", info.version);
|
title: "Freedom Loader",
|
||||||
}
|
body: `Nouvelle version disponible : ${info.version}. L'application va redémarrer`
|
||||||
|
}).show();
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on("update-downloaded", (info) => {
|
autoUpdater.on("update-downloaded", (info) => {
|
||||||
logger.info(`Mise à jour téléchargée : ${info.version}`);
|
logger.info(`Mise à jour téléchargée : ${info.version}`);
|
||||||
if (mainWindow) {
|
new Notification({
|
||||||
mainWindow.webContents.send("update-downloaded", info.version);
|
title: "Freedom Loader",
|
||||||
}
|
body: `Mise à jour ${info.version} téléchargée.`
|
||||||
|
}).show();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
autoUpdater.quitAndInstall();
|
autoUpdater.quitAndInstall();
|
||||||
@@ -23,11 +26,15 @@ function initAutoUpdater(mainWindow) {
|
|||||||
|
|
||||||
autoUpdater.on("error", (err) => {
|
autoUpdater.on("error", (err) => {
|
||||||
logger.error("Erreur auto-update :", err.message);
|
logger.error("Erreur auto-update :", err.message);
|
||||||
|
new Notification({
|
||||||
|
title: "Freedom Loader - Erreur de mise à jour",
|
||||||
|
body: err.message
|
||||||
|
}).show();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(async () => {
|
||||||
try {
|
try {
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
await autoUpdater.checkForUpdates();
|
||||||
logger.info("Vérification des mises à jour effectuée");
|
logger.info("Vérification des mises à jour effectuée");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Erreur lors du check update :", err.message);
|
logger.error("Erreur lors du check update :", err.message);
|
||||||
@@ -35,4 +42,4 @@ function initAutoUpdater(mainWindow) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { initAutoUpdater };
|
module.exports = { AutoUpdater };
|
||||||
|
|||||||
Reference in New Issue
Block a user