"use strict";var w=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.getPrototypeOf;var p=Object.prototype.hasOwnProperty;var h=(t,e)=>a(t,"name",{value:e,configurable:true});var A=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:true})};var f=(t,e,i,s)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let r of m(e))if(!p.call(t,r)&&r!==i)a(t,r,{get:()=>e[r],enumerable:!(s=g(e,r))||s.enumerable})}return t};var W=(t,e,i)=>(i=t!=null?w(b(t)):{},f(e||!t||!t.__esModule?a(i,"default",{value:t,enumerable:true}):i,t));var E=t=>f(a({},"__esModule",{value:true}),t);var l=(t,e,i,s)=>{var r=s>1?void 0:s?g(e,i):e;for(var d=t.length-1,v;d>=0;d--)if(v=t[d])r=(s?v(e,i,r):v(r))||r;if(s&&r)a(e,i,r);return r};var _={};A(_,{default:()=>o});module.exports=E(_);var n=require("mobx");var c=W(require("../helpers/userAgent-helpers"));const u=require("../preload-safe-debug")("Ferdium:UserAgent");class o{_didNavigateListener=e=>{};webview=null;userAgentPref=null;overrideUserAgent=()=>"";constructor(e=null){(0,n.makeObservable)(this);if(typeof e==="function"){this.overrideUserAgent=e}(0,n.observe)(this,"webview",i=>{const{oldValue:s,newValue:r}=i;if(s!==null){this._removeWebviewEvents(s)}if(r!==null){this._addWebviewEvents(r)}})}get defaultUserAgent(){const e=this.overrideUserAgent();if(e.length>0){return e}const i=window["ferdium"].stores.settings.all.app.userAgentPref;if(typeof i==="string"){const s=i.trim();if(s!==""){return s}}return(0,c.default)()}get serviceUserAgentPref(){if(typeof this.userAgentPref==="string"){const e=this.userAgentPref.trim();if(e!==""){return e}}return null}get userAgentWithoutChromeVersion(){const e=this.defaultUserAgent;return e.replace(/Chrome\/[\d.]+/,"Chrome")}get userAgent(){return this.serviceUserAgentPref||this.defaultUserAgent}setWebviewReference(e){if(this.webview===e){return}this.webview=e}_handleNavigate(e){if(e.startsWith("https://accounts.google.com")){u("Setting user agent to chromeless for url",e);if(this.webview){this.webview.userAgent=this.serviceUserAgentPref||this.userAgentWithoutChromeVersion}}else{u("Setting user agent to default for url",e);if(this.webview){this.webview.userAgent=this.serviceUserAgentPref||this.defaultUserAgent}}}_addWebviewEvents(e){u("Adding event handlers");this._didNavigateListener=i=>this._handleNavigate(i.url);e.addEventListener("did-navigate",this._didNavigateListener)}_removeWebviewEvents(e){u("Removing event handlers");e.removeEventListener("did-navigate",this._didNavigateListener)}}h(o,"UserAgent");l([n.observable.ref],o.prototype,"webview",2);l([n.observable],o.prototype,"userAgentPref",2);l([n.observable],o.prototype,"overrideUserAgent",2);l([n.computed],o.prototype,"defaultUserAgent",1);l([n.computed],o.prototype,"serviceUserAgentPref",1);l([n.computed],o.prototype,"userAgentWithoutChromeVersion",1);l([n.computed],o.prototype,"userAgent",1);l([n.action],o.prototype,"setWebviewReference",1);l([n.action],o.prototype,"_handleNavigate",1);
