import{Xn as e,qt as t}from"./vendor-C4JLrdLj.js";import{E as n,F as r,K as i,Si as a,T as o,b as s,h as c,m as l,wi as u,x as d}from"./ws-JRT2XE7Y.js";import{r as f,t as p}from"./PlaybackEventBus-5pocITQX.js";import{r as m,t as h}from"./RPC-C7MWZyXE.js";f(),l(),i(),t(),d(),u(),m();async function g(){console.log(`Hello Genten!`);let t=await a.sendIZRequest(`/_/config/info`);console.log(t),document.body.setAttribute(`data-os`,t.os),o(()=>{a.sendJSONPost(`/_/discord-rpc/start`,{clientId:s(`connectivity.discord.client`)}),e(()=>n().visual.appearance,e=>{switch(e){case`dark`:window.electronAPI?.sendWindowEvent(`set-native-theme`,{theme:`dark`});break;case`light`:window.electronAPI?.sendWindowEvent(`set-native-theme`,{theme:`light`});break;default:case`auto`:window.electronAPI?.sendWindowEvent(`set-native-theme`,{theme:`system`});break}},{immediate:!0})},!0)}async function _(){if(c(),`mediaSession`in navigator){let e=window.navigator.mediaSession;e.setActionHandler(`play`,()=>{h.play()}),e.setActionHandler(`pause`,()=>{h.pause()}),e.setActionHandler(`previoustrack`,()=>{h.previous()}),e.setActionHandler(`nexttrack`,()=>{h.next()})}let e=null,t=null,n=()=>{t=null;let n=e;if(e=null,n)try{let e=n.item;if(!e)return;let t=n.attributes??{},i=r(t?.artwork?.url,640,640,void 0,`jpg`)??``,a={id:e.id,type:e.type,attributes:{name:t?.name??``,artistName:t?.artistName??``,albumName:t?.albumName??``,durationInMillis:t?.durationInMillis,genreNames:Array.isArray(t?.genreNames)?[...t.genreNames]:[],artwork:{url:i}}};window.electronAPI?.sendMusicKitEvent(`nowPlayingItemDidChange`,a);let o=window.navigator.mediaSession;if(!o)return;o.metadata=new MediaMetadata({title:a.attributes.name,artist:a.attributes.artistName,album:a.attributes.albumName,artwork:i?[{src:i,sizes:`640x640`,type:`image/jpeg`}]:[]})}catch(e){console.error(`Error updating media session metadata`,e)}};p.on(`playbackStatus.nowPlayingItemDidChange`,r=>{e=r,t===null&&(t=setTimeout(n,120))}),p.on(`playbackStatus.playbackStateDidChange`,e=>{try{let t=e.state,n=window.navigator.mediaSession;if(n&&(t===`playing`||t===`seeking`?n.playbackState=`playing`:t===`paused`?n.playbackState=`paused`:t===`stopped`&&(n.playbackState=`none`)),t!==`playing`&&t!==`paused`&&t!==`stopped`&&t!==`seeking`)return;if(window.electronAPI?.sendMusicKitEvent(`playbackStateDidChange`,{state:t}),n&&e.item&&e.attributes){let t=e.attributes,i=r(t?.artwork?.url,640,640,void 0,`jpg`)??``;n.metadata=new MediaMetadata({title:t?.name??``,artist:t?.artistName??``,album:t?.albumName??``,artwork:i?[{src:i,sizes:`640x640`,type:`image/jpeg`}]:[]})}}catch{}}),p.on(`playbackStatus.playbackTimeDidChange`,e=>{try{window.electronAPI?.sendMusicKitEvent(`playbackTimeDidChange`,{currentPlaybackDuration:e.currentPlaybackDuration,currentPlaybackTime:e.currentPlaybackTime,currentPlaybackTimeRemaining:e.currentPlaybackTimeRemaining,isPlaying:e.isPlaying,anchor:e.anchor});let t=window.navigator.mediaSession;if(!t)return;t.setPositionState?.({duration:e.currentPlaybackDuration,position:e.currentPlaybackTime,playbackRate:1})}catch{}}),p.on(`playerStatus.shuffleModeDidChange`,e=>{try{window.electronAPI?.sendMusicKitEvent(`shuffleModeDidChange`,e.shuffleMode??0)}catch{}}),p.on(`playerStatus.repeatModeDidChange`,e=>{try{window.electronAPI?.sendMusicKitEvent(`repeatModeDidChange`,e.repeatMode??0)}catch{}}),p.on(`playerStatus.volumeDidChange`,e=>{try{window.electronAPI?.sendMusicKitEvent(`playbackVolumeDidChange`,{volume:e.volume})}catch{}})}export{_ as n,g as t};