mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
Notify Logic
This commit is contained in:
47
main.js
47
main.js
@@ -1,33 +1,36 @@
|
|||||||
const config = require("./config.js")
|
const config = require("./config.js");
|
||||||
const { app, BrowserWindow, ipcMain, dialog, Menu, shell } = require("electron");
|
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 { AutoUpdater } = require("./server/update.js");
|
const { AutoUpdater } = require("./server/update.js");
|
||||||
const gotLock = app.requestSingleInstanceLock();
|
|
||||||
|
|
||||||
let mainWindow;
|
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();
|
|
||||||
|
|
||||||
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
|
||||||
|
app.disableHardwareAcceleration();
|
||||||
|
|
||||||
async function createWindow() {
|
// Gestion single instance
|
||||||
|
const gotLock = app.requestSingleInstanceLock();
|
||||||
|
|
||||||
|
if (!gotLock) {
|
||||||
|
// Une instance existe déjà → fermer l'ancienne et continuer la nouvelle
|
||||||
|
// Ici la nouvelle instance continue normalement
|
||||||
|
} else {
|
||||||
|
app.on("second-instance", () => {
|
||||||
|
// La vieille instance se ferme
|
||||||
|
if (mainWindow) {
|
||||||
|
logger.info("Nouvelle instance détectée, fermeture de l'ancienne...");
|
||||||
|
mainWindow.destroy();
|
||||||
|
mainWindow = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création fenêtre principale
|
||||||
|
async function createMainWindow() {
|
||||||
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");
|
||||||
return;
|
return;
|
||||||
@@ -77,10 +80,10 @@ ipcMain.handle("select-download-folder", async () => {
|
|||||||
ipcMain.handle("get-default-download-path", () => defaultDownloadPath);
|
ipcMain.handle("get-default-download-path", () => defaultDownloadPath);
|
||||||
|
|
||||||
ipcMain.on("set-progress", (event, percent) => {
|
ipcMain.on("set-progress", (event, percent) => {
|
||||||
mainWindow.setProgressBar(percent / 100); // Electron attend 0 → 1
|
if (mainWindow) mainWindow.setProgressBar(percent / 100); // Electron attend 0 → 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Menu
|
||||||
function setupMenu() {
|
function setupMenu() {
|
||||||
const menuTemplate = [
|
const menuTemplate = [
|
||||||
{
|
{
|
||||||
@@ -111,6 +114,7 @@ function setupMenu() {
|
|||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(mergedTemplate));
|
Menu.setApplicationMenu(Menu.buildFromTemplate(mergedTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// App ready
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
logSessionStart();
|
logSessionStart();
|
||||||
logger.info("App prête, démarrage du serveur Express...");
|
logger.info("App prête, démarrage du serveur Express...");
|
||||||
@@ -125,7 +129,7 @@ app.whenReady().then(async () => {
|
|||||||
const { startRPC } = require("./server/discordRPC");
|
const { startRPC } = require("./server/discordRPC");
|
||||||
startRPC();
|
startRPC();
|
||||||
|
|
||||||
await createWindow();
|
await createMainWindow();
|
||||||
AutoUpdater(mainWindow);
|
AutoUpdater(mainWindow);
|
||||||
setupMenu();
|
setupMenu();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -134,7 +138,6 @@ app.whenReady().then(async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
logger.info("Toutes fenêtres fermées, quitte l'app");
|
logger.info("Toutes fenêtres fermées, quitte l'app");
|
||||||
if (process.platform !== "darwin") app.quit();
|
if (process.platform !== "darwin") app.quit();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const path = require("path");
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { logger } = require("../logger");
|
const { logger } = require("../logger");
|
||||||
const { buildYtDlpArgs } = require("../helpers/buildArgs");
|
const { buildYtDlpArgs } = require("../helpers/buildArgs");
|
||||||
|
const notify = require("../helpers/notify")
|
||||||
|
|
||||||
function fetchDownload(options, listeners, speedListeners) {
|
function fetchDownload(options, listeners, speedListeners) {
|
||||||
|
|
||||||
@@ -43,6 +44,9 @@ function fetchDownload(options, listeners, speedListeners) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (line.match(/ERROR: Could not copy .* cookie database/i)) {
|
||||||
|
notify.notifyCookiesBrowserError();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user