SyncPairing-BbSyvmmq.js

5.7 KB · raw

1import{t as e}from"./dist-Cgg5UYwv.js";import{A as t,D as n,F as r,G as i,K as a,M as o,N as s,O as c,U as l,V as u,W as d,j as f,z as p}from"./index-BP9j8KNs.js";var m=r(`<span class=peach-pairing-spinner>`),h=r(`<p class="peach-pairing-error peach-pairing-error--muted">`),g=r(`<button class=peach-pairing-toggle>I have a code to enter →`),_=r(`<div class="peach-pairing-content peach-pairing-code-screen"><p class=peach-pairing-headline>Add a device</p><p class="peach-pairing-subline peach-pairing-subline--center">Open Peach on your other device, tap<br>Add a device, and enter this code.</p><p class=peach-pairing-hint>Both devices must be on the same WiFi.`),v=r(`<button class=peach-pairing-toggle>← Show my code instead`),y=r(`<div class="peach-pairing-content peach-pairing-code-screen"><p class=peach-pairing-headline>Add a device</p><input class=peach-pairing-code-input type=text inputmode=numeric autocomplete=off autocorrect=off placeholder="000 000"aria-label="enter pairing code"><button class="peach-btn peach-btn--accent peach-btn--md peach-lock-submit"></button><p class=peach-pairing-hint>Both devices must be on the same WiFi.`),b=r(`<div class="peach-overlay-view ov-enter-right"><div class=peach-overlay-header><button class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"aria-label=Close><svg width=7 height=12 viewBox="0 0 7 12"fill=none stroke=currentColor stroke-width=1.1 stroke-linecap=round stroke-linejoin=round><path d="M6 1L1 6L6 11"></path></svg></button><span class=peach-overlay-title>add a device</span><div class=peach-overlay-spacer></div></div><div class=peach-pairing-body>`),x=r(`<div class=peach-pairing-content><div class=peach-pairing-success-icon><svg width=32 height=32 viewBox="0 0 32 32"fill=none><circle cx=16 cy=16 r=14 stroke=var(--peach-health-ok) stroke-width=1.5></circle><path d="M10 16L14 20L22 12"stroke=var(--peach-health-ok) stroke-width=1.5 stroke-linecap=round stroke-linejoin=round></path></svg></div><p class=peach-pairing-headline>Paired!</p><p class="peach-pairing-subline peach-pairing-subline--center"></p><button class="peach-btn peach-btn--accent peach-btn--md peach-lock-submit">Done`),S=r(`<div class="peach-pairing-code peach-pairing-code--loading">`),C=r(`<button class="peach-pairing-code peach-pairing-code--expired">refresh`),w=r(`<div class=peach-pairing-code aria-label="pairing code">`),T=!0;function E(){return m()}function D(e){return e.length<=3?e:`${e.slice(0,3)} ${e.slice(3)}`}function O(t){let[r,m]=d(`show`),[O,k]=d(null),[A,j]=d(null),[M,N]=d(null),[P,F]=d(``),[I,L]=d(!1),[R,z]=d(null),[B,V]=d(null),H=null;function U(){H!==null&&(clearTimeout(H),H=null)}function W(e){let n=e;if(n?.type===`PAIRING_COMPLETED`&&n.payload?.deviceName){let e={deviceId:n.payload.deviceName,displayName:n.payload.deviceName,x25519PublicKey:``,pairedAt:Date.now()};U(),k(null),j(null),V(e),t.onPaired(e)}}async function G(){N(null),k(null),j(null),U();let e=await n({type:`START_PAIRING_SERVER`});if(!e.ok||!e.data){N(e.error===`pro_required`?`Sync requires Peach Pro.`:`Couldn't start the pairing server.`);return}k(e.data.token),j(e.data.expiresAt);let t=Math.max(0,e.data.expiresAt-Date.now());H=setTimeout(()=>{k(null),j(null),N(`Code expired — tap to refresh.`)},t)}async function K(){U(),k(null),j(null),await n({type:`STOP_PAIRING_SERVER`})}async function q(){await K(),await G()}async function J(e){r()!==e&&(e===`enter`?(await K(),z(null),F(``),m(`enter`)):(z(null),m(`show`),await G()))}function Y(e){F(D(e.currentTarget.value.replace(/[^0-9]/g,``).slice(0,6))),R()&&z(null)}function X(){return P().replace(/\D/g,``)}async function Z(){let e=X();if(e.length!==6)return;L(!0),z(null);let r=await n({type:`CONNECT_WITH_CODE`,payload:{token:e}});L(!1);let i=r;if(!i.ok){z(i.error===`no peer responded to pairing code`||(i.error??``).includes(`resolve failed`)?`Couldn't find that device. Make sure both are on the same WiFi.`:i.error===`pair_rejected`?`The other device declined.`:i.error===`invalid_code`?`Enter all six digits.`:`Couldn't connect. Try again.`);return}let a=i.data?.deviceName??`Peach`,o={deviceId:a,displayName:a,x25519PublicKey:``,pairedAt:Date.now()};V(o),t.onPaired(o)}return a(()=>{e.isNativePlatform()||chrome.runtime.onMessage.addListener(W),G()}),i(()=>{e.isNativePlatform()||chrome.runtime.onMessage.removeListener(W),U()}),(()=>{var e=b(),i=e.firstChild,a=i.firstChild,d=i.nextSibling;return a.$$click=()=>{n({type:`STOP_PAIRING_SERVER`}),t.onClose()},f(d,u(p,{get when(){return B()},children:e=>(()=>{var n=x(),r=n.firstChild.nextSibling.nextSibling,i=r.nextSibling;return f(r,()=>e().displayName),c(i,`click`,t.onClose,!0),n})()}),null),f(d,u(p,{get when(){return o(()=>!B())()&&r()===`show`},get children(){var e=_(),t=e.firstChild.nextSibling;return t.nextSibling,f(e,u(p,{get when(){return O()},get fallback(){return u(p,{get when(){return!M()},get fallback(){return(()=>{var e=C();return e.$$click=()=>void q(),e})()},get children(){var e=S();return f(e,u(E,{})),e}})},children:e=>(()=>{var t=w();return f(t,()=>D(e())),t})()}),t),f(e,u(p,{get when(){return M()},get children(){var e=h();return f(e,M),e}}),null),f(e,u(p,{when:T,get children(){var e=g();return e.$$click=()=>void J(`enter`),e}}),null),e}}),null),f(d,u(p,{get when(){return o(()=>!B())()&&r()===`enter`},get children(){var e=y(),t=e.firstChild.nextSibling,n=t.nextSibling;return n.nextSibling,t.$$input=Y,s(t,`spellcheck`,!1),n.$$click=()=>void Z(),f(n,()=>I()?`Connecting…`:`Connect →`),f(e,u(p,{get when(){return R()},get children(){var e=h();return f(e,R),e}}),null),f(e,u(p,{when:T,get children(){var e=v();return e.$$click=()=>void J(`show`),l(()=>e.disabled=I()),e}}),null),l(e=>{var r=I(),i=X().length!==6||I();return r!==e.e&&(t.disabled=e.e=r),i!==e.t&&(n.disabled=e.t=i),e},{e:void 0,t:void 0}),l(()=>t.value=P()),e}}),null),e})()}t([`click`,`input`]);export{O as SyncPairingView};