All-Resources/[phone]/codem-phone/ui/dist/js/ExternalApp.DVeIUZa5.js
2026-04-14 17:41:39 +02:00

2 lines
3.4 KiB
JavaScript

var m=(g,d,l)=>new Promise((f,c)=>{var t=r=>{try{s(l.next(r))}catch(p){c(p)}},n=r=>{try{s(l.throw(r))}catch(p){c(p)}},s=r=>r.done?f(r.value):Promise.resolve(r.value).then(t,n);s((l=l.apply(g,d)).next())});import{r as h,b as L,M as O,w as U,o as x,e as C,f as _,g as w,i as E,u as S,h as y}from"./vendor-vue.CmaRnji1.js";import{_ as I,dC as T,u as R,f as i}from"./index.CjrDwa0W.js";import"./vendor.DSdF8huI.js";import"./swiper.tg5sgs8j.js";const W={class:"external-app-container"},B={key:0,class:"error-overlay"},D=["src"],N={__name:"ExternalApp",setup(g){const d=O(),l=S(),f=T(),c=R(),t=h(null),n=h(null),s=h(null),r=L(()=>{const a=d.path;return a&&a.startsWith("/external/")?a.replace("/external/",""):null}),p=a=>{s.value&&URL.revokeObjectURL(s.value);const e=new Blob([a],{type:"text/html"});s.value=URL.createObjectURL(e)},A=()=>{if(!r.value)return;let a=f.getAppById(r.value);a||(a=f.getStoreAppById(r.value)),a&&a.ui&&(n.value=a,p(a.ui))},M=()=>m(this,null,function*(){var e,o,u,P;if(!t.value||!n.value)return;i("CUSTOM_APP_OPENED",{identifier:n.value.identifier});let a={};try{a=yield i("CUSTOM_APP_GET_PLAYER",{})}catch(v){}try{t.value.contentWindow.postMessage({type:"mphone:init",identifier:n.value.identifier,player:a,theme:(o=(e=c.PhoneData)==null?void 0:e.settings)!=null&&o.darkmode?"dark":"light",language:((P=(u=c.PhoneData)==null?void 0:u.settings)==null?void 0:P.language)||"en"},"*")}catch(v){console.error("[ExternalApp] Error sending init:",v)}}),b=a=>m(this,null,function*(){const e=a.data;if(!(!e||!e.type||!n.value)&&!(t.value&&a.source!==t.value.contentWindow))switch(e.type){case"mphone:close":i("CUSTOM_APP_CLOSED",{identifier:n.value.identifier}),l.push("/");break;case"mphone:notification":i("CUSTOM_APP_NOTIFICATION",{identifier:n.value.identifier,header:e.header,message:e.message});break;case"mphone:callback":try{const o=yield i("CUSTOM_APP_CALLBACK",{identifier:n.value.identifier,action:e.action,payload:e.payload||{},server:e.server||!1});t.value&&e.callbackId&&t.value.contentWindow.postMessage({type:"mphone:callback:response",callbackId:e.callbackId,result:o},"*")}catch(o){t.value&&e.callbackId&&t.value.contentWindow.postMessage({type:"mphone:callback:response",callbackId:e.callbackId,result:{success:!1,error:o.message}},"*")}break;case"mphone:navigate":e.path&&l.push(e.path);break;case"mphone:setWaypoint":e.x!==void 0&&e.y!==void 0&&i("CUSTOM_APP_SET_WAYPOINT",{x:e.x,y:e.y});break;case"mphone:getPlayer":try{const o=yield i("CUSTOM_APP_GET_PLAYER",{});t.value&&t.value.contentWindow.postMessage({type:"mphone:playerData",player:o},"*")}catch(o){}break}}),k=a=>{var u;const{identifier:e,message:o}=a.detail||{};e===((u=n.value)==null?void 0:u.identifier)&&t.value&&t.value.contentWindow.postMessage(o,"*")};return U(()=>d.path,()=>{A()}),x(()=>{A(),window.addEventListener("message",b),window.addEventListener("customAppMessage",k)}),C(()=>{n.value&&i("CUSTOM_APP_CLOSED",{identifier:n.value.identifier}),window.removeEventListener("message",b),window.removeEventListener("customAppMessage",k),s.value&&URL.revokeObjectURL(s.value)}),(a,e)=>(y(),_("div",W,[n.value?w("",!0):(y(),_("div",B,e[0]||(e[0]=[E("div",{class:"error-icon"},"!",-1),E("span",{class:"error-text"},"App not found",-1)]))),n.value&&s.value?(y(),_("iframe",{key:1,ref_key:"appFrame",ref:t,src:s.value,class:"app-iframe",onLoad:M},null,40,D)):w("",!0)]))}},K=I(N,[["__scopeId","data-v-3b3dfe6d"]]);export{K as default};