(()=>{var e={3:e=>{"use strict";e.exports=require("path")},157:e=>{"use strict";e.exports=require("electron")},200:e=>{"use strict";e.exports=require("child_process")},383:e=>{"use strict";e.exports=require("fs")}},t={};function o(n){var s=t[n];if(void 0!==s)return s.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,o),r.exports}const{app:n,BrowserWindow:s,Menu:r,ipcMain:i}=o(157),a=o(3),{spawn:c}=o(200),l=o(383);let d,p;const u=a.join(n.getPath("userData"),"settings.json");let f;const h={x:void 0,y:void 0,scale:1,opacity:1,color:"#ffffff",font:"Segoe UI",carousel:!1,alwaysOnTop:!1};function y(){try{l.writeFileSync(u,JSON.stringify(f,null,2))}catch(e){console.error("Failed to save settings:",e)}}!function(){try{if(l.existsSync(u)){const e=JSON.parse(l.readFileSync(u,"utf-8"));f={...h,...e}}else f={...h}}catch(e){console.error("Failed to load settings, using defaults:",e),f={...h}}}(),n.whenReady().then(()=>{!function(){let e;d=new s({x:f.x,y:f.y,width:850,height:300,transparent:!0,frame:!1,alwaysOnTop:f.alwaysOnTop,skipTaskbar:!0,webPreferences:{preload:a.join(__dirname,"preload.js")}}),d.loadFile("index.html"),d.setIgnoreMouseEvents(!0,{forward:!0}),function(){const e=[50,75,100].map(e=>({label:`${e}%`,type:"radio",checked:f.scale===e/100,click:()=>{f.scale=e/100,y(),d.webContents.send("set-scale",f.scale)}})),t=[];for(let e=10;e<=100;e+=10)t.push({label:`${e}%`,type:"radio",checked:Math.round(100*f.opacity)===e,click:()=>{f.opacity=e/100,y(),d.webContents.send("set-opacity",f.opacity)}});const o="Segoe UI",n={label:"Default (Segoe UI)",type:"radio",checked:f.font===o,click:()=>{f.font=o,y(),d.webContents.send("set-font",o)}},s=a.join(__dirname,"fonts"),i=(l.existsSync(s)?l.readdirSync(s).filter(e=>e.endsWith(".ttf")||e.endsWith(".otf")):[]).map(e=>{const t=a.basename(e,a.extname(e));return{label:t,type:"radio",checked:f.font===t,click:()=>{f.font=t,y(),d.webContents.send("set-font",t)}}}),c=[n,{type:"separator"}].concat(i),p=[{label:"Window Mode",submenu:[{label:"Desktop Mode (Default)",type:"radio",checked:!f.alwaysOnTop,click:()=>{f.alwaysOnTop=!1,y(),d.setAlwaysOnTop(!1)}},{label:"Always on Top",type:"radio",checked:f.alwaysOnTop,click:()=>{f.alwaysOnTop=!0,y(),d.setAlwaysOnTop(!0,"screen-saver")}}]},{label:"Sizing",submenu:e},{label:"Title Carousel",type:"checkbox",checked:f.carousel,click:e=>{f.carousel=e.checked,y(),d.webContents.send("toggle-carousel",f.carousel)}},{label:"Opacity",submenu:t},{label:"Pick Color...",click:()=>d.webContents.send("open-color-picker")},{label:"Font",submenu:c},{type:"separator"},{label:"Quit",role:"quit"}],u=r.buildFromTemplate(p);d.webContents.on("context-menu",(e,t)=>{u.popup(d,t.x,t.y)})}(),d.webContents.once("did-finish-load",()=>{d.webContents.send("apply-settings",f)}),d.on("move",()=>{clearTimeout(e),e=setTimeout(()=>{const[e,t]=d.getPosition();f.x=e,f.y=t,y()},250)})}();const e=a.join(__dirname,"media_controller.exe");p=c(e),p.stdout.on("data",e=>{e.toString().split("\n").forEach(e=>{if(e)try{const t=JSON.parse(e);d&&d.webContents.send("update-media",t)}catch(e){}})}),setInterval(()=>{p&&!p.killed&&p.stdin.write("ping\n")},3e3),p.on("error",e=>{console.error("Failed to start backend process:",e)}),p.stderr.on("data",e=>{console.error(`Python Error: ${e}`)}),p.on("close",e=>{0!==e&&console.error(`Backend process exited with code ${e}`)})}),n.on("before-quit",()=>{if(d){const[e,t]=d.getPosition();f.x=e,f.y=t}y()}),n.on("will-quit",()=>{p&&p.kill()}),i.on("set-interactive",()=>d.setIgnoreMouseEvents(!1)),i.on("set-click-through",()=>d.setIgnoreMouseEvents(!0,{forward:!0})),i.on("move-window",(e,{deltaX:t,deltaY:o})=>{if(d){const[e,n]=d.getPosition();d.setPosition(e+t,n+o,!1)}}),i.on("save-setting",(e,{key:t,value:o})=>{f[t]=o,y()}),i.handle("get-fonts",()=>{const e=a.join(__dirname,"fonts");try{return l.readdirSync(e).filter(e=>e.endsWith(".ttf")||e.endsWith(".otf"))}catch{return[]}}),i.on("media-control",(e,t)=>{if(p&&!p.killed){const e=JSON.stringify({command:t});p.stdin.write(e+"\n")}}),i.on("request-resize",(e,{width:t,height:o})=>{if(d){const e=d.getBounds(),n=Math.round(t)+40,s=Math.round(o)+40;(Math.abs(e.width-n)>2||Math.abs(e.height-s)>2)&&d.setBounds({width:n,height:s},!0)}})})();