Module 966846

3,867 characters · in no known chunk
Dependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{A:()=>Z}),n(321073),n(667532);var r=n(735438),i=n.n(r),s=n(311907),a=n(506774),o=n(73153),l=n(92077),u=n(15285),c=n(961350),d=n(568004),_=n(674378),f=n(962052),p=n(723702),h=n(194871),m=n(652215),E=n(613057);let g=[E.Hi.AUTHENTICATION_FAILED,E.Hi.NOT_ENTITLED],A="DispatchManagerStore",I=[],T=[],S=!1,y=null,v=null,N=!1,C=new Map,R=!1,O=null;function b(){let e={queue:I,paused:S,userActions:Array.from(C)};a.w.set(A,e)}function D(e,t){return null!=y&&y.applicationId===e&&y.branchId===t||null!=v&&v.applicationId===e&&v.branchId===t}function L(){let e=I[0];if(null!=e){let{comboId:t,action:n}=e,{applicationId:r,branchId:i}=(0,_.r0)(t);if(!D(r,i)){let e=c.default.getToken(),t=c.default.getId();if(null==e)throw Error("missing user token");R=!f.A.setCurrentTask(r,i,n,t,e)}}}function w(e,t){let n=(0,_.gW)(e,t);return I.findIndex(e=>e.comboId===n)}function M(e,t,n,r){let i=(0,_.gW)(e,t),s={comboId:i,action:r},a=T.indexOf(i);-1!==a&&T.splice(a,1);let o=w(e,t);0!==o&&(n?-1===o&&(I.push(s),L()):(o>0&&I.splice(o,1),I.unshift(s),L())),!n&&S&&f.A.resume(),b()}function P(e,t){let n=(0,_.gW)(e,t),r=T.indexOf(n);-1!==r&&T.splice(r,1);let i=w(e,t);-1!==i&&(I.splice(i,1),b()),L()}function x(e){let{applicationId:t,branchId:n}=e;C.set((0,_.gW)(t,n),"Install"),M(t,n,!1,"Patch")}function k(e){F(e),B(e)}function U(e){let{applicationId:t,branchId:n}=e;C.set((0,_.gW)(t,n),"Repair"),M(t,n,!1,"Repair")}function G(e){let{applicationId:t,branchId:n,automatic:r}=e;M(t,n,r,"Patch")}function F(e){let{applicationId:t,branchId:n}=e;P(t,n)}function V(e){let{applicationId:t,branchId:n}=e,r=w(t,n);if(r<1)return!1;I.splice(0,0,I.splice(r,1)[0]),L(),S&&f.A.resume(),b()}function B(e){let{applicationId:t,branchId:n}=e,r=(0,_.gW)(t,n),i=T.indexOf(r);-1!==i&&T.splice(i,1)}function H(e){let{state:t}=e;!N&&(N=!0,L(),S||f.A.resume());let n=S;S=t.paused,y=t.currentTask,v=t.nextTask;let r=!1;I=I.filter(e=>{let{comboId:t}=e,{applicationId:n,branchId:s}=(0,_.r0)(t),a=h.A.getState(n,s),o=d.A.getTargetBuildId(n,s),u=d.A.getTargetManifests(n,s);if(null!=a&&a.type===m.WTw.UP_TO_DATE&&a.buildId===a.targetBuildId&&a.buildId===o&&i().isEqual(a.manifestIds,a.targetManifestIds)&&i().isEqual(a.manifestIds,u)){if(T.push(t),C.has(t)){switch(C.get(t)){case"Install":l.BK(n,a);break;case"Repair":l.jU(n,a)}C.delete(t)}return r=!0,!1}return!0}),L(),(r||n!==S)&&b()}function j(){let e=c.default.getToken(),t=c.default.getId();null!=e&&f.A.setCredentials(t,e)}function Y(e){let{error:t}=e,{code:n}=t;if(null!=n){if(g.includes(n))j();else if(n===E.Hi.APPLICATION_NOT_FOUND){let{context:e}=t;if(null!=e){let{application_id:t,branch_id:n}=e;P(t,n)}}}}function W(){for(let e of u.Ay.getRunningDiscordApplicationIds())l.ZT(e,e);let e=u.Ay.getVisibleGame();return S||null==e||e.pid===O||l.v7(),O=null==e?null:e.pid,!1}function K(){(0,p.isDesktop)()&&j()}function $(){a.w.remove(A),(0,p.isDesktop)()&&f.A.pause()}function z(e){return e.map(e=>"string"==typeof e?{comboId:e,action:"Patch"}:e)}class q extends s.Ay.Store{static displayName="DispatchManagerStore";initialize(){let e=a.w.get(A)??{queue:null,paused:null,userActions:null};null!=e.queue&&(I=z(e.queue)),null!=e.paused&&(S=e.paused),null!=e.userActions&&(C=new Map(Array.from(e.userActions))),this.waitFor(h.A,u.Ay),this.syncWith([u.Ay],W),this.waitFor(d.A,c.default,h.A)}get activeItems(){return I.map(e=>{let{comboId:t}=e;return(0,_.r0)(t)})}get finishedItems(){return T.map(_.r0)}get paused(){return S}getQueuePosition(e,t){return w(e,t)}isCorruptInstallation(){return R}}let Z=new q(o.h,{DISPATCH_APPLICATION_INSTALL:x,DISPATCH_APPLICATION_UPDATE:G,DISPATCH_APPLICATION_UNINSTALL:k,DISPATCH_APPLICATION_CANCEL:F,DISPATCH_APPLICATION_REPAIR:U,DISPATCH_APPLICATION_MOVE_UP:V,DISPATCH_APPLICATION_REMOVE_FINISHED:B,DISPATCH_APPLICATION_STATE_UPDATE:H,DISPATCH_APPLICATION_ERROR:Y,CONNECTION_OPEN:K,LOGOUT:$})}