function hijackWxMethod(){if(!global.__minium__.initedHijack){global.__minium__.initedHijack=!0;const o=wx._MINI_WX_PROXY_,a=new Map,l=new Map,r=new Map,u=new Map,_=new Map;function e(e,t,n,c){let i=n.get(e);return i[t]||(i[t]=c),i[t]}_.set(wx,{}),a.set(wx,{}),l.set(wx,{}),r.set(wx,{}),u.set(wx,{}),o&&(_.set(o,{}),a.set(o,{}),l.set(o,{}),r.set(o,{}),u.set(o,{})),global.__minium__.hijackTest=function(e){return{hijacked:_.get(e),hijack_before:a.get(e),hijack_after:l.get(e),hijack_callback:r.get(e),hijack_mock:u.get(e)}};const f={},s=new Set(["request","downloadFile","uploadFile","connectSocket"]);function t(e){return!(!e.endsWith("Sync")&&!e.startsWith("create"))||s.has(e)}function n(n,c,i){if(!n)return;if(_.get(n)[c])return;let o=e(n,c,a,{}),m=e(n,c,l,{}),h=e(n,c,r,{});!u.has(n)&&u.set(n,{});let g=global.__minium__.getSrcMethod(n,c);if(!g&&(g=global.__minium__.setSrcMethod(n,c),void 0===g))return void(_.get(n)[c]=!0);global.__minium__.defineMethod(n,c,function(e,t){let n;return n=f[t]?f[t]:f[t]=[],function(...t){n.push(e);try{return e(...t)}finally{n.pop()}}}((function(...e){var i=e[0],a=!1,l=t(c),r=!l||function(e){return s.has(e)}(c);let _=u.get(n)[c];l||i&&(i.success||i.fail||i.complete)||(a=!0);if(f[c].length>1)return g(...e);const b=Math.random();var d;if(Object.values(o).forEach((t=>t(...e,b))),l){if(r&&i&&Object.keys(h).length){const e=i.complete;i.complete=t=>{Object.values(h).forEach((e=>e(t,b))),e&&e(t)}}d=(_||g)(...e)}else if(_||Object.keys(h).length)if(a||_)d=(_||g)(...e).then((function(e){return Object.values(h).forEach((t=>t(e,b))),i&&(i.success&&i.success(e),i.complete&&i.complete(e)),e})).catch((function(e){throw console.warn(`[minium] ${c} ${_?"mockFn":"origin"} catch ${e}`),Object.values(h).forEach((t=>t(e,b))),i&&(i.fail&&i.fail(e),i.complete&&i.complete(e)),e}));else{if(i){var p=i.complete;i.complete=function(e){Object.values(h).forEach((t=>t(e,b))),p&&p(e)}}d=g(...e)}else d=g(...e);return Object.values(m).forEach((e=>e(d,b))),d}),c)),_.get(n)[c]=!0}function c(e){return function(...t){try{return e.call(this,...t)}catch(e){return e}}}function i(e){return function(){return c(e).apply(this,Array.from(arguments).slice(0,-1))}}global.__minium__.setCall=function(e,t,{before:u,after:_,callback:f},s=!1){(o?[wx,o]:[wx]).forEach(((o,m)=>{n(o,e),u&&(a.get(o)[e][`${t}`]=s?c(u):i(u)),_&&(l.get(o)[e][`${t}`]=s?c(_):i(_)),f&&(r.get(o)[e][`${t}`]=s?c(f):i(f))}))},global.__minium__.delCall=function(e,t){(o?[wx,o]:[wx]).forEach((n=>{if(!_.get(n)[e])return;const c=a.get(n)[e],i=l.get(n)[e],o=r.get(n)[e];t?(delete c[`${t}`],delete i[`${t}`],delete o[`${t}`]):(Object.entries(c).forEach((([e])=>{delete c[e]})),Object.entries(i).forEach((([e])=>{delete i[e]})),Object.entries(o).forEach((([e])=>{delete o[e]})))}))},global.__minium__.canHook=!0,global.__minium__.setMock=function(e,c,i){(o?[wx,o]:[wx]).forEach((o=>{n(o,e);const a=global.__minium__.getSrcMethod(o,e),l={origin:global.__minium__.bind(a,o)};t(e)?u.get(o)[e]=function(){return c.apply(l,Array.from(arguments).concat(i))}:u.get(o)[e]=function(){return new Promise((e=>{e(c.apply(l,Array.from(arguments).concat(i)))}))}}))},global.__minium__.delMock=function(e){(o?[wx,o]:[wx]).forEach((t=>{u.get(t)[e]=void 0}))},global.__minium__.canMock=!0}}
