mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-11-13 15:09:20 +01:00
fix(autoUpdate): improve error handling and UI reset during update process
This commit is contained in:
@@ -112,6 +112,7 @@ function initAutoUpdater(mainWindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.error("Auto update error:", err);
|
logger.error("Auto update error:", err);
|
||||||
|
mainWindow?.webContents.send("update-error", msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
@@ -122,6 +123,8 @@ function initAutoUpdater(mainWindow) {
|
|||||||
* Separated from init for reusability and testability.
|
* Separated from init for reusability and testability.
|
||||||
*/
|
*/
|
||||||
async function checkForUpdates() {
|
async function checkForUpdates() {
|
||||||
|
|
||||||
|
// If app is was installed from SNAP or Flatpak.
|
||||||
if (process.env.SNAP || process.env.FLATPAK_ID) return;
|
if (process.env.SNAP || process.env.FLATPAK_ID) return;
|
||||||
if (!require("electron").app.isPackaged) return;
|
if (!require("electron").app.isPackaged) return;
|
||||||
|
|
||||||
@@ -141,6 +144,7 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,10 +122,19 @@ contextBridge.exposeInMainWorld("electronAPI", {
|
|||||||
*/
|
*/
|
||||||
installUpdate: () => ipcRenderer.invoke("install-update"),
|
installUpdate: () => ipcRenderer.invoke("install-update"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to the update error event.
|
||||||
|
*
|
||||||
|
* @param {Function} callback - Function executed with error information when an update error occurs.
|
||||||
|
* @returns {Electron.IpcRenderer}
|
||||||
|
*/
|
||||||
|
onUpdateError: (callback) => ipcRenderer.on("update-error", (_, err) => callback(err)),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to the download progress event.
|
* Subscribes to the download progress event.
|
||||||
*
|
*
|
||||||
* @param {Function} callback - Function executed with progress metrics (percent, bytesPerSecond, transferred, total).
|
* @param {Function} callback - Function executed with progress metrics (percent, bytesPerSecond, transferred, total).
|
||||||
|
* @returns {Electron.IpcRenderer}
|
||||||
*/
|
*/
|
||||||
onDownloadProgress: (callback) =>
|
onDownloadProgress: (callback) =>
|
||||||
ipcRenderer.on("update-progress", (_, progress) => callback(progress)),
|
ipcRenderer.on("update-progress", (_, progress) => callback(progress)),
|
||||||
|
|||||||
@@ -50,6 +50,23 @@ async function initUpdateUI() {
|
|||||||
const initialTitleText = title.textContent;
|
const initialTitleText = title.textContent;
|
||||||
const initialSubText = sub.textContent;
|
const initialSubText = sub.textContent;
|
||||||
|
|
||||||
|
const resetUI = () => {
|
||||||
|
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.onUpdateError((err) => {
|
||||||
|
console.error("Update failed asynchronously:", err);
|
||||||
|
resetUI();
|
||||||
|
});
|
||||||
|
|
||||||
btn.onclick = async () => {
|
btn.onclick = async () => {
|
||||||
|
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
@@ -61,15 +78,7 @@ async function initUpdateUI() {
|
|||||||
try {
|
try {
|
||||||
await window.electronAPI.downloadUpdate();
|
await window.electronAPI.downloadUpdate();
|
||||||
} catch {
|
} catch {
|
||||||
btn.disabled = false;
|
resetUI();
|
||||||
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 = "";
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user