${i}`,t*1e3);s&&(o.noticeEl.oncontextmenu=()=>{s()})}varj=(n,e=!0)=>{lett=n.createEl("div");t.style.float="right",e?(t.style.padding="15px",t.style.paddingLeft="15px",t.style.paddingRight="15px",t.style.marginLeft="15px"):(t.style.padding="10px",t.style.paddingLeft="15px",t.style.paddingRight="15px");lets=t.createDiv("coffee");s.addClass("ex-twitter-span"),s.style.paddingLeft="10px";leti=s.createDiv();i.innerText="Learn more about my work at:",s.appendChild(i);leto=s.createEl("a",{href:"https://tfthacker.com"});returno.innerText="https://tfthacker.com",t};varAt=require("obsidian"),ye=classextendsAt.SuggestModal{constructor(e,t,s,i,o){super(e),this.versions=s,this.selected=i,this.onChoose=o,this.setTitle("Select a version"),this.setPlaceholder(`Type to search for a version for ${t}`),this.setInstructions([{command:"\u2191\u2193",purpose:"Navigate versions"},{command:"\u21B5",purpose:"Select version"},{command:"esc",purpose:"Dismiss modal"}])}getSuggestions(e){lett=e.toLowerCase();returnthis.versions.filter(s=>s.version.toLowerCase().contains(t))}renderSuggestion(e,t){t.createEl("div",{text:`${e.version}${e.prerelease?"(Prerelease)":""}`})}onChooseSuggestion(e){this.onChoose(e.version)}onNoSuggestion(){this.onChoose(this.selected?this.selected:""),this.close()}};varM=classextendsN.Modal{constructor(t,s,i=!1,o=!1,r="",a="",u=""){super(t.app);this.versionSetting=null;this.repositoryAddressEl=null;this.tokenInputEl=null;this.validateButton=null;this.validator=null;this.addPluginButton=null;this.cancelButton=null;this.plugin=t,this.betaPlugins=s,this.address=r,this.version=a,this.privateApiKey=u,this.usePrivateApiKey=!(u===""||u===void0),this.openSettingsTabAfterwards=i,this.updateVersion=o,this.enableAfterInstall=t.settings.enableAfterInstall}asyncsubmitForm(){varo,r,a,u,l,c,p,h;if(this.address==="")return;lett=we(this.address),s=this.plugin.settings.pluginSubListFrozenVersion.find(m=>m.repo===t);if(s){awaitthis.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!0,this.enableAfterInstall,this.usePrivateApiKey?this.privateApiKey:void0)&&(s.version=this.version,s.token=this.usePrivateApiKey?this.privateApiKey||"":void0,awaitthis.plugin.saveSettings(),this.close()),(o=this.cancelButton)==null||o.setDisabled(!1),(r=this.addPluginButton)==null||r.setDisabled(!1),(a=this.addPluginButton)==null||a.setButtonText("Add Plugin"),(u=this.versionSetting)==null||u.setDisabled(!1);return}if(!this.version&&yt(this.plugin,t)){b(this.plugin,"This plugin is already in the list for beta testing",10);return}awaitthis.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!1,this.enableAfterInstall,this.usePrivateApiKey?this.privateApiKey:void0)&&this.close(),(l=this.cancelButton)==null||l.setDisabled(!1),(c=this.addPluginButton)==null||c.setDisabled(!1),(p=this.addPluginButton)==null||p.setButtonText("Add Plugin"),(h=this.versionSetting)==null||h.setDisabled(!1)}updateVersionDropdown(t,s,i=""){leto;t.clear(),s.length>0&&!i&&this.plugin.settings.selectLatestPluginVersionByDefault?o="latest":o=i,s.length<20||N.Platform.isMobile?t.addDropdown(a=>{a.addOption("","Select a version"),a.addOption("latest","Latest version");for(letlofs)a.addOption(l.version,`${l.version}${l.prerelease?"(Prerelease)":""}`);letu=l=>{this.version=l,this.updateAddButtonState()};a.onChange(u),a.setValue(o),u(o),a.selectEl.addClass("brat-version-selector"),a.selectEl.style.width="100%"}):t.addButton(a=>{a.setButtonText(o==="latest"?"Latest version":o||"Select a version...").setClass("brat-version-selector").setClass("button").onClick(u=>{u.preventDefault();letc=[{version:"latest",prerelease:!1},...s];newye(this.app,this.address,c,o,h=>{this.version=h,a.setButtonText(h==="latest"?"Latest version":h||"Select a version..."),this.updateAddButtonState()}).open()})})}updateAddButtonState(){this.addPluginButton&&this.addPluginButton.setDisabled(this.version==="")}onOpen(){lett=this.contentEl.createEl("h4");this.address?(t.appendText("Change plugin version: "),t.appendChild(Q(this.address))):t.setText("Github repository for beta plugin:"),this.contentEl.createEl(
ThepluginhasbeenregisteredwithBRAT.`;a||(v+=" You may still need to enable it the Community Plugin List."),await this.plugin.log(v,!0),b(this.plugin,v,l)}}else{let m=`${this.plugin.app.vault.configDir}/plugins/${c.id}/`,y="";try{y=await this.plugin.app.vault.adapter.read(`${m}manifest.json`)}catch(I){if(I.errno===-4058||I.errno===-2)return await this.addPlugin(e,!1,p,!1,o,!1,a,u),!0;console.log("BRAT - Local Manifest Load",c.id,JSON.stringify(I,null,2))}if(o!==""&&o!=="latest")return b(this.plugin,`Theversionof${e}isfrozen,notupdating.`,3),!1;let v=await JSON.parse(y),T=Pe(v.version,{includePrerelease:!0,loose:!0}),E=Pe(c.version,{includePrerelease:!0,loose:!0});if(Lt(T,E)===-1){let I=await h();if(I===null)return!1;if(s){let ce=`Thereisanupdateavailablefor${c.id}fromversion${v.version}to${c.version}.`;return await this.plugin.log(`${ce}[ReleaseInfo](https://github.com/${e}/releases/tag/${c.version})`,!0),b(this.plugin,ce,30,()=>{c&&window.open(`https://github.com/${e}/releases/tag/${c.version}`)}),!1}await this.writeReleaseFilesToPluginFolder(c.id,I),await this.plugin.app.plugins.loadManifests(),await this.reloadPlugin(c.id);let $=`${c.id}
Updateofpluginfailed.`),r}async checkForPluginUpdatesAndInstallUpdates(e=!1,t=!1){var a,u;if(!await ve()){console.log("BRAT: No internet detected.");return}let s,i="Checking for plugin updates STARTED";await this.plugin.log(i,!0),e&&this.plugin.settings.notificationsEnabled&&(s=new F.Notice(`BRAT
${i}`,3e4));let o=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(l=>[l.repo,{version:l.version,token:l.token}]));for(let l of this.plugin.settings.pluginList)o.has(l)&&((a=o.get(l))==null?void 0:a.version)!=="latest"||await this.updatePlugin(l,t,!1,!1,(u=o.get(l))==null?void 0:u.token);let r="Checking for plugin updates COMPLETED";await this.plugin.log(r,!0),e&&(s&&s.hide(),b(this.plugin,r,10))}deletePlugin(e){let t=`Removed${e}fromBRATpluginlist`;this.plugin.log(t,!0),this.plugin.settings.pluginList=this.plugin.settings.pluginList.filter(s=>s!==e),this.plugin.settings.pluginSubListFrozenVersion=this.plugin.settings.pluginSubListFrozenVersion.filter(s=>s.repo!==e),this.plugin.saveSettings()}getEnabledDisabledPlugins(e){let t=this.plugin.app.plugins,s=Object.values(t.manifests),i=Object.values(t.plugins).map(o=>o.manifest);return e?s.filter(o=>i.find(r=>o.id===r.id)):s.filter(o=>!i.find(r=>o.id===r.id))}};var V=require("obsidian");var J=async(n,e,t)=>{let s=await _(e,!0,n.settings.debuggingMode);if(s||(s=await _(e,!1,n.settings.debuggingMode)),!s)return b(n,"There is no theme.css or theme-beta.css file in the root path of this repository, so there is no theme to install."),!1;let i=await wt(e,n.settings.debuggingMode);if(!i)return b(n,"There is no manifest.json file in the root path of this repository, so theme cannot be installed."),!1;let o=await JSON.parse(i),r=(0,V.normalizePath)(Ds(n)+o.name),{adapter:a}=n.app.vault;await a.exists(r)||await a.mkdir(r),await a.write((0,V.normalizePath)(`${r}/theme.css`),s),await a.write((0,V.normalizePath)(`${r}/manifest.json`),i),Rt(n,e,K(s));let u="";return t?(vt(n,e,s),u=`${o.name}themeinstalledfrom${e}.`,setTimeout(()=>{n.app.customCss.setTheme(o.name)},500)):u=`${o.name}themeupdatedfrom${e}.`,n.log(`${u}[ThemeInfo](https://github.com/${e})`,!1),b(n,u,20,()=>{window.open(`https://github.com/${e}`)}),!0},q=async(n,e)=>{if(!await ve()){console.log("BRAT: No internet detected.");return}let t,s="Checking for beta theme updates STARTED";await n.log(s,!0),e&&n.settings.notificationsEnabled&&(t=new V.Notice(`BRAT
${s}`,3e4));for(let o of n.settings.themesList){let r=await W(o.repo,!0,n.settings.debuggingMode);r==="0"&&(r=await W(o.repo,!1,n.settings.debuggingMode)),console.log("BRAT: lastUpdateOnline",r),r!==o.lastUpdate&&await J(n,o.repo,!1)}let i="Checking for beta theme updates COMPLETED";(async()=>await n.log(i,!0))(),e&&(n.settings.notificationsEnabled&&t&&t.hide(),b(n,i))},Re=(n,e)=>{n.settings.themesList=n.settings.themesList.filter(s=>s.repo!==e),n.saveSettings();let t=`Removed${e}fromBRATthemeslistandwillnolongerbeupdated.However,thethemefilesstillexistinthevault.Toremovethem,gointoSettings>Appearanceandremovethetheme.`;n.log(t,!0),b(n,t)},Ds=n=>`${(0,V.normalizePath)(`${n.app.vault.configDir}/themes`)}/`;var U=require("obsidian");var O=class extends U.Modal{constructor(e,t=!1){super(e.app),this.plugin=e,this.address="",this.openSettingsTabAfterwards=t}async submitForm(){if(this.address==="")return;let e=this.address.replace("https://github.com/","");if(Pt(this.plugin,e)){b(this.plugin,"This theme is already in the list for beta testing",10);return}await J(this.plugin,e,!0)&&this.close()}onOpen(){this.contentEl.createEl("h4",{text:"Github repository for beta theme:"}),this.contentEl.createEl("form",{},e=>{e.addClass("brat-modal"),new U.Setting(e).addText(i=>{i.setPlaceholder("Repository (example: https://github.com/GitHubUserName/repository-name"),i.setValue(this.address),i.onChange(o=>{this.address=o.trim()}),i.inputEl.addEventListener("keydown",o=>{o.key==="Enter"&&this.address!==" "&&(o.preventDefault(),this.submitForm())}),i.inputEl.style.width="100%",window.setTimeout(()=>{let o=document.querySelector(".setting-item-info");o&&o.remove(),i.inputEl.focus()},10)}),e.createDiv("modal-button-container",i=>{new U.ButtonComponent(i).setButtonText("Never mind").onClick(()=>{this.close()}),new U.ButtonComponent(i).setButtonText("Add theme").setCta().onClick(o=>{o.preventDefault(),console.log("Add theme button clicked"),this.address!==""&&this.submitForm()})});let t=e.createDiv();t.style.borderTop="1px solid #ccc",t.style.marginTop="30px";let s=t.createSpan();s.innerHTML="BRAT by <a href='https://bit.ly/o42-twitter'>TFTHacker</a>",s.style.fontStyle="italic",t.appendChild(s),j(t,!1),window.setTimeout(()=>{let i=e.querySelectorAll(".brat-modal .setting-item-info");for(let o of Array.from(i))o.remove()},50)})}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.openTab(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}};var Ct=require("obsidian"),L=class extends Ct.FuzzySuggestModal{constructor(t){super(t.app);this.data=[];this.scope.register(["Shift"],"Enter",s=>{this.enterTrigger(s)}),this.scope.register(["Ctrl"],"Enter",s=>{this.enterTrigger(s)})}setSuggesterData(t){this.data=t}display(t){this.callbackFunction=t,this.open()}getItems(){return this.data}getItemText(t){return t.display}onChooseItem(){}renderSuggestion(t,s){s.createEl("div",{text:t.item.display})}enterTrigger(t){var o;let s=(o=document.querySelector(".suggestion-item.is-selected div"))==null?void 0:o.textContent,i=this.data.find(r=>r.display===s);i&&(this.invokeCallback(i,t),this.close())}onChooseSuggestion(t,s){this.invokeCallback(t.item,s)}invokeCallback(t,s){typeof this.callbackFunction=="function"&&this.callbackFunction(t,s)}};var ee=class{constructor(e){this.bratCommands=[{id:"AddBetaPlugin",icon:"BratIcon",name:"Plugins: Add a beta plugin for testing (with or without version)",showInRibbon:!0,callback:()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!1,!0)}},{id:"checkForUpdatesAndUpdate",icon:"BratIcon",name:"Plugins: Check for updates to all beta plugins and UPDATE",showInRibbon:!0,callback:async()=>{await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!0,!1)}},{id:"checkForUpdatesAndDontUpdate",icon:"BratIcon",name:"Plugins: Only check for updates to beta plugins, but don't Update",showInRibbon:!0,callback:async()=>{await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!0,!0)}},{id:"updateOnePlugin",icon:"BratIcon",name:"Plugins: Choose a single plugin version to
${o}`,3),this.plugin.betaPlugins.updatePlugin(i.info,!1,!0,!1,r==null?void0:r.token)})}},{id:"reinstallOnePlugin",icon:"BratIcon",name:"Plugins: Choose a single plugin to reinstall",showInRibbon:!0,callback:()=>{lete=newSet(this.plugin.settings.pluginSubListFrozenVersion.map(i=>i.repo)),t=Object.values(this.plugin.settings.pluginList).filter(i=>!e.has(i)).map(i=>({display:i,info:i})),s=newL(this.plugin);s.setSuggesterData(t),s.display(i=>{leto=`Reinstalling ${i.info}`;b(this.plugin,`
${o}`,3),this.plugin.log(o,!0),this.plugin.betaPlugins.updatePlugin(i.info,!1,!1,!0)})}},{id:"restartPlugin",icon:"BratIcon",name:"Plugins: Restart a plugin that is already installed",showInRibbon:!0,callback:()=>{lete=Object.values(this.plugin.app.plugins.manifests).map(s=>({display:s.id,info:s.id})),t=newL(this.plugin);t.setSuggesterData(e),t.display(s=>{b(this.plugin,`${s.info}
Plugin reloading .....`,5),this.plugin.betaPlugins.reloadPlugin(s.info)})}},{id:"disablePlugin",icon:"BratIcon",name:"Plugins: Disable a plugin - toggle it off",showInRibbon:!0,callback:()=>{lete=this.plugin.betaPlugins.getEnabledDisabledPlugins(!0).map(s=>({display:`${s.name} (${s.id})`,info:s.id})),t=newL(this.plugin);t.setSuggesterData(e),t.display(s=>{this.plugin.log(`${s.display} plugin disabled`,!1),this.plugin.settings.debuggingMode&&console.log(s.info),this.plugin.app.plugins.disablePluginAndSave(s.info)})}},{id:"enablePlugin",icon:"BratIcon",name:"Plugins: Enable a plugin - toggle it on",showInRibbon:!0,callback:()=>{lete=this.plugin.betaPlugins.getEnabledDisabledPlugins(!1).map(s=>({display:`${s.name} (${s.id})`,info:s.id})),t=newL(this.plugin);t.setSuggesterData(e),t.display(s=>{this.plugin.log(`${s.display} plugin enabled`,!1),this.plugin.app.plugins.enablePluginAndSave(s.info)})}},{id:"openGitHubZRepository",icon:"BratIcon",name:"Plugins: Open the GitHub repository for a plugin",showInRibbon:!0,callback:async()=>{lete=awaitft(this.plugin.settings.debuggingMode);if(e){lett=Object.values(e).map(o=>({display:`Plugin: ${o.name} (${o.repo})`,info:o.repo})),s=Object.values(this.plugin.settings.pluginList).map(o=>({display:`BRAT: ${o}`,info:o}));for(letooft)s.push(o);leti=newL(this.plugin);i.setSuggesterData(s),i.display(o=>{o.info&&window.open(`https://github.com/${o.info}`)})}}},{id:"openGitHubRepoTheme",icon:"BratIcon",name:"Themes: Open the GitHub repository for a theme (appearance)",showInRibbon:!0,callback:async()=>{lete=awaitbt(this.plugin.settings.debuggingMode);if(e){lett=Object.values(e).map(i=>({display:`Theme: ${i.name} (${i.repo})`,info:i.repo})),s=newL(this.plugin);s.setSuggesterData(t),s.display(i=>{i.info&&window.open(`https://github.com/${i.info}`)})}}},{id:"opentPluginSettings",icon:"BratIcon",name:"Plugins: Open Plugin Settings Tab",showInRibbon:!0,callback:()=>{lete=this.plugin.app.setting,t=Object.values(e.pluginTabs).map(o=>({display:`Plugin: ${o.name}`,info:o.id})),s=newL(this.plugin),i=Object.values(e.settingTabs).map(o=>({display:`Core: ${o.name}`,info:o.id}));for(letooft)i.push(o);s.setSuggesterData(i),s.display(o=>{e.open(),e.openTabById(o.info)})}},{id:"GrabBetaTheme",icon:"BratIcon",name:"Themes: Grab a beta theme for testing from a Github repository",showInRibbon:!0,callback:()=>{newO(this.plugin).open()}},{id:"updateBetaThemes",icon:"BratIcon",name:"Themes: Update beta themes",showInRibbon:!0,callback:async()=>{awaitq(this.plugin,!0)}},{id:"allCommands",icon:"BratIcon",name:"All Commands list",showInRibbon:!1,callback:()=>{this.ribbonDisplayCommands()}}];this.plugin=e;for(lettofthis.bratCommands)this.plugin.addCommand({id:t.id,name:t.name,icon:t.icon,callback:()=>{t.callback()}})}ribbonDisplayCommands(){lete=[];for(letrofthis.bratCommands)r.showInRibbon&&e.push({display:r.name,info:r.callback});lett=newL(this.plugin),s=this.plugin.app.setting,i=Object.values(s.settingTabs).map(r=>({display:`Core: ${r.name}`,info:()=>{s.open(),s.openTabById(r.id)}})),o=Object.values(s.pluginTabs).map(r=>({display:`Plugin: ${r.name}`,info:()=>{s.open(),s.openTabById(r.id)}}));e.push({display:"---- Core Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(letrofi)e.push(r);e.push({display:"---- Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(letrofo)e.push(r);t.setSuggesterData(e),t.display(r=>{typeofr.info=="function"&&r.info()})}};varR=require("obsidian");varIe=classextendsR.PluginSettingTab{constructor(t,s){super(t,s);this.accessTokenSetting=null;this.accessTokenButton=null;this.tokenInfo=null;this.validator=null;this.plugin=s}display(){let{containerEl:t}=this;t.empty(),t.addClass("brat-settings"),newR.Setting(t).setName("Auto-enable plugins after installation").setDesc('If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.').addToggle(i=>{i.setValue(this.plugin.settings.enableAfterInstall).onChange(asynco=>{this
`," ")}
`,u=n.app.vault.getAbstractFileByPath(s);u?awaitn.app.vault.append(u,a):u=awaitn.app.vault.create(s,a)}}varAe=classextendsYt.Plugin{constructor(){super(...arguments);this.APP_NAME="BRAT";this.APP_ID="obsidian42-brat";this.settings=Me;this.betaPlugins=newZ(this);this.commands=newee(this);this.bratApi=newte(this);this.obsidianProtocolHandler=t=>{if(!t.plugin&&!t.theme){b(this,"Could not locate the repository from the URL.",10);return}for(letsof["plugin","theme"])if(t[s]){leti;switch(s){case"plugin":i=newM(this,this.betaPlugins,!0,!1,t[s],t.version?t.version:void0),i.open();break;case"theme":i=newO(this),i.address=t[s],i.open();break}return}}}onload(){console.log(`loading ${this.APP_NAME}`),$t(),this.addRibbonIcon("BratIcon","BRAT",()=>{this.commands.ribbonDisplayCommands()}),this.loadSettings().then(()=>{this.app.workspace.onLayoutReady(()=>{this.addSettingTab(newIe(this.app,this)),this.registerObsidianProtocolHandler("brat",this.obsidianProtocolHandler),this.settings.updateAtStartup&&setTimeout(()=>{this.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!1)},6e4),this.settings.updateThemesAtStartup&&setTimeout(()=>{q(this,!1)},12e4),setTimeout(()=>{window.bratAPI=this.bratApi},500)})}).catch(t=>{console.error("Failed to load settings:",t)})}asynclog(t,s=!1){awaitXt(this,t,s)}onunload(){console.log(`unloading ${this.APP_NAME}`)}asyncloadSettings(){this.settings=Object.assign({},Me,awaitthis.loadData())}asyncsaveSettings(){awaitthis.saveData(this.settings)}};