mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-11-13 15:09:20 +01:00
Compare commits
4 Commits
1e099f6bb6
...
8614b0e32e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8614b0e32e | ||
|
|
c212302550 | ||
|
|
0835e13840 | ||
|
|
1c0dd32732 |
@@ -1,2 +0,0 @@
|
||||
BUG_REPORT_URL=
|
||||
BUG_REPORT_API_KEY=
|
||||
@@ -19,7 +19,7 @@ const config = require("../config");
|
||||
const { validateDownloadPath, getDefaultDownloadPath } = require("./pathValidator");
|
||||
const { userThemesPath } = require("../server/helpers/path.helpers");
|
||||
const { createSystemTray, destroyTray } = require("./tray");
|
||||
const { sendReport } = require("./sendReport");
|
||||
const {sendReport, checkReportService, getReportServiceStatus} = require("./sendReport");
|
||||
const { isUpdateAvailable, downloadUpdate, installUpdate } = require("./autoUpdater");
|
||||
|
||||
/**
|
||||
@@ -210,6 +210,11 @@ function registerIpcHandlers(getMainWindow) {
|
||||
return await sendReport(params);
|
||||
});
|
||||
|
||||
ipcMain.handle("get-report-service-status", async () => {
|
||||
await checkReportService();
|
||||
return getReportServiceStatus();
|
||||
});
|
||||
|
||||
ipcMain.handle("is-update-available", () => {
|
||||
return isUpdateAvailable();
|
||||
});
|
||||
|
||||
@@ -2,6 +2,58 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const {logger, logDir} = require("../server/logger");
|
||||
|
||||
const REPORT_URL = "https://freedom-loader-report.acnolo.fr";
|
||||
const REPORT_SERVICE_TIMEOUT_MS = 5000;
|
||||
let reportServiceStatus = {
|
||||
status: "checking",
|
||||
message: "Checking bug report service..."
|
||||
};
|
||||
let reportServiceCheck = null;
|
||||
|
||||
async function checkReportService() {
|
||||
if (reportServiceCheck) {
|
||||
return reportServiceCheck;
|
||||
}
|
||||
|
||||
reportServiceCheck = (async () => {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), REPORT_SERVICE_TIMEOUT_MS);
|
||||
|
||||
try {
|
||||
const response = await fetch(REPORT_URL, {
|
||||
method: "GET",
|
||||
signal: controller.signal
|
||||
});
|
||||
|
||||
if (response.status >= 500) {
|
||||
throw new Error(`Server responded with status ${response.status}`);
|
||||
}
|
||||
|
||||
reportServiceStatus = {
|
||||
status: "online",
|
||||
message: "Bug report service is available."
|
||||
};
|
||||
logger.info(`Bug report service is reachable (status ${response.status}).`);
|
||||
} catch (err) {
|
||||
reportServiceStatus = {
|
||||
status: "offline",
|
||||
message: "Bug report service is unavailable. Reports may fail to send."
|
||||
};
|
||||
logger.warn(`Bug report service is unreachable: ${err.message}`);
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
return reportServiceStatus;
|
||||
})();
|
||||
|
||||
return reportServiceCheck;
|
||||
}
|
||||
|
||||
function getReportServiceStatus() {
|
||||
return reportServiceStatus;
|
||||
}
|
||||
|
||||
async function sendReport(params) {
|
||||
try {
|
||||
const {title, description, includeLogs} = params;
|
||||
@@ -35,13 +87,7 @@ async function sendReport(params) {
|
||||
}
|
||||
}
|
||||
|
||||
const reportUrl = process.env.BUG_REPORT_URL;
|
||||
|
||||
if (!reportUrl) {
|
||||
throw new Error("Bug report service is not configured. Missing BUG_REPORT_URL on backend.");
|
||||
}
|
||||
|
||||
const response = await fetch(reportUrl, {
|
||||
const response = await fetch(REPORT_URL, {
|
||||
method: "POST",
|
||||
body: formData
|
||||
});
|
||||
@@ -59,4 +105,4 @@ async function sendReport(params) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {sendReport};
|
||||
module.exports = {sendReport, checkReportService, getReportServiceStatus};
|
||||
9
main.js
9
main.js
@@ -77,11 +77,7 @@ const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./
|
||||
const { userThemesPath, initUserThemes, validateBinaries, defaultDownloadFolder } = require("./server/helpers/path.helpers");
|
||||
const {createSystemTray, destroyTray} = require("./app/tray");
|
||||
const { stopServer } = require("./server/server");
|
||||
|
||||
/**
|
||||
* Expose .env in process.env
|
||||
*/
|
||||
require("dotenv").config();
|
||||
const {checkReportService} = require("./app/sendReport");
|
||||
|
||||
/**
|
||||
* Global flag indicating if the application is intentionally shutting down.
|
||||
@@ -137,6 +133,9 @@ app.on("second-instance", () => {
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
logSessionStart(logDir, defaultDownloadFolder);
|
||||
checkReportService().catch((err) => {
|
||||
logger.warn(`Bug report service startup check failed: ${err.message}`);
|
||||
});
|
||||
|
||||
createSplashWindow();
|
||||
|
||||
|
||||
17
package-lock.json
generated
17
package-lock.json
generated
@@ -1,18 +1,17 @@
|
||||
{
|
||||
"name": "freedom-loader",
|
||||
"version": "1.6.4-preview",
|
||||
"version": "1.6.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "freedom-loader",
|
||||
"version": "1.6.4-preview",
|
||||
"version": "1.6.4",
|
||||
"license": "GPL-3.0-only",
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.2",
|
||||
"debug": "^4.4.1",
|
||||
"discord-rpc": "^4.0.1",
|
||||
"dotenv": "^17.4.2",
|
||||
"electron-updater": "^6.6.2",
|
||||
"express": "^5.1.0",
|
||||
"express-rate-limit": "^8.2.1",
|
||||
@@ -4193,18 +4192,6 @@
|
||||
"js-yaml": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "17.4.2",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz",
|
||||
"integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv-expand": {
|
||||
"version": "11.0.7",
|
||||
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-11.0.7.tgz",
|
||||
|
||||
14
package.json
14
package.json
@@ -40,7 +40,6 @@
|
||||
"chalk": "^4.1.2",
|
||||
"debug": "^4.4.1",
|
||||
"discord-rpc": "^4.0.1",
|
||||
"dotenv": "^17.4.2",
|
||||
"electron-updater": "^6.6.2",
|
||||
"express": "^5.1.0",
|
||||
"express-rate-limit": "^8.2.1",
|
||||
@@ -75,10 +74,15 @@
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"**/*",
|
||||
"node_modules/**/*",
|
||||
"!config/config.dev.json",
|
||||
"!theme/**/*"
|
||||
"app/**/*",
|
||||
"public/**/*",
|
||||
"server/**/*",
|
||||
"build/**/*",
|
||||
"config/config.default.json",
|
||||
"config.js",
|
||||
"main.js",
|
||||
"preload.js",
|
||||
"package.json"
|
||||
],
|
||||
"directories": {
|
||||
"buildResources": "build"
|
||||
|
||||
@@ -214,4 +214,9 @@ contextBridge.exposeInMainWorld("topbarAPI", {
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
sendReport: (params) => ipcRenderer.invoke("send-report", params),
|
||||
|
||||
/**
|
||||
* Returns the startup health status of the bug report service.
|
||||
*/
|
||||
getReportServiceStatus: () => ipcRenderer.invoke("get-report-service-status"),
|
||||
});
|
||||
@@ -29,9 +29,13 @@ class BugReportModal {
|
||||
<option value="no" style="background:#2a2a2a !important; color:#ffffff !important;">No</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="bugReportServiceStatus" role="status" aria-live="polite" style="display:none !important; align-items:center !important; gap:8px !important; color:#aaaaaa !important; font-size:0.8rem !important;">
|
||||
<span id="bugReportServiceStatusDot" style="width:8px !important; height:8px !important; border-radius:50% !important; background:#f59e0b !important; flex-shrink:0 !important;"></span>
|
||||
<span id="bugReportServiceStatusText">Checking bug report service...</span>
|
||||
</div>
|
||||
<div style="display:flex !important; justify-content:flex-end !important; gap:8px !important; margin-top:8px !important;">
|
||||
<button type="button" id="bugCancelBtn" style="background:#333333 !important; border:none !important; color:#cccccc !important; padding:8px 14px !important; border-radius:6px !important; cursor:pointer !important;">Cancel</button>
|
||||
<button type="submit" style="background:#4f46e5 !important; border:none !important; color:#ffffff !important; padding:8px 16px !important; border-radius:6px !important; cursor:pointer !important; font-weight:500 !important;">Send</button>
|
||||
<button type="submit" id="bugSendBtn" disabled style="background:#4f46e5 !important; border:none !important; color:#ffffff !important; padding:8px 16px !important; border-radius:6px !important; cursor:not-allowed !important; opacity:0.5 !important; font-weight:500 !important;">Send</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -46,6 +50,7 @@ class BugReportModal {
|
||||
bindEvents() {
|
||||
const titleInput = this.modal.querySelector("#bugTitle");
|
||||
const descInput = this.modal.querySelector("#bugDescription");
|
||||
const sendButton = this.modal.querySelector("#bugSendBtn");
|
||||
|
||||
titleInput.addEventListener("input", () => {
|
||||
localStorage.setItem("draft_bug_title", titleInput.value);
|
||||
@@ -67,6 +72,10 @@ class BugReportModal {
|
||||
|
||||
this.form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
if (sendButton.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
title: titleInput.value,
|
||||
description: descInput.value,
|
||||
@@ -107,11 +116,46 @@ class BugReportModal {
|
||||
open() {
|
||||
this.loadState();
|
||||
this.modal.style.display = "flex";
|
||||
this.updateServiceStatus();
|
||||
}
|
||||
|
||||
close() {
|
||||
this.modal.style.display = "none";
|
||||
}
|
||||
|
||||
async updateServiceStatus() {
|
||||
const statusText = this.modal.querySelector("#bugReportServiceStatusText");
|
||||
const statusDot = this.modal.querySelector("#bugReportServiceStatusDot");
|
||||
const sendButton = this.modal.querySelector("#bugSendBtn");
|
||||
|
||||
sendButton.disabled = true;
|
||||
sendButton.style.setProperty("cursor", "not-allowed", "important");
|
||||
sendButton.style.setProperty("opacity", "0.5", "important");
|
||||
|
||||
try {
|
||||
const serviceStatus = await window.topbarAPI.getReportServiceStatus();
|
||||
const serviceAvailable = serviceStatus.status === "online";
|
||||
const statusVisible = !serviceAvailable;
|
||||
statusText.textContent = serviceStatus.message;
|
||||
statusDot.style.background = "#ef4444";
|
||||
statusText.style.color = "#fca5a5";
|
||||
this.modal.querySelector("#bugReportServiceStatus").style.setProperty(
|
||||
"display",
|
||||
statusVisible ? "flex" : "none",
|
||||
"important"
|
||||
);
|
||||
sendButton.disabled = !serviceAvailable;
|
||||
sendButton.style.setProperty("cursor", serviceAvailable ? "pointer" : "not-allowed", "important");
|
||||
sendButton.style.setProperty("opacity", serviceAvailable ? "1" : "0.5", "important");
|
||||
} catch (err) {
|
||||
statusText.textContent = "Unable to check bug report service.";
|
||||
statusDot.style.background = "#ef4444";
|
||||
statusText.style.color = "#fca5a5";
|
||||
this.modal.querySelector("#bugReportServiceStatus").style.setProperty("display", "flex", "important");
|
||||
sendButton.disabled = true;
|
||||
window.electronAPI.logError("Failed to retrieve bug report service status:", err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.bugModal = new BugReportModal();
|
||||
|
||||
Reference in New Issue
Block a user