Compare commits

..

5 Commits

Author SHA1 Message Date
MasterAcnolo
ac1d74ff23 fix(autoUpdate): better error handling in frontEnd
#50
2026-09-27 21:19:48 +02:00
copilot-swe-agent[bot]
7f86d46ae7 fix: validate backend bug report configuration before request
Co-authored-by: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com>
2026-09-27 18:31:59 +00:00
MasterAcnolo
187e3af559 fix: log transport names files local date 2026-09-27 20:03:25 +02:00
MasterAcnolo
e8c499fe23 fix: sendReport wrong IPC instance 2026-09-27 20:02:56 +02:00
MasterAcnolo
99b7164ff8 fix(update): don't check for update if the app is installed with SNAP or Flatpak 2026-09-27 16:23:28 +02:00
5 changed files with 18 additions and 58 deletions

View File

@@ -122,6 +122,7 @@ function initAutoUpdater(mainWindow) {
* Separated from init for reusability and testability. * Separated from init for reusability and testability.
*/ */
async function checkForUpdates() { async function checkForUpdates() {
if (process.env.SNAP || process.env.FLATPAK_ID) return;
if (!require("electron").app.isPackaged) return; if (!require("electron").app.isPackaged) return;
try { try {
@@ -140,7 +141,6 @@ async function downloadUpdate() {
await autoUpdater.downloadUpdate(); await autoUpdater.downloadUpdate();
} catch (err) { } catch (err) {
logger.error("Download failed:", err.message); logger.error("Download failed:", err.message);
throw err;
} }
} }

View File

@@ -16,7 +16,12 @@ async function sendReport(params) {
if (includeLogs === "yes" && logDir) { if (includeLogs === "yes" && logDir) {
// YYYY-MM-DD // YYYY-MM-DD
const today = new Date().toISOString().split("T")[0]; const now = new Date();
const today = [
now.getFullYear(),
String(now.getMonth() + 1).padStart(2, "0"),
String(now.getDate()).padStart(2, "0")
].join("-");
const logFilePath = path.join(logDir, `LOGS-${today}.log`); const logFilePath = path.join(logDir, `LOGS-${today}.log`);
@@ -30,10 +35,17 @@ async function sendReport(params) {
} }
} }
const response = await fetch(process.env.BUG_REPORT_URL, { const reportUrl = process.env.BUG_REPORT_URL;
const reportApiKey = process.env.BUG_REPORT_API_KEY;
if (!reportUrl || !reportApiKey) {
throw new Error("Bug report service is not configured. Missing BUG_REPORT_URL or BUG_REPORT_API_KEY on backend.");
}
const response = await fetch(reportUrl, {
method: "POST", method: "POST",
headers: { headers: {
"X-Api-Key": process.env.BUG_REPORT_API_KEY "X-Api-Key": reportApiKey
}, },
body: formData body: formData
}); });

View File

@@ -51,6 +51,7 @@ async function initUpdateUI() {
const initialSubText = sub.textContent; const initialSubText = sub.textContent;
btn.onclick = async () => { btn.onclick = async () => {
btn.disabled = true; btn.disabled = true;
btn.textContent = "Downloading..."; btn.textContent = "Downloading...";
icon.textContent = "download"; icon.textContent = "download";

View File

@@ -76,7 +76,7 @@ class BugReportModal {
window.electronAPI.logInfo("Submitting:", data); window.electronAPI.logInfo("Submitting:", data);
try { try {
const success = await window.electronAPI.sendReport(data); const success = await window.topbarAPI.sendReport(data);
if (success) { if (success) {
localStorage.removeItem("draft_bug_title"); localStorage.removeItem("draft_bug_title");

View File

@@ -1,53 +0,0 @@
const mockDownloadUpdate = jest.fn();
const mockCheckForUpdates = jest.fn();
const mockOn = jest.fn();
const mockQuitAndInstall = jest.fn();
jest.mock("electron-updater", () => ({
autoUpdater: {
autoDownload: true,
autoInstallOnAppQuit: true,
on: mockOn,
checkForUpdates: mockCheckForUpdates,
downloadUpdate: mockDownloadUpdate,
quitAndInstall: mockQuitAndInstall,
},
}));
jest.mock("electron", () => ({
app: {
isPackaged: true,
},
}));
const mockLoggerError = jest.fn();
jest.mock("../../server/logger", () => ({
logger: {
info: jest.fn(),
warn: jest.fn(),
error: mockLoggerError,
},
}));
const { downloadUpdate } = require("../../app/autoUpdater");
describe("autoUpdater.downloadUpdate", () => {
beforeEach(() => {
jest.clearAllMocks();
});
test("resolves when electron-updater download succeeds", async () => {
mockDownloadUpdate.mockResolvedValue(undefined);
await expect(downloadUpdate()).resolves.toBeUndefined();
expect(mockDownloadUpdate).toHaveBeenCalledTimes(1);
});
test("rejects when electron-updater download fails", async () => {
const error = new Error("network down");
mockDownloadUpdate.mockRejectedValue(error);
await expect(downloadUpdate()).rejects.toThrow("network down");
expect(mockLoggerError).toHaveBeenCalledWith("Download failed:", "network down");
});
});