Module 869014

2,668 characters · in no known chunk
Dependencies
Required by (2)
Lazily required by (0)none
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";n.d(t,{A:()=>L});var r=n(439372),i=n(626584),s=n(87001),a=n(531685),o=n(365971),l=n(777334),u=n(41984),c=n(833551),d=n(395011),_=n(392164);let f=new i.A("OverlayWindowRAFManager"),p=window.requestAnimationFrame.bind(window),h=new Set([u.Ue.OutOfProcess,u.Ue.OutOfProcessLimitedInteraction]),m=new Set([u.AR.OVERLAY_CRASHED,u.AR.OVERLAY_CRASHED_DISABLED]);function E(e){for(let t of Object.values(c.default.getTrackedGames()))if(!(!h.has(t.overlayMethod)||m.has(t.state))&&(!e||t.state===u.AR.OVERLAY_RENDERING))return!0;return!1}let g=null,A=!1,I=!1,T={},S=(e,t)=>{T[e]=t},y=e=>{delete T[e]},v=()=>{T={}},N=()=>Object.entries(T).map(e=>{let[t,n]=e;return{timeoutId:Number(t),callback:n}}),C=e=>{try{let t=s.A.getWindow(_.f);if(null==t||"function"!=typeof t.requestAnimationFrame)return g="OverlayNotAvailable",p(e);if(!I)return g="MainWindowFocused",p(e);if(!E(!0))return g="NoOverlayRendering",p(e);let n=null!==d.A.getFocusedRunningGame(),r=a.A.isFocused((0,o.Q2)(t));if(a.A.isFocused()&&f.error("Main window is reported as focused when it should not be!"),n||r){g=n?"OverlayGameFocused":"OverlayWindowFocused";let r=t.requestAnimationFrame(t=>{y(r),e(t)});return S(r,e),r}}catch(e){f.error("RAF redirect failed, falling back to original. Cause:",e),(0,l.pj)(e,c.default.getOverlayMethod(d.A.getTargetPID()))}return g="None",p(e)};function R(){return!a.A.isFocused()||!a.A.isVisible()}function O(){let e=s.A.getWindow(_.f),t=!1;try{t=null!=e&&"function"==typeof e.cancelAnimationFrame}catch(e){f.warn("Unable to access overlay window cancelAnimationFrame, falling back to main window RAF callbacks",e)}N().forEach(n=>{let{timeoutId:r,callback:i}=n;if(t&&null!=e)try{e.cancelAnimationFrame(r)}catch(e){t=!1,f.warn("Unable to cancel overlay RAF callback, continuing with main window RAF callbacks",e)}p(i)}),v()}function b(e){if(e===I)return;let t=!e&&I;I=e,t&&O()}class D extends r.A{_initialize(){b(R())}_terminate(){window.requestAnimationFrame=p}getLastRAFCallbackReason(){return g}handleUpdateOverlayMethod(){if(!__OVERLAY__){if(!A&&!E(!1)){window.requestAnimationFrame=p,g="NoOverlayRendering",O();return}f.info("Patching window RAF to use overlay window"),window.requestAnimationFrame=C}}handleWindowStateChage(){b(R())}handleOverlayRenderDebugMode(e){let{enabled:t,mode:n}=e;n===u.x7.OverlayRafManagerForceEnabled&&(A=t,t?window.requestAnimationFrame=C:I||(window.requestAnimationFrame=p,O()))}actions={OVERLAY_UPDATE_OVERLAY_METHOD:this.handleUpdateOverlayMethod,WINDOW_VISIBILITY_CHANGE:this.handleWindowStateChage,WINDOW_FOCUS:this.handleWindowStateChage,OVERLAY_RENDER_DEBUG_MODE:this.handleOverlayRenderDebugMode}}let L=new D}