(function(c,E,y,a,f,P,u,R,I,N,v){"use strict";functionC(e,t){if(!(einstanceoft))thrownewTypeError("Cannot call a class as a function")}function_(e,t){for(varn=0;n<t.length;n++){varr=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"inr&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}functionF(e,t,n){returnt&&_(e.prototype,t),n&&_(e,n),e}functionD(e,t,n){returntine?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}consto={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",LFM_API_KEY:"615322f0047e12aedbc610d9d71f7430",LFM_DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"]},w=y.findByProps("getAssetIds"),U=y.findByStoreName("PresenceStore");asyncfunctionk(){conste=newURLSearchParams({method:"user.getrecenttracks",user:s.username,api_key:o.LFM_API_KEY,format:"json",limit:"1",extended:"1"}).toString(),t=awaitfetch(`https://ws.audioscrobbler.com/2.0/?${e}`);if(!t.ok)thrownewError(`Failed to fetch the latest scrobble: ${t.statusText}`);constn=awaitt.json(),r=n?.recenttracks?.track?.[0];if(!r)thrown;return{name:r.name,artist:r.artist.name,album:r.album["#text"],albumArt:awaitV(r.image[3]["#text"]),url:r.url,date:r.date?.["#text"]??"now",nowPlaying:!!r["@attr"]?.nowplaying,loved:r.loved==="1"}}asyncfunctionV(e){returno.LFM_DEFAULT_COVER_HASHES.some(function(t){returne.includes(t)})?null:e}functiond(){returni.lastActivity&&l("--> Clearing activity..."),S(null)}functionS(e){i.pluginStopped&&(console.log("--> Plugin is unloaded, aborting..."),i.updateInterval&&clearInterval(i.updateInterval),e=null),i.lastActivity=e,a.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e})}asyncfunctionO(e){lett=arguments.length>1&&arguments[1]!==void0?arguments[1]:o.APPLICATION_ID;returne?typeofe=="string"?(awaitw.getAssetIds(t,[e]))[0]:awaitw.getAssetIds(t,e):null}asyncfunctionL(){if(l("--> Fetching last track..."),!s.username)throwI.showToast("Last.fm username is not set!",u.getAssetIDByName("Small")),p(),newError("Username is not set");if(s.ignoreSpotify){for(constnofU.getActivities(b.getCurrentUser().id))if(n?.type===ActivityType.LISTENING&&n.application_id!==o.APPLICATION_ID){l("--> Spotify is currently playing, aborting..."),d();return}}conste=awaitk().catch(asyncfunction(n){throwl("--> An error occurred while fetching the last track, aborting..."),d(),n});if(!e.nowPlaying){l("--> Last track is not currently playing, aborting..."),d();return}if(l("--> Track fetched!"),i.lastTrackUrl===e.url){l("--> Last track is the same as the previous one, aborting...");return}constt={name:s.appName||o.DEFAULT_APP_NAME,flags:0,type:s.listeningTo?2:0,details:e.name,state:`by ${e.artist}`,application_id:o.APPLICATION_ID};if(i.lastTrackUrl=e.url,t.name.includes("{{"))for(constnine)t.name=t.name.replace(`{{${n}}}`,e[n]);s.showTimestamp&&(t.timestamps={start:Date.now()/1e3|0}),e.album&&(t.assets={large_image:awaitO(e.albumArt),large_text:`on ${e.album}`}),l("--> Setting activity..."),l(t);try{S(t)}catch(n){throwl("--> An error occurred while setting the activity"),d(),n}l("--> Successfully set activity!")}functionp(){console.log("--> Flushing..."),i.lastActivity=null,i.lastTrackUrl=null,i.updateInterval&&clearInterval(i.updateInterval),d()}asyncfunctionT(){if(console.log("--> Initializing..."),i.pluginStopped)thrownewError("Plugin is already stopped!");p();lete=0;awaitL().catch(function(t){console.error(t),e++}),i.updateInterval=setInterval(function(){returnL().then(function(){e=0}).catch(function(t){console.error(t),++e>3&&(console.error("Failed to fetch/set activity 3 times, aborting..."),p())})},(s.timeInterval||o.DEFAULT_TIME_INTERVAL)*1e3)}const{FormInput:A,FormDivider:g,FormSwitchRow:h,FormText:M,FormIcon:m}=R.Forms;functionB(){asyncfunctione(){for(consttinf.storage)(f.storage[t]===!1||f.storage[t])&&(s[t]=f.storage[t]);console.log("Applying settings..."),awaitT(),I.showToast("Settings updated!",u.getAssetIDByName("Check"))}returna.React.create