"use strict";var l=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var r=(e,t)=>l(e,"name",{value:t,configurable:true});var m=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:true})};var U=(e,t,a,n)=>{if(t&&typeof t==="object"||typeof t==="function"){for(let d of c(t))if(!b.call(e,d)&&d!==a)l(e,d,{get:()=>t[d],enumerable:!(n=f(t,d))||n.enumerable})}return e};var v=e=>U(l({},"__esModule",{value:true}),e);var g={};m(g,{default:()=>W});module.exports=v(g);var s=require("electron");var o=require("electron-updater");var u=require("../..");var p=require("../../environment");const i=require("../../preload-safe-debug")("Ferdium:ipcApi:autoUpdate");var W=r(e=>{const t=Boolean(e.settings.app.get("automaticUpdates"));if(t){if(p.isSnap){o.autoUpdater.autoDownload=false}s.ipcMain.on("autoUpdate",(a,n)=>{if(t){try{o.autoUpdater.autoInstallOnAppQuit=false;o.autoUpdater.allowPrerelease=Boolean(e.settings.app.get("beta"));if(n.action==="check"){i("checking for update");o.autoUpdater.checkForUpdates()}else if(n.action==="install"){if(p.isSnap){return}i("installing update");u.appEvents.emit("install-update");const d=s.BrowserWindow.getAllWindows();for(const w of d)w.close();o.autoUpdater.quitAndInstall()}}catch(d){a.sender.send("autoUpdate",{error:d})}}});o.autoUpdater.on("update-not-available",()=>{i("update-not-available");e.mainWindow.webContents.send("autoUpdate",{available:false})});o.autoUpdater.on("update-available",a=>{i("update-available");if(t){e.mainWindow.webContents.send("autoUpdate",{version:a.version,available:true})}});o.autoUpdater.on("download-progress",a=>{let n=`Download speed: ${a.bytesPerSecond}`;n=`${n} - Downloaded ${a.percent}%`;n=`${n} (${a.transferred}/${a.total})`;i(n)});o.autoUpdater.on("update-downloaded",()=>{i("update-downloaded");e.mainWindow.webContents.send("autoUpdate",{downloaded:true})});o.autoUpdater.on("error",a=>{i("update-error");e.mainWindow.webContents.send("autoUpdate",{error:a})})}else{o.autoUpdater.autoInstallOnAppQuit=false;o.autoUpdater.autoDownload=false}},"default");
