1import{a as A}from"./chunk-ZFK6V5HU.js";import{W as U,X as N}from"./chunk-WV3S3FZP.js";import"./chunk-XWILFII7.js";import"./chunk-7VVCOIH5.js";import"./chunk-AZ4QQZDS.js";import"./chunk-XVCHM2ZO.js";import"./chunk-YJAOHDKO.js";import{e as M}from"./chunk-ZHALXYZR.js";import{c as y}from"./chunk-ARQPVZWD.js";import{F as g,G as B}from"./chunk-EYOZCDTO.js";import"./chunk-47JB3QK6.js";import"./chunk-6MFMUNE6.js";import"./chunk-EKIIEAN6.js";import"./chunk-3BGN7EFA.js";import"./chunk-L3BY3W2H.js";import"./chunk-BPCAXWRU.js";import"./chunk-SF2IARL4.js";import"./chunk-AYM3J725.js";import"./chunk-3AQJXUIF.js";import"./chunk-3DXU5EGB.js";import{Bb as b}from"./chunk-QC665TQX.js";import"./chunk-7CGVOPYV.js";import"./chunk-KCNJIDRM.js";import{p as u}from"./chunk-ULIQTYXE.js";import"./chunk-BL5SNMIB.js";import"./chunk-XYVDJZHV.js";import"./chunk-JDCFZT6W.js";import"./chunk-Z7VFWCTR.js";import"./chunk-TX6LVNBR.js";import"./chunk-246FEAQG.js";import"./chunk-M4HFPSG7.js";import"./chunk-YI2DTASI.js";import{ga as k,la as h}from"./chunk-6LNVQHTW.js";import{a as d,b as R,k as p}from"./chunk-SI3YDIW4.js";var l={OK:"ok",LOST:"lost",UNCHECKED_NO_MARKER:"unchecked-no-marker",UNCHECKED_SHORT_RUN:"unchecked-run-shorter-than-5-min",UNCHECKED_RENDERER_RELOAD:"unchecked-renderer-reload"},C="web-storage-durability-renderer-session",w=5*6e4,F=1e4,K="did not keep its data across the last restart",P=5e3,x="compleadly-web-storage-probe",Y=1,_="probe",D="probe",se=(()=>{class s{constructor(){this.debug=h(U),this.electronService=h(M),this.localStorageService=h(N)}ngOnDestroy(){clearTimeout(this.durabilityMirrorTimer)}reportOnStartup(){return p(this,null,function*(){let e=yield this.probeIndexedDb(),r=this.probeLocalStorage(),t=this.localStorageService.getLocalStorage(u.WEB_STORAGE_UNAVAILABLE_REPORTED),o=this.checkDurability(t),a=String(this.localStorageService.getLocalStorage(u.USER_ID)??"");this.reportIfUnhealthy(e,r,o,a,t);let n=yield B(F);this.logStartupSnapshot(e,r,o,n,a),this.logDurabilityVerdict(o,a)})}reportIfUnhealthy(e,r,t,o,a){if(!e&&!r&&!t.lost){(t.result!==l.UNCHECKED_RENDERER_RELOAD||a?.localStorageDurabilityLost!==!0)&&this.localStorageService.deleteLocalStorage(u.WEB_STORAGE_UNAVAILABLE_REPORTED);return}let n=[r,t.lost?K:""].filter(Boolean),i=[e?`IndexedDB: ${e}`:"IndexedDB: ok",n.length>0?`localStorage: ${n.join("; ")}`:"localStorage: ok"].join(" | ");if(a?.summary===i)return;this.debug.adminWebStorageUnavailable(i,o)&&this.localStorageService.setLocalStorage(u.WEB_STORAGE_UNAVAILABLE_REPORTED,{summary:i,at:b(),localStorageDurabilityLost:t.lost})}
1checkDurability(e){let r=b(),t=this.localStorageService.getLocalStorage(u.WEB_STORAGE_DURABILITY_MARKER),o=v(),a=this.readMainProcessId(),n=G(),i=t?.writtenAt||t?.startedAt,c=i?Math.max(0,r-i):void 0,m=!!o,T=typeof t?.lastCheckedLost=="boolean"?t.lastCheckedLost:e?.localStorageDurabilityLost===!0;if(!!t&&(!!a&&t.mainProcessId===a||n))return this.resumeDurabilityMirror(t,r),{result:l.UNCHECKED_RENDERER_RELOAD,markerAgeSec:c,localStorageMarkerPresent:m,lost:T};let E;t?t.token?E=t.token===o?l.OK:l.LOST:E=l.UNCHECKED_SHORT_RUN:E=l.UNCHECKED_NO_MARKER;let O=E===l.OK||E===l.LOST?E===l.LOST:T,I=`${r}-${Math.random().toString(36).slice(2,12)}`;if(H(I)){let f=R(d({startedAt:r},a?{mainProcessId:a}:{}),{lastCheckedLost:O});this.localStorageService.setLocalStorage(u.WEB_STORAGE_DURABILITY_MARKER,f),this.scheduleDurabilityMirror(R(d({},f),{token:I}),w)}else this.localStorageService.deleteLocalStorage(u.WEB_STORAGE_DURABILITY_MARKER);return{result:E,markerAgeSec:c,localStorageMarkerPresent:m,lost:O}}resumeDurabilityMirror(e,r){if(e.token)return;let t=v();if(!t)return;let o=(e.startedAt-r)*1e3+w;this.scheduleDurabilityMirror(R(d({},e),{token:t}),o)}scheduleDurabilityMirror(e,r){clearTimeout(this.durabilityMirrorTimer),this.durabilityMirrorTimer=void 0;let t=()=>{this.durabilityMirrorTimer=void 0,this.localStorageService.setLocalStorage(u.WEB_STORAGE_DURABILITY_MARKER,R(d({},e),{writtenAt:b()}))};if(r<=0){t();return}this.durabilityMirrorTimer=setTimeout(t,r)}readMainProcessId(){try{let e=this.electronService.remote?.process,r=e?.pid,t=e?.getCreationTime?.();return r&&t?`${r}@${Math.round(t)}`:""}catch(e){return console.debug("[WebStorage] main-process identity unreadable",S(e)),""}}logStartupSnapshot(e,r,t,o,a){let n=o.restoreOutcome===g.RESTORED,i=n||o.restoreOutcome===g.FAILED_FALLBACK_UNREADABLE||o.restoreOutcome===g.FAILED_LOCAL_STORAGE_UNREADABLE||o.restoreOutcome===g.FAILED_WRITE||o.restoreOutcome===g.FAILED_UNDECRYPTABLE_FALLBACK||o.restoreOutcome===g.FAILED_ENCRYPTION_UNAVAILABLE||o.mirrorFailureCount>0,c=!!e||!!r||t.lost||i;A(this.debug,c?"warn":"info","Web storage startup snapshot",R(d({indexedDb:e||"ok",localStorageProbe:r||"ok",durability:t.result,durabilityLost:t.lost,durabilityMarkerAgeSec:t.markerAgeSec,firebaseSessionFallbackPresent:o.fallbackPresentAtStartup,firebaseSessionRestoredFromFallback:n,firebaseSessionRestoreOutcome:o.restoreOutcome,firebaseSessionLocation:o.firstTokenCallbackLocation,firebaseSessionMirrorFailures:o.mirrorFailureCount},L(a)),{[y.userId]:a||void 0}))}logDurabilityVerdict(e,r){e.result===l.LOST?A(this.debug,"warn",`localStorage ${K}`,d({markerAgeSec:e.markerAgeSec,localStorageMarkerPresent:e.localStorageMarkerPresent},L(r))):e.result===l.UNCHECKED_SHORT_RUN?A(this.debug,"debug","localStorage durability check skipped \u2014 the previous run was shorter than 5 minutes",d({markerAgeSec:e.markerAgeSec},L(r))):e.result===l.UNCHECKED_RENDERER_RELOAD&&A(this.debug,"debug","localStorage durability check skipped \u2014 renderer reload in the same main process",d({markerAgeSec:e.markerAgeSec,durabilityLost:e.lost},L(r)))}probeIndexedDb(){return new Promise(e=>{let r=!1,t=n=>{r||(r=!0,e(n))},o=setTimeout(()=>t(`probe timed out after ${P} ms`),P),a=n=>{clearTimeout(o),t(n)};try{if(!indexedDB){a("indexedDB is not available in this context");return}let n=indexedDB.open(x,Y);n.onupgradeneeded=()=>{let i=n.result;i.objectStoreNames.contains(_)||i.createObjectStore(_)},n.onblocked=()=>a("indexedDB.open was blocked by another connection"),n.onerror=()=>a(S(n.error)),n.onsuccess=()=>{let i=n.result;try{let c=i.transaction(_,"readwrite"),m=c.objectStore(_);m.put("1",D),m.delete(D),c.oncomplete=()=>{i.close(),a("")},c.onabort=()=>{i.close(),a(S(c.error))},c.onerror=()=>{i.close(),a(S(c.error))}}catch(c){i.close(),a(S(c))}}}catch(n){a(S(n))}})}probeLocalStorage(){try{return localStorage?(localStorage.setItem(D,"1"),localStorage.removeItem(D),""):"localStorage is not available in this context"}catch(e){return S(e)}}static{this.\u0275fac=function(r){return new(r||s)}}static{this.\u0275prov=k({token:s,factory:s.\u0275fac,providedIn:"root"})}}return s})();function S(s){return s instanceof DOMException||s instanceof Error?`${s.name}: ${s.message}`:s?String(s):"unknown error"}function v(){try{return window.localStorage.getItem(u.WEB_STORAGE_DURABILITY_MARKER)||""}catch(s){return console.debug("[WebStorage] durability token unreadable",S(s)),""}}function H(s){try{return window.localStorage.setItem(u.WEB_STORAGE_DURABILITY_MARKER,s),!0}catch(W){return console.debug("[WebStorage] durability token not writable",S(W)),!1}}function L(s){return s?{storedUserId:s}:{}}function G(){try{let s=window.sessionStorage.getItem(C)==="1";return window.sessionStorage.setItem(C,"1"),s}catch(s){return console.debug("[WebStorage] renderer session flag unavailable",S(s)),!1}}export{w as DURABILITY_MIRROR_DELAY_MS,l as WebStorageDurability,se as WebStorageHealthService};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.