"use strict";var W=Object.create;var d=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var x=Object.getPrototypeOf;var R=Object.prototype.hasOwnProperty;var a=(i,e)=>d(i,"name",{value:e,configurable:true});var k=(i,e)=>{for(var s in e)d(i,s,{get:e[s],enumerable:true})};var h=(i,e,s,r)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let t of _(e))if(!R.call(i,t)&&t!==s)d(i,t,{get:()=>e[t],enumerable:!(r=b(e,t))||r.enumerable})}return i};var I=(i,e,s)=>(s=i!=null?W(x(i)):{},h(e||!i||!i.__esModule?d(s,"default",{value:i,enumerable:true}):s,i));var y=i=>h(d({},"__esModule",{value:true}),i);var v=(i,e,s,r)=>{var t=r>1?void 0:r?b(e,s):e;for(var p=i.length-1,l;p>=0;p--)if(l=i[p])t=(r?l(e,s,t):l(t))||t;if(r&&t)d(e,s,t);return t};var U={};k(U,{default:()=>F});module.exports=y(U);var T=require("react/jsx-runtime");var u=require("node:path");var n=require("mobx");var m=require("mobx-react");var f=require("react");var g=I(require("react-electron-web-view"));const w=require("../../../preload-safe-debug")("Ferdium:Services");let o=class extends f.Component{webview=null;constructor(e){super(e);this.refocusWebview=this.refocusWebview.bind(this);this._setWebview=this._setWebview.bind(this);(0,n.makeObservable)(this);(0,n.reaction)(()=>this.webview,()=>{if(this.webview?.view){this.webview.view.addEventListener("console-message",s=>{w("Service logged a message:",s.message)});this.webview.view.addEventListener("did-navigate",()=>{if(this.props.service._webview){document.title=`Ferdium - ${this.props.service.name} ${this.props.service.dialogTitle?` - ${this.props.service.dialogTitle}`:""} ${`- ${this.props.service._webview.getTitle()}`}`}})}})}componentWillUnmount(){const{service:e,detachService:s}=this.props;s({service:e})}refocusWebview(){const{webview:e}=this;w("Refocus Webview is called",this.props.service);if(!e){return}if(this.props.service.isActive){e.view.blur();e.view.focus();window.setTimeout(()=>{document.title=`Ferdium - ${this.props.service.name} ${this.props.service.dialogTitle?` - ${this.props.service.dialogTitle}`:""} ${`- ${this.props.service._webview.getTitle()}`}`},100)}else{w("Refocus not required - Not active service")}}_setWebview(e){this.webview=e}render(){const{service:e,setWebviewReference:s,isSpellcheckerEnabled:r,stores:t}=this.props;const{sandboxServices:p}=t.settings.app;const{sandboxServices:l}=t.app;const $=a(()=>{const c=l.find(S=>S.services.includes(e.id));if(c){return`persist:sandbox-${c.id}`}return e.partition},"checkForSandbox");const E=(0,u.join)(__dirname,"..","..","..","webview","recipe.js");return(0,T.jsx)(g.default,{ref:c=>{this._setWebview(c);if(c?.view){c.view.addEventListener("did-stop-loading",this.refocusWebview)}},autosize:true,src:e.url,preload:E,partition:p?$():"persist:general-session",onDidAttach:()=>{setTimeout(()=>{s({serviceId:e.id,webview:this.webview.view})},0)},useragent:e.userAgent,disablewebsecurity:e.recipe.disablewebsecurity?true:void 0,allowpopups:true,nodeintegration:true,webpreferences:`spellcheck=${r?1:0}, contextIsolation=1`})}};a(o,"ServiceWebview");v([n.observable],o.prototype,"webview",2);v([n.action],o.prototype,"_setWebview",1);o=v([m.observer],o);var F=o;
