var g=Object.create;var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var S=(i,e)=>{for(var t in e)l(i,t,{get:e[t],enumerable:!0})},h=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!x.call(i,r)&&r!==t&&l(i,r,{get:()=>e[r],enumerable:!(n=y(e,r))||n.enumerable});return i};var w=(i,e,t)=>(t=i!=null?g(b(i)):{},h(e||!i||!i.__esModule?l(t,"default",{value:i,enumerable:!0}):t,i)),v=i=>h(l({},"__esModule",{value:!0}),i);var C={};S(C,{WinStateKeeper:()=>O,appConfig:()=>p});module.exports=v(C);var s=require("fs"),a=require("electron/main"),d=require("path"),u=require("../../common/modules/client"),c=require("../../common/global");const z=a.safeStorage.isEncryptionAvailable();function E(){return process.platform==="darwin"?!0:a.app.isReady()}const T=Object.freeze({settings:{general:{menuBar:{hide:!1},tray:{disable:!1},taskbar:{flash:!0},window:{transparent:!1,hideOnClose:!0}},privacy:{blockApi:{science:!0,sentry:!0,typingIndicator:!1,fingerprinting:!0},permissions:{video:null,audio:null,fullscreen:!0,notifications:null,"display-capture":!0,"background-sync":!1,"speaker-selection":!1,"clipboard-sanitized-write":!0}},advanced:{csp:{enabled:!0},cspThirdParty:{spotify:!0,gif:!0,hcaptcha:!0,youtube:!0,twitter:!0,twitch:!0,streamable:!0,vimeo:!0,soundcloud:!0,paypal:!0,audius:!0,algolia:!0,reddit:!0,googleStorageApi:!0},currentInstance:{radio:0},devel:{enabled:!1},redirection:{warn:!0},optimize:{gpu:!1},webApi:{webGl:!0},unix:{autoscroll:!1}}},update:{notification:{version:"",till:""}},screenShareStore:{audio:!1}});var k=(t=>(t.JSON=".json",t.Encrypted="",t))(k||{});class f{#e;#t;#i=null;defaultConfig;spaces=4;#s(e){const t=JSON.stringify(e,null,this.spaces);let n=t;this.#e===""&&(n=a.safeStorage.encryptString(t)),(0,s.writeFileSync)(this.#t+this.#e,n)}#r(){const e=(0,s.readFileSync)(this.#t+this.#e);let t=e.toString();try{return this.#e===""&&(t=a.safeStorage.decryptString(e)),JSON.parse(t)}catch(n){console.debug("[Config] Error in #read during config decoding."),console.debug(n)}return{}}set value(e){const t=(0,c.typeMerge)(this.value,{nullType:Boolean},e);this.#s(t),this.#i=t}get value(){if(this.#i!==null)return this.#i;const e=(0,c.typeMerge)(this.defaultConfig,{nullType:Boolean},this.#r());return this.#i=e,Object.freeze(e)}constructor(e,t,n,r){if(t&&!E())throw new Error("Cannot use encrypted configuration file when app is not ready yet!");switch(this.#t=e,this.#e=t&&a.safeStorage.isEncryptionAvailable()?"":".json",this.defaultConfig=Object.freeze(n),r!==void 0&&r>0&&(this.spaces=r),this.#e){case"":!(0,s.existsSync)(this.#t+"")&&(0,s.existsSync)(this.#t+".json")&&this.#s((0,s.readFileSync)(this.#t+".json")),(0,s.existsSync)(this.#t+".json")&&(0,s.rmSync)(this.#t+".json");break;case".json":(0,s.existsSync)(this.#t+"")&&(0,s.rmSync)(this.#t+"");break}let o;(0,s.existsSync)(this.#t+this.#e)?o={...this.defaultConfig,...this.value}:o=this.defaultConfig;try{this.#s(o),this.#i=o}catch{this.#s(this.defaultConfig),this.#i=this.defaultConfig}}}const p=new f((0,d.resolve)(a.app.getPath("userData"),"config"),z,T);class O extends f{#e;#t;initState;#i(e,t="resize"){switch(t){case"maximize":case"unmaximize":this.#t=Object.freeze({[this.#e]:Object.freeze({width:this.#t[this.#e]?.width??this.value[this.#e]?.width??e.getNormalBounds().width,height:this.#t[this.#e]?.height??this.value[this.#e]?.height??e.getNormalBounds().height,isMaximized:t==="maximize"})});break;default:if(e.isMaximized())return;this.#t=Object.freeze({[this.#e]:Object.freeze({width:e.getNormalBounds().width,height:e.getNormalBounds().height,isMaximized:this.#t[this.#e]?.isMaximized??this.value[this.#e]?.isMaximized??!1})})}console.debug(`[WIN] Electron event: ${t}`),console.debug(`[WIN] State changed to: ${JSON.stringify(this.#t[this.#e])}`)}watchState(e){e.on("resize",()=>setTimeout(()=>this.#i(e),10)),e.on("unmaximize",()=>this.#i(e,"unmaximize")),e.on("maximize",()=>this.#i(e,"maximize")),e.once("closed",()=>this.value=this.#t)}constructor(e,t=(0,d.resolve)(a.app.getPath("userData"),"windowState"),n){const r=Object.freeze({width:u.appInfo.minWinWidth+a.screen.getPrimaryDisplay().workAreaSize.width/3,height:u.appInfo.minWinHeight+a.screen.getPrimaryDisplay().workAreaSize.height/3,isMaximized:!1});super(t,!0,Object.freeze({[e]:r}),n),this.#e=e,this.initState=Object.freeze({width:this.value[this.#e]?.width??r.width,height:this.value[this.#e]?.height??r.height,isMaximized:this.value[this.#e]?.isMaximized??!1}),this.#t=this.value}}import("electron/main").then(i=>i.ipcMain).then(i=>i.on("settings-config-modified",(e,t)=>{e.senderFrame&&new URL(e.senderFrame.url).protocol==="file:"&&(p.value=t)}));0&&(module.exports={WinStateKeeper,appConfig});
