From d6de184bfd4731baf5cfd6dee16112a1ce5fb698 Mon Sep 17 00:00:00 2001 From: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com> Date: Wed, 12 Nov 2025 18:00:07 +0100 Subject: [PATCH] =?UTF-8?q?Autoupdate=20+=20FreedomKiller=20D=C3=A9marrage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 21 +++++++++++++++++---- server/autoupdate.js | 29 ++++++++++++++++++----------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index b1bc4b6..c75b160 100644 --- a/main.js +++ b/main.js @@ -3,17 +3,30 @@ const { app, BrowserWindow, ipcMain, dialog, Menu, shell } = require("electron") const path = require("path"); const os = require("os"); 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 -let mainWindow; const logsFolderPath = logDir; const defaultDownloadPath = path.join(os.homedir(), "Downloads", "Freedom Loader"); app.setAppUserModelId("com.masteracnolo.freedomloader"); // pour notifications Windows -// ---------- FENÊTRE ---------- // async function createWindow() { if (mainWindow) { logger.warn("La fenêtre existe déjà, pas de nouvelle création"); @@ -106,7 +119,7 @@ app.whenReady().then(async () => { startRPC(); await createWindow(); - initAutoUpdater(mainWindow); + AutoUpdater(mainWindow); setupMenu(); } catch (err) { logger.error("Erreur serveur ou fenêtre :", err); diff --git a/server/autoupdate.js b/server/autoupdate.js index bcc700a..01b70d0 100644 --- a/server/autoupdate.js +++ b/server/autoupdate.js @@ -1,20 +1,23 @@ const { autoUpdater } = require("electron-updater"); -const { dialog, app } = require("electron"); +const { app, Notification } = require("electron"); const { logger } = require("./logger"); -function initAutoUpdater(mainWindow) { +function AutoUpdater() { + autoUpdater.on("update-available", (info) => { logger.info(`Nouvelle version disponible : ${info.version}`); - if (mainWindow) { - mainWindow.webContents.send("update-available", info.version); - } + new Notification({ + title: "Freedom Loader", + body: `Nouvelle version disponible : ${info.version}. L'application va redémarrer` + }).show(); }); autoUpdater.on("update-downloaded", (info) => { logger.info(`Mise à jour téléchargée : ${info.version}`); - if (mainWindow) { - mainWindow.webContents.send("update-downloaded", info.version); - } + new Notification({ + title: "Freedom Loader", + body: `Mise à jour ${info.version} téléchargée.` + }).show(); setTimeout(() => { autoUpdater.quitAndInstall(); @@ -23,11 +26,15 @@ function initAutoUpdater(mainWindow) { autoUpdater.on("error", (err) => { 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 { - autoUpdater.checkForUpdatesAndNotify(); + await autoUpdater.checkForUpdates(); logger.info("Vérification des mises à jour effectuée"); } catch (err) { logger.error("Erreur lors du check update :", err.message); @@ -35,4 +42,4 @@ function initAutoUpdater(mainWindow) { }); } -module.exports = { initAutoUpdater }; +module.exports = { AutoUpdater };