sync-storage-C6WHaVcD.js

1.8 KB · raw

1import{n as e}from"./chunk-CilyBKbf.js";var t=e({addPairedDevice:()=>l,addTrustedNetwork:()=>o,clearIncomingPairingRequest:()=>m,getIncomingPairingRequest:()=>p,getPairedDevices:()=>c,getTrustedNetworks:()=>a,removePairedDevice:()=>u,removeTrustedNetwork:()=>s,setIncomingPairingRequest:()=>f,updatePairedDevice:()=>d}),n=`peach_trusted_networks`,r=`peach_paired_devices`,i=`peach_incoming_pair`;async function a(){try{return(await chrome.storage.local.get(n))[n]??[]}catch{return[]}}async function o(e){try{let t=await a();t.push(e),await chrome.storage.local.set({[n]:t})}catch(e){throw Error(`Failed to add trusted network: ${e}`)}}async function s(e){try{let t=(await a()).filter(t=>t.addedAt!==e);await chrome.storage.local.set({[n]:t})}catch(e){throw Error(`Failed to remove trusted network: ${e}`)}}async function c(){try{return(await chrome.storage.local.get(r))[r]??[]}catch{return[]}}async function l(e){try{let t=await c();if(t.some(t=>t.deviceId===e.deviceId))throw Error(`Device ${e.deviceId} is already paired`);t.push(e),await chrome.storage.local.set({[r]:t})}catch(e){throw Error(`Failed to add paired device: ${e}`)}}async function u(e){try{let t=(await c()).filter(t=>t.deviceId!==e);await chrome.storage.local.set({[r]:t})}catch(e){throw Error(`Failed to remove paired device: ${e}`)}}async function d(e,t){try{let n=await c(),i=n.findIndex(t=>t.deviceId===e);if(i===-1)throw Error(`Device ${e} not found`);n[i]={...n[i],...t,deviceId:e},await chrome.storage.local.set({[r]:n})}catch(e){throw Error(`Failed to update paired device: ${e}`)}}async function f(e){await chrome.storage.session.set({[i]:e})}async function p(){try{let e=(await chrome.storage.session.get(i))[i];return e?Date.now()>=e.expiresAt?(await m(),null):e:null}catch{return null}}async function m(){try{await chrome.storage.session.remove(i)}catch{}}export{t as i,c as n,f as r,l as t};