/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var fe=Object.create;var S=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var Ae=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var m=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),ye=(i,e)=>{for(var t in e)S(i,t,{get:e[t],enumerable:!0})},J=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of we(e))!Oe.call(i,n)&&n!==t&&S(i,n,{get:()=>e[n],enumerable:!(s=Se(e,n))||s.enumerable});return i};var De=(i,e,t)=>(t=i!=null?fe(Ae(i)):{},J(e||!i||!i.__esModule?S(t,"default",{value:i,enumerable:!0}):t,i)),Re=i=>J(S({},"__esModule",{value:!0}),i);var j=m(()=>{});var w=m((at,W)=>{"use strict";var C;try{let{app:i}=require("electron");C=i.setAsDefaultProtocolClient.bind(i)}catch(i){try{C=j()}catch(e){}}typeof C!="function"&&(C=()=>!1);function Le(){return typeof process!="undefined"?process.pid:null}var be=()=>{let i="";for(let e=0;e<32;e+=1){(e===8||e===12||e===16||e===20)&&(i+="-");let t;if(e===12)t=4;else{let s=Math.random()*16|0;e===16?t=s&3|0:t=s}i+=t.toString(16)}return i};W.exports={pid:Le,register:C,uuid:be}});var v=m((I,z)=>{"use strict";var ve=function(){if(typeof self!="undefined")return self;if(typeof window!="undefined")return window;if(typeof global!="undefined")return global;throw new Error("unable to locate global object")},p=ve();z.exports=I=p.fetch;p.fetch&&(I.default=p.fetch.bind(p));I.Headers=p.Headers;I.Request=p.Request;I.Response=p.Response});var Z=m((ot,A)=>{"use strict";var Pe=require("net"),Ve=require("events"),Be=v(),{uuid:Ue}=w(),E={HANDSHAKE:0,FRAME:1,CLOSE:2,PING:3,PONG:4};function Ge(i){if(process.platform==="win32")return`\\\\?\\pipe\\discord-ipc-${i}`;let{env:{XDG_RUNTIME_DIR:e,TMPDIR:t,TMP:s,TEMP:n}}=process;return`${(e||t||s||n||"/tmp").replace(/\/$/,"")}/discord-ipc-${i}`}function Q(i=0){return new Promise((e,t)=>{let s=Ge(i),n=()=>{i<10?e(Q(i+1)):t(new Error("Could not connect"))},a=Pe.createConnection(s,()=>{a.removeListener("error",n),e(a)});a.once("error",n)})}async function P(i=0){if(i>30)throw new Error("Could not find endpoint");let e=`http://127.0.0.1:${6463+i%10}`;try{return(await Be(e)).status===404?e:P(i+1)}catch(t){return P(i+1)}}function V(i,e){e=JSON.stringify(e);let t=Buffer.byteLength(e),s=Buffer.alloc(8+t);return s.writeInt32LE(i,0),s.writeInt32LE(t,4),s.write(e,8,t),s}var g={full:"",op:void 0};function U(i,e){let t=i.read();if(!t)return;let{op:s}=g,n;if(g.full===""){s=g.op=t.readInt32LE(0);let a=t.readInt32LE(4);n=t.slice(8,a+8)}else n=t.toString();try{let a=JSON.parse(g.full+n);e({op:s,data:a}),g.full="",g.op=void 0}catch(a){g.full+=n}U(i,e)}var B=class extends Ve{constructor(e){super(),this.client=e,this.socket=null}async connect(){let e=this.socket=await Q();e.on("close",this.onClose.bind(this)),e.on("error",this.onClose.bind(this)),this.emit("open"),e.write(V(E.HANDSHAKE,{v:1,client_id:this.client.clientId})),e.pause(),e.on("readable",()=>{U(e,({op:t,data:s})=>{switch(t){case E.PING:this.send(s,E.PONG);break;case E.FRAME:if(!s)return;s.cmd==="AUTHORIZE"&&s.evt!=="ERROR"&&P().then(n=>{this.client.request.endpoint=n}).catch(n=>{this.client.emit("error",n)}),this.emit("message",s);break;case E.CLOSE:this.emit("close",s);break;default:break}})})}onClose(e){this.emit("close",e)}send(e,t=E.FRAME){this.socket.write(V(t,e))}async close(){return new Promise(e=>{this.once("close",e),this.send({},E.CLOSE),this.socket.end()})}ping(){this.send(Ue(),E.PING)}};A.exports=B;A.exports.encode=V;A.exports.decode=U});var G=m(T=>{"use strict";function X(i){let e={};for(let t of i)e[t]=t;return e}T.browser=typeof window!="undefined";T.RPCCommands=X(["DISPATCH","AUTHORIZE","AUTHENTICATE","GET_GUILD","GET_GUILDS","GET_CHANNEL","GET_CHANNELS","CREATE_CHANNEL_INVITE","GET_RELATIONSHIPS","GET_USER","SUBSCRIBE","UNSUBSCRIBE","SET_USER_VOICE_SETTINGS","SET_USER_VOICE_SETTINGS_2","SELECT_VOICE_CHANNEL","GET_SELECTED_VOICE_CHANNEL","SELECT_TEXT_CHANNEL","GET_VOICE_SETTINGS","SET_VOICE_SETTINGS_2","SET_VOICE_SETTINGS","CAPTURE_SHORTCUT","SET_ACTIVITY","SEND_ACTIVITY_JOIN_INVITE","CLOSE_ACTIVITY_JOIN_REQUEST","ACTIVITY_INVITE_USER","ACCEPT_ACTIVITY_INVITE","INVITE_BROWSER","DEEP_LINK","CONNECTIONS_CALLBACK","BRAINTREE_POPUP_BRIDGE_CALLBACK","GIFT_CODE_BROWSER","GUILD_TEMPLATE_BROWSER","OVERLAY","BROWSER_HANDOFF","SET_CERTIFIED_DEVICES","GET_IMAGE","CREATE_LOBBY","UPDATE_LOBBY","DELETE_LOBBY","UPDATE_LOBBY_MEMBER","CONNECT_TO_LOBBY","DISCONNECT_FROM_LOBBY","SEND_TO_LOBBY","SEARCH_LOBBIES","CONNECT_TO_LOBBY_VOICE","DISCONNECT_FROM_LOBBY_VOICE","SET_OVERLAY_LOCKED","OPEN_OVERLAY_ACTIVITY_INVITE","OPEN_OVERLAY_GUILD_INVITE","OPEN_OVERLAY_VOICE_SETTINGS","VALIDATE_APPLICATION","GET_ENTITLEMENT_TICKET","GET_APPLICATION_TICKET","START_PURCHASE","GET_SKUS","GET_ENTITLEMENTS","GET_NETWORKING_CONFIG","NETWORKING_SYSTEM_METRICS","NETWORKING_PEER_METRICS","NETWORKING_CREATE_TOKEN","SET_USER_ACHIEVEMENT","GET_USER_ACHIEVEMENTS"]);T.RPCEvents=X(["CURRENT_USER_UPDATE","GUILD_STATUS","GUILD_CREATE","CHANNEL_CREATE","RELATIONSHIP_UPDATE","VOICE_CHANNEL_SELECT","VOICE_STATE_CREATE","VOICE_STATE_DELETE","VOICE_STATE_UPDATE","VOICE_SETTINGS_UPDATE","VOICE_SETTINGS_UPDATE_2","VOICE_CONNECTION_STATUS","SPEAKING_START","SPEAKING_STOP","GAME_JOIN","GAME_SPECTATE","ACTIVITY_JOIN","ACTIVITY_JOIN_REQUEST","ACTIVITY_SPECTATE","ACTIVITY_INVITE","NOTIFICATION_CREATE","MESSAGE_CREATE","MESSAGE_UPDATE","MESSAGE_DELETE","LOBBY_DELETE","LOBBY_UPDATE","LOBBY_MEMBER_CONNECT","LOBBY_MEMBER_DISCONNECT","LOBBY_MEMBER_UPDATE","LOBBY_MESSAGE","CAPTURE_SHORTCUT_CHANGE","OVERLAY","OVERLAY_UPDATE","ENTITLEMENT_CREATE","ENTITLEMENT_DELETE","USER_ACHIEVEMENT_UPDATE","READY","ERROR"]);T.RPCErrors={CAPTURE_SHORTCUT_ALREADY_LISTENING:5004,GET_GUILD_TIMED_OUT:5002,INVALID_ACTIVITY_JOIN_REQUEST:4012,INVALID_ACTIVITY_SECRET:5005,INVALID_CHANNEL:4005,INVALID_CLIENTID:4007,INVALID_COMMAND:4002,INVALID_ENTITLEMENT:4015,INVALID_EVENT:4004,INVALID_GIFT_CODE:4016,INVALID_GUILD:4003,INVALID_INVITE:4011,INVALID_LOBBY:4013,INVALID_LOBBY_SECRET:4014,INVALID_ORIGIN:4008,INVALID_PAYLOAD:4e3,INVALID_PERMISSIONS:4006,INVALID_TOKEN:4009,INVALID_USER:4010,LOBBY_FULL:5007,NO_ELIGIBLE_ACTIVITY:5006,OAUTH2_ERROR:5e3,PURCHASE_CANCELED:5008,PURCHASE_ERROR:5009,RATE_LIMITED:5011,SELECT_CHANNEL_TIMED_OUT:5001,SELECT_VOICE_FORCE_REQUIRED:5003,SERVICE_UNAVAILABLE:1001,TRANSACTION_ABORTED:1002,UNAUTHORIZED_FOR_ACHIEVEMENT:5010,UNKNOWN_ERROR:1e3};T.RPCCloseCodes={CLOSE_NORMAL:1e3,CLOSE_UNSUPPORTED:1003,CLOSE_ABNORMAL:1006,INVALID_CLIENTID:4e3,INVALID_ORIGIN:4001,RATELIMITED:4002,TOKEN_REVOKED:4003,INVALID_VERSION:4004,INVALID_ENCODING:4005};T.LobbyTypes={PRIVATE:1,PUBLIC:2};T.RelationshipTypes={NONE:0,FRIEND:1,BLOCKED:2,PENDING_INCOMING:3,PENDING_OUTGOING:4,IMPLICIT:5}});var ee=m(()=>{});var ie=m((ut,se)=>{"use strict";var xe=require("events"),{browser:te}=G(),Me=te?window.WebSocket:ee(),Fe=i=>JSON.stringify(i),He=i=>JSON.parse(i),x=class extends xe{constructor(e){super(),this.client=e,this.ws=null,this.tries=0}async connect(){let e=6463+this.tries%10;this.tries+=1,this.ws=new Me(`ws://127.0.0.1:${e}/?v=1&client_id=${this.client.clientId}`,te?void 0:{origin:this.client.options.origin}),this.ws.onopen=this.onOpen.bind(this),this.ws.onclose=this.onClose.bind(this),this.ws.onerror=this.onError.bind(this),this.ws.onmessage=this.onMessage.bind(this)}onOpen(){this.emit("open")}onClose(e){e.wasClean&&this.emit("close",e)}onError(e){try{this.ws.close()}catch(t){}this.tries>20?this.emit("error",e.error):setTimeout(()=>{this.connect()},250)}onMessage(e){this.emit("message",He(e.data))}send(e){this.ws.send(Fe(e))}ping(){}close(){return new Promise(e=>{this.once("close",e),this.ws.close()})}};se.exports=x});var ae=m((ht,ne)=>{"use strict";ne.exports={ipc:Z(),websocket:ie()}});var le=m((dt,ce)=>{"use strict";var ke=require("events"),{setTimeout:qe,clearTimeout:Ye}=require("timers"),$e=v(),Ke=ae(),{RPCCommands:o,RPCEvents:oe,RelationshipTypes:Je}=G(),{pid:re,uuid:je}=w();function We(i,e){return`${i}${JSON.stringify(e)}`}var M=class extends ke{constructor(e={}){super(),this.options=e,this.accessToken=null,this.clientId=null,this.application=null,this.user=null;let t=Ke[e.transport];if(!t)throw new TypeError("RPC_INVALID_TRANSPORT",e.transport);this.fetch=(s,n,{data:a,query:r}={})=>$e(`${this.fetch.endpoint}${n}${r?new URLSearchParams(r):""}`,{method:s,body:a,headers:{Authorization:`Bearer ${this.accessToken}`}}).then(async h=>{let l=await h.json();if(!h.ok){let u=new Error(h.status);throw u.body=l,u}return l}),this.fetch.endpoint="https://discord.com/api",this.transport=new t(this),this.transport.on("message",this._onRpcMessage.bind(this)),this._expecting=new Map,this._connectPromise=void 0}connect(e){return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise((t,s)=>{this.clientId=e;let n=qe(()=>s(new Error("RPC_CONNECTION_TIMEOUT")),1e4);n.unref(),this.once("connected",()=>{Ye(n),t(this)}),this.transport.once("close",()=>{this._expecting.forEach(a=>{a.reject(new Error("connection closed"))}),this.emit("disconnected"),s(new Error("connection closed"))}),this.transport.connect().catch(s)}),this._connectPromise)}async login(e={}){let{clientId:t,accessToken:s}=e;return await this.connect(t),e.scopes?(s||(s=await this.authorize(e)),this.authenticate(s)):(this.emit("ready"),this)}request(e,t,s){return new Promise((n,a)=>{let r=je();this.transport.send({cmd:e,args:t,evt:s,nonce:r}),this._expecting.set(r,{resolve:n,reject:a})})}_onRpcMessage(e){if(e.cmd===o.DISPATCH&&e.evt===oe.READY)e.data.user&&(this.user=e.data.user),this.emit("connected");else if(this._expecting.has(e.nonce)){let{resolve:t,reject:s}=this._expecting.get(e.nonce);if(e.evt==="ERROR"){let n=new Error(e.data.message);n.code=e.data.code,n.data=e.data,s(n)}else t(e.data);this._expecting.delete(e.nonce)}else this.emit(e.evt,e.data)}async authorize({scopes:e,clientSecret:t,rpcToken:s,redirectUri:n,prompt:a}={}){t&&s===!0&&(s=(await this.fetch("POST","/oauth2/token/rpc",{data:new URLSearchParams({client_id:this.clientId,client_secret:t})})).rpc_token);let{code:r}=await this.request("AUTHORIZE",{scopes:e,client_id:this.clientId,prompt:a,rpc_token:s});return(await this.fetch("POST","/oauth2/token",{data:new URLSearchParams({client_id:this.clientId,client_secret:t,code:r,grant_type:"authorization_code",redirect_uri:n})})).access_token}authenticate(e){return this.request("AUTHENTICATE",{access_token:e}).then(({application:t,user:s})=>(this.accessToken=e,this.application=t,this.user=s,this.emit("ready"),this))}getGuild(e,t){return this.request(o.GET_GUILD,{guild_id:e,timeout:t})}getGuilds(e){return this.request(o.GET_GUILDS,{timeout:e})}getChannel(e,t){return this.request(o.GET_CHANNEL,{channel_id:e,timeout:t})}async getChannels(e,t){let{channels:s}=await this.request(o.GET_CHANNELS,{timeout:t,guild_id:e});return s}setCertifiedDevices(e){return this.request(o.SET_CERTIFIED_DEVICES,{devices:e.map(t=>({type:t.type,id:t.uuid,vendor:t.vendor,model:t.model,related:t.related,echo_cancellation:t.echoCancellation,noise_suppression:t.noiseSuppression,automatic_gain_control:t.automaticGainControl,hardware_mute:t.hardwareMute}))})}setUserVoiceSettings(e,t){return this.request(o.SET_USER_VOICE_SETTINGS,{user_id:e,pan:t.pan,mute:t.mute,volume:t.volume})}selectVoiceChannel(e,{timeout:t,force:s=!1}={}){return this.request(o.SELECT_VOICE_CHANNEL,{channel_id:e,timeout:t,force:s})}selectTextChannel(e,{timeout:t}={}){return this.request(o.SELECT_TEXT_CHANNEL,{channel_id:e,timeout:t})}getVoiceSettings(){return this.request(o.GET_VOICE_SETTINGS).then(e=>({automaticGainControl:e.automatic_gain_control,echoCancellation:e.echo_cancellation,noiseSuppression:e.noise_suppression,qos:e.qos,silenceWarning:e.silence_warning,deaf:e.deaf,mute:e.mute,input:{availableDevices:e.input.available_devices,device:e.input.device_id,volume:e.input.volume},output:{availableDevices:e.output.available_devices,device:e.output.device_id,volume:e.output.volume},mode:{type:e.mode.type,autoThreshold:e.mode.auto_threshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}}))}setVoiceSettings(e){return this.request(o.SET_VOICE_SETTINGS,{automatic_gain_control:e.automaticGainControl,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,qos:e.qos,silence_warning:e.silenceWarning,deaf:e.deaf,mute:e.mute,input:e.input?{device_id:e.input.device,volume:e.input.volume}:void 0,output:e.output?{device_id:e.output.device,volume:e.output.volume}:void 0,mode:e.mode?{type:e.mode.type,auto_threshold:e.mode.autoThreshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}:void 0})}captureShortcut(e){let t=We(oe.CAPTURE_SHORTCUT_CHANGE),s=()=>(this._subscriptions.delete(t),this.request(o.CAPTURE_SHORTCUT,{action:"STOP"}));return this._subscriptions.set(t,({shortcut:n})=>{e(n,s)}),this.request(o.CAPTURE_SHORTCUT,{action:"START"}).then(()=>s)}setActivity(e={},t=re()){let s,n,a,r;if(e.startTimestamp||e.endTimestamp){if(s={start:e.startTimestamp,end:e.endTimestamp},s.start instanceof Date&&(s.start=Math.round(s.start.getTime())),s.end instanceof Date&&(s.end=Math.round(s.end.getTime())),s.start>2147483647e3)throw new RangeError("timestamps.start must fit into a unix timestamp");if(s.end>2147483647e3)throw new RangeError("timestamps.end must fit into a unix timestamp")}return(e.largeImageKey||e.largeImageText||e.smallImageKey||e.smallImageText)&&(n={large_image:e.largeImageKey,large_text:e.largeImageText,small_image:e.smallImageKey,small_text:e.smallImageText}),(e.partySize||e.partyId||e.partyMax)&&(a={id:e.partyId},(e.partySize||e.partyMax)&&(a.size=[e.partySize,e.partyMax])),(e.matchSecret||e.joinSecret||e.spectateSecret)&&(r={match:e.matchSecret,join:e.joinSecret,spectate:e.spectateSecret}),this.request(o.SET_ACTIVITY,{pid:t,activity:{state:e.state,details:e.details,timestamps:s,assets:n,party:a,secrets:r,buttons:e.buttons,instance:!!e.instance}})}clearActivity(e=re()){return this.request(o.SET_ACTIVITY,{pid:e})}sendJoinInvite(e){return this.request(o.SEND_ACTIVITY_JOIN_INVITE,{user_id:e.id||e})}sendJoinRequest(e){return this.request(o.SEND_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}closeJoinRequest(e){return this.request(o.CLOSE_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}createLobby(e,t,s){return this.request(o.CREATE_LOBBY,{type:e,capacity:t,metadata:s})}updateLobby(e,{type:t,owner:s,capacity:n,metadata:a}={}){return this.request(o.UPDATE_LOBBY,{id:e.id||e,type:t,owner_id:s&&s.id||s,capacity:n,metadata:a})}deleteLobby(e){return this.request(o.DELETE_LOBBY,{id:e.id||e})}connectToLobby(e,t){return this.request(o.CONNECT_TO_LOBBY,{id:e,secret:t})}sendToLobby(e,t){return this.request(o.SEND_TO_LOBBY,{id:e.id||e,data:t})}disconnectFromLobby(e){return this.request(o.DISCONNECT_FROM_LOBBY,{id:e.id||e})}updateLobbyMember(e,t,s){return this.request(o.UPDATE_LOBBY_MEMBER,{lobby_id:e.id||e,user_id:t.id||t,metadata:s})}getRelationships(){let e=Object.keys(Je);return this.request(o.GET_RELATIONSHIPS).then(t=>t.relationships.map(s=>({...s,type:e[s.type]})))}async subscribe(e,t){return await this.request(o.SUBSCRIBE,t,e),{unsubscribe:()=>this.request(o.UNSUBSCRIBE,t,e)}}async destroy(){await this.transport.close()}};ce.exports=M});var he=m((mt,ue)=>{"use strict";var ze=w();ue.exports={Client:le(),register(i){return ze.register(`discord-${i}`)}}});var tt={};ye(tt,{default:()=>L});module.exports=Re(tt);var Ce=De(he()),b=require("obsidian");var F=require("obsidian"),N=class{constructor(e){this.plugin=e}log(e,t){t&&new F.Notice(e),console.log(`discordrpc: ${e}`)}logIgnoreNoNotice(e){new F.Notice(e),console.log(`discordrpc: ${e}`)}};var O=class{constructor(){this.showVaultName=!0;this.showCurrentFileName=!0;this.showFolderName=!1;this.showConnectionTimer=!1;this.showPopups=!0;this.customVaultName="";this.showFileExtension=!1;this.useLoadedTime=!1;this.connectOnStart=!0;this.autoHideStatusBar=!0;this.privacyMode=!1;this.themeStyle="default-new-dark"}};var c=require("obsidian");var y="Mouadhbendjedidi/themed-obsidian-discord-rpc",Qe=`https://api.github.com/repos/${y}`,H=null,k=null,q=null,de=0,me=0,Ee=0,Y=36e5;async function pe(){let i=Date.now();if(q!==null&&i-Ee({name:n.name,displayName:n.displayName,url:`${t}/${n.filename}`}));return s.length>0?s:Te(f())}catch(i){return console.warn("Error fetching theme images from GitHub:",i),Te(f())}}function Te(i){let e=`https://raw.githubusercontent.com/${y}/main/assets/themes`;return i.map(t=>({name:t.name,displayName:t.displayName,url:`${e}/${t.filename}`}))}async function ge(){let i=Date.now();if(H!==null&&i-des.name===i);return t?t.url:i}async function Ie(){return ge()}var D=class extends c.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t,this.logger=new N(t)}display(){let{containerEl:e}=this,t=this.plugin;e.empty(),new c.Setting(e).setName("Vault name").setHeading(),new c.Setting(e).setName("Privacy mode").setDesc("Enable this to hide the name of the vault and Hide file names").addToggle(s=>s.setValue(t.settings.privacyMode).onChange(n=>{t.settings.privacyMode=n,t.saveData(t.settings),t.setActivity("","","")})),new c.Setting(e).setName("Show vault name").setDesc("Enable this to show the name of the vault you are working with.").addToggle(s=>s.setValue(t.settings.showVaultName).onChange(n=>{t.settings.showVaultName=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})),new c.Setting(e).setName("Set custom vault name").setDesc("Change the vault name shown publicly. Leave blank to use your actual vault name.").addText(s=>s.setValue(t.settings.customVaultName).onChange(n=>{t.settings.customVaultName=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})),new c.Setting(e).setName("File & Folder Name").setHeading(),new c.Setting(e).setName("Show current file name").setDesc("Enable this to show the name of the file you are working on.").addToggle(s=>s.setValue(t.settings.showCurrentFileName).onChange(n=>{t.settings.showCurrentFileName=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})),new c.Setting(e).setName("Show folder name").setDesc("Enable this to show the folder path where the file is located.").addToggle(s=>s.setValue(t.settings.showFolderName).onChange(n=>{t.settings.showFolderName=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})),new c.Setting(e).setName("Show file extension").setDesc("Enable this to show file extension.").addToggle(s=>s.setValue(t.settings.showFileExtension).onChange(n=>{t.settings.showFileExtension=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})),new c.Setting(e).setName("Time tracking").setHeading(),new c.Setting(e).setName("Use obsidian total time").setDesc("Enable to use the total time you have been using Obsidian, instead of the time spent editing a single file.").addToggle(s=>{s.setValue(t.settings.useLoadedTime).onChange(n=>{t.settings.useLoadedTime=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})}),new c.Setting(e).setName("Status bar").setHeading(),new c.Setting(e).setName("Automatically hide status bar").setDesc("Automatically hide status bar after successfully connecting to Discord.").addToggle(s=>{s.setValue(t.settings.autoHideStatusBar).onChange(n=>{t.settings.autoHideStatusBar=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})}),new c.Setting(e).setName("Show connected time").setDesc("Show time spent editing file or time connected to Discord in the status bar.").addToggle(s=>{s.setValue(t.settings.showConnectionTimer).onChange(n=>{t.settings.showConnectionTimer=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension),t.statusBar.displayState(t.getState(),t.settings.autoHideStatusBar)})}),new c.Setting(e).setName("Startup behavior").setHeading(),new c.Setting(e).setName("Automatically connect to Discord").setDesc("Automatically connect to Discord on startup. You can always click the status bar to manually connect.").addToggle(s=>{s.setValue(t.settings.connectOnStart).onChange(n=>{t.settings.connectOnStart=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})}),new c.Setting(e).setName("Notices").setHeading(),new c.Setting(e).setName("Show notices").setDesc("Enable this to show connection Notices.").addToggle(s=>s.setValue(t.settings.showPopups).onChange(n=>{t.settings.showPopups=n,t.saveData(t.settings),t.setActivity(this.app.vault.getName(),t.currentFile.basename,t.currentFile.extension)})),new c.Setting(e).setName("Theme style").setHeading(),this.loadThemeSelector(e,t)}async loadThemeSelector(e,t){try{let s=await Ie();new c.Setting(e).setName("Theme style").setDesc("Choose the theme style for Discord Rich Presence").addDropdown(n=>{var h;s.forEach(l=>{n.addOption(l.name,l.displayName)});let a=t.settings.themeStyle,r=s.some(l=>l.name===a);n.setValue(r?a:((h=s[0])==null?void 0:h.name)||"default-new-dark"),n.onChange(async l=>{var u,d,_,K;t.settings.themeStyle=l,await t.saveData(t.settings),t.getState()===0&&await t.setActivity(t.app.vault.getName(),(d=(u=t.currentFile)==null?void 0:u.basename)!=null?d:"...",(K=(_=t.currentFile)==null?void 0:_.extension)!=null?K:"")})})}catch(s){console.error("Error loading theme selector:",s),new c.Setting(e).setName("Theme style").setDesc("Error loading themes. Using defaults.").addButton(n=>n.setButtonText("Retry").onClick(()=>{let a=e.parentElement;if(a){e.remove();let r=a.createDiv();this.loadThemeSelector(r,t)}}))}}};var $=require("obsidian"),R=class i{constructor(e){this.statusBarEl=e}displayState(e,t){switch(e){case 0:this.displayConnected(t?1e4:0);break;case 1:this.statusBarEl.setText("Connecting to Discord...");break;case 2:this.statusBarEl.setText("\u{1F5D8} Reconnect to Discord");break}}displayTimer(e){this.statusBarEl.setText(`\u{1F30D} ${i.millisecsToString(new Date().getTime()-e.getTime())}`)}displayConnected(e){this.statusBarEl.setText("\u2713 Connected to Discord"),e&&e>0?window.setTimeout(()=>{this.statusBarEl.setText("")},e):window.setTimeout(()=>{this.statusBarEl.setText("Discord RPC")},5e3)}static millisecsToString(e){let t;return e>=3600*1e3?t=$.moment.utc(e).format("HH:mm:ss"):t=$.moment.utc(e).format("mm:ss"),t.toString()}};var L=class extends b.Plugin{constructor(){super(...arguments);this.logger=new N(this)}setState(t){this.state=t}getState(){return this.state}getApp(){return this.app}getPluginManifest(){return this.manifest}async onload(){let t=this.addStatusBarItem();this.statusBar=new R(t),this.settings=await this.loadData()||new O,this.registerEvent(this.app.workspace.on("file-open",this.onFileOpen,this)),this.registerInterval(window.setInterval(async()=>{this.settings.showConnectionTimer&&this.getState()==0&&this.statusBar.displayTimer(this.settings.useLoadedTime?this.loadedTime:this.lastSetTime)},500)),this.registerDomEvent(t,"click",async()=>{this.getState()==2?await this.connectDiscord():this.getState()==0&&await this.disconnectDiscord()}),this.addSettingTab(new D(this.app,this)),this.addCommand({id:"reconnect-discord",name:"Reconnect to Discord",callback:async()=>await this.connectDiscord()}),this.addCommand({id:"disconnect-discord",name:"Disconnect from Discord",callback:async()=>await this.disconnectDiscord()}),this.settings.connectOnStart?this.connectDiscord().then(()=>{let s=this.app.workspace.getActiveViewOfType(b.MarkdownView),n=this.app.vault.getMarkdownFiles();if(s){let a=s.getDisplayText();n.forEach(r=>{r.basename===a&&this.onFileOpen(r)})}}):(this.setState(2),this.statusBar.displayState(this.getState(),this.settings.autoHideStatusBar))}async onFileOpen(t){this.currentFile=t,this.getState()===0&&await this.setActivity(this.app.vault.getName(),t.basename,t.extension)}async onunload(){await this.saveData(this.settings),this.rpc.clearActivity(),this.rpc.destroy()}async connectDiscord(){this.loadedTime=new Date,this.lastSetTime=new Date,this.rpc=new Ce.Client({transport:"ipc"}),this.setState(1),this.statusBar.displayState(this.getState(),this.settings.autoHideStatusBar),this.rpc.once("ready",()=>{this.setState(0),this.statusBar.displayState(this.getState(),this.settings.autoHideStatusBar),this.logger.log("Connected to Discord",this.settings.showPopups)});try{await this.rpc.login({clientId:"1352970439684657152"}),await this.setActivity(this.app.vault.getName(),"...","")}catch(t){this.setState(2),this.statusBar.displayState(this.getState(),this.settings.autoHideStatusBar),this.logger.log("Failed to connect to Discord",this.settings.showPopups)}}async disconnectDiscord(){this.rpc.clearActivity(),this.rpc.destroy(),this.setState(2),this.statusBar.displayState(this.getState(),this.settings.autoHideStatusBar),this.logger.log("Disconnected from Discord",this.settings.showPopups)}async setActivity(t,s,n){var a;if(this.getState()===0){let r;this.settings.customVaultName===""?r=t:r=this.settings.customVaultName;let h;this.settings.showFileExtension?h=s+"."+n:h=s;let l="";if(this.settings.showFolderName&&this.currentFile){let _=(a=this.currentFile.parent)==null?void 0:a.path;_&&_!=="/"&&(l=_)}let u;this.settings.useLoadedTime?u=this.loadedTime:u=new Date,this.lastSetTime=u;let d=await _e(this.settings.themeStyle);this.settings.privacyMode?await this.rpc.setActivity({details:"Editing Notes",state:"Working in a Vault",startTimestamp:u,largeImageKey:d,largeImageText:"no info just privacy mode"}):this.settings.showVaultName&&this.settings.showCurrentFileName&&this.settings.showFolderName&&l?await this.rpc.setActivity({details:`Editing ${h}`,state:`Vault: ${r} \u25B8 ${l}`,startTimestamp:u,largeImageKey:d,largeImageText:"I'm thinking!"}):this.settings.showVaultName&&this.settings.showCurrentFileName?await this.rpc.setActivity({details:`Editing ${h}`,state:`Vault: ${r}`,startTimestamp:u,largeImageKey:d,largeImageText:"I'm thinking!"}):this.settings.showFolderName&&l&&this.settings.showCurrentFileName?await this.rpc.setActivity({details:`Editing: ${h}`,state:`Folder: ${l}`,startTimestamp:u,largeImageKey:d,largeImageText:"I'm thinking!"}):this.settings.showVaultName?await this.rpc.setActivity({state:`Vault: ${r}`,startTimestamp:u,largeImageKey:d,largeImageText:"Obsidian"}):this.settings.showCurrentFileName?await this.rpc.setActivity({details:`Editing ${h}`,startTimestamp:u,largeImageKey:d,largeImageText:"I'm thinking!"}):await this.rpc.setActivity({startTimestamp:u,largeImageKey:d,largeImageText:"Obsidian"})}}}; /* nosourcemap */