"use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var l=(o,e)=>s(o,"name",{value:e,configurable:true});var m=(o,e)=>{for(var t in e)s(o,t,{get:e[t],enumerable:true})};var y=(o,e,t,a)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let r of u(e))if(!h.call(o,r)&&r!==t)s(o,r,{get:()=>e[r],enumerable:!(a=g(e,r))||a.enumerable})}return o};var P=o=>y(s({},"__esModule",{value:true}),o);var b={};m(b,{default:()=>D});module.exports=P(b);var i=require("electron");var c=require("electron-dl");var p=require("fs-extra");const d=require("../../preload-safe-debug")("Ferdium:ipcApi:download");const v=l(o=>{const e=o.match(/^data:([+/A-Za-z-]+);base64,(.+)$/);if(e?.length!==3){return new Error("Invalid input string")}return Buffer.from(e[2],"base64")},"decodeBase64Image");var D=l(o=>{i.ipcMain.on("download-file",async(e,{url:t,content:a,fileOptions:r={}})=>{const w=i.BrowserWindow.getFocusedWindow();try{if(a){try{const n=await i.dialog.showSaveDialog(o.mainWindow,{defaultPath:r.name});if(n.canceled)return;const f=v(a);(0,p.writeFileSync)(n.filePath,f,"binary");d("File blob saved to",n.filePath)}catch(n){console.error(n)}}else{const n=await(0,c.download)(w,t,{saveAs:true});d("File saved to",n.savePath)}}catch(n){console.error(n)}});i.ipcMain.handle("download-folder-select",async()=>{const e={properties:["openDirectory"]};const t=o.settings?.app?.get("downloadFolderPath");if(typeof t==="string"&&t!==""){e.defaultPath=t}const a=await i.dialog.showOpenDialog(o.mainWindow,e);if(a.canceled)return null;return a.filePaths[0]})},"default");
