import{_ as e,i as n,a as s,s as o,g as a,b as i,o as l,c as d,f as t,e as c,w,h as g,t as k,p as u,k as p}from"./index-4c6e30ca.js";const r={data:()=>({messageString:"",message1:"",message2:"",message3:"",windowName:"window-ipc",newWcId:0,views:[{type:"vue",content:"#/special/subwindow",windowName:"window-ipc",windowTitle:"ipc window"}]}),mounted(){this.init()},methods:{init(){n.removeAllListeners(s.ipcSendMsg),n.on(s.ipcSendMsg,((e,n)=>{console.log("[ipcRenderer] [socketMsgStart] result:",n),this.messageString=n,e.sender.send(s.hello,"electron-egg")})),n.removeAllListeners(o.window2ToWindow1),n.on(o.window2ToWindow1,((e,n)=>{this.$message.info(n)}))},sendMsgStart(){n.send(s.ipcSendMsg,{type:"start",content:"开始"})},sendMsgStop(){n.send(s.ipcSendMsg,{type:"end",content:""})},handleInvoke(){n.invoke(s.ipcInvokeMsg,"异步-回调").then((e=>{console.log("r:",e),this.message1=e}))},async handleInvoke2(){const e=await n.invoke(s.ipcInvokeMsg,"异步");console.log("msg:",e),this.message2=e},handleSendSync(){const e=n.sendSync(s.ipcSendSyncMsg,"同步");this.message3=e},createWindow(e){n.invoke(s.createWindow,a(this.views[e])).then((e=>{console.log("[createWindow] id:",e)}))},async sendTosubWindow(){this.newWcId=await n.invoke(s.getWCid,this.windowName),n.sendTo(this.newWcId,o.window1ToWindow2,"窗口1通过 sendTo 给窗口2发送消息")}}},v=e=>(u("data-v-227d95f1"),e=e(),p(),e),m={id:"app-base-socket-ipc"},h=v((()=>t("div",{class:"one-block-1"},[t("span",null," 1. 发送异步消息 ")],-1))),f={class:"one-block-2"},S=v((()=>t("p",null,null,-1))),_=v((()=>t("div",{class:"one-block-1"},[t("span",null," 2. 同步消息（不推荐，阻塞执行） ")],-1))),b={class:"one-block-2"},C=v((()=>t("div",{class:"one-block-1"},[t("span",null," 3. 长消息： 服务端持续向前端页面发消息 ")],-1))),W={class:"one-block-2"},M=v((()=>t("div",{class:"one-block-1"},[t("span",null," 4. 多窗口通信：子窗口与主进程通信，子窗口互相通信 ")],-1))),y={class:"one-block-2"};const I=e(r,[["render",function(e,n,s,o,a,u){const p=i("a-button"),r=i("a-space");return l(),d("div",m,[h,t("div",f,[c(r,null,{default:w((()=>[c(p,{onClick:u.handleInvoke},{default:w((()=>[g("发送 - 回调")])),_:1},8,["onClick"]),g(" 结果："+k(a.message1),1)])),_:1}),S,c(r,null,{default:w((()=>[c(p,{onClick:u.handleInvoke2},{default:w((()=>[g("发送 - async/await")])),_:1},8,["onClick"]),g(" 结果："+k(a.message2),1)])),_:1})]),_,t("div",b,[c(r,null,{default:w((()=>[c(p,{onClick:u.handleSendSync},{default:w((()=>[g("同步消息")])),_:1},8,["onClick"]),g(" 结果："+k(a.message3),1)])),_:1})]),C,t("div",W,[c(r,null,{default:w((()=>[c(p,{onClick:u.sendMsgStart},{default:w((()=>[g("开始")])),_:1},8,["onClick"]),c(p,{onClick:u.sendMsgStop},{default:w((()=>[g("结束")])),_:1},8,["onClick"]),g(" 结果："+k(a.messageString),1)])),_:1})]),M,t("div",y,[c(r,null,{default:w((()=>[c(p,{onClick:n[0]||(n[0]=e=>u.createWindow(0))},{default:w((()=>[g("打开新窗口2")])),_:1}),c(p,{onClick:n[1]||(n[1]=e=>u.sendTosubWindow())},{default:w((()=>[g("向新窗口2发消息")])),_:1})])),_:1})])])}],["__scopeId","data-v-227d95f1"]]);export{I as default};
