2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
9d09cf1b5d Handle updater download failures for retry UI
Co-authored-by: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com>
2026-09-27 16:09:55 +00:00
copilot-swe-agent[bot]
c80d65483a Initial plan 2026-09-27 16:07:06 +00:00
5 changed files with 76 additions and 10 deletions

View File

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

View File

@@ -16,12 +16,7 @@ async function sendReport(params) {
if (includeLogs === "yes" && logDir) {
// YYYY-MM-DD
const now = new Date();
const today = [
now.getFullYear(),
String(now.getMonth() + 1).padStart(2, "0"),
String(now.getDate()).padStart(2, "0")
].join("-");
const today = new Date().toISOString().split("T")[0];
const logFilePath = path.join(logDir, `LOGS-${today}.log`);

View File

@@ -45,13 +45,31 @@ async function initUpdateUI() {
return;
}
btn.onclick = () => {
window.electronAPI.downloadUpdate();
const initialButtonText = btn.textContent;
const initialIconText = icon.textContent;
const initialTitleText = title.textContent;
const initialSubText = sub.textContent;
btn.onclick = async () => {
btn.disabled = true;
btn.textContent = "Downloading...";
icon.textContent = "download";
title.textContent = "Downloading update";
progressWrap.style.display = "flex";
try {
await window.electronAPI.downloadUpdate();
} catch {
btn.disabled = false;
btn.textContent = initialButtonText;
icon.textContent = initialIconText;
title.textContent = initialTitleText;
sub.textContent = initialSubText;
progressWrap.style.display = "none";
progressFill.style.width = "0%";
progressPct.textContent = "0%";
progressEta.textContent = "";
}
};
window.electronAPI.onDownloadProgress((progress) => {

View File

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

View File

@@ -0,0 +1,53 @@
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");
});
});