45 lines
81 KiB
JavaScript
45 lines
81 KiB
JavaScript
|
|
"use strict";var nn=Object.create;var pe=Object.defineProperty;var sn=Object.getOwnPropertyDescriptor;var on=Object.getOwnPropertyNames;var rn=Object.getPrototypeOf,an=Object.prototype.hasOwnProperty;var x=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),ln=(s,e)=>{for(var t in e)pe(s,t,{get:e[t],enumerable:!0})},Ze=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of on(e))!an.call(s,i)&&i!==t&&pe(s,i,{get:()=>e[i],enumerable:!(n=sn(e,i))||n.enumerable});return s};var un=(s,e,t)=>(t=s!=null?nn(rn(s)):{},Ze(e||!s||!s.__esModule?pe(t,"default",{value:s,enumerable:!0}):t,s)),cn=s=>Ze(pe({},"__esModule",{value:!0}),s);var $e=x((ms,et)=>{"use strict";var gn=typeof process=="object"&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...s)=>console.error("SEMVER",...s):()=>{};et.exports=gn});var xe=x((hs,tt)=>{"use strict";var dn="2.0.0",pn=Number.MAX_SAFE_INTEGER||9007199254740991,mn=16,hn=250,fn=["major","premajor","minor","preminor","patch","prepatch","prerelease"];tt.exports={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:mn,MAX_SAFE_BUILD_LENGTH:hn,MAX_SAFE_INTEGER:pn,RELEASE_TYPES:fn,SEMVER_SPEC_VERSION:dn,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}});var Be=x((F,nt)=>{"use strict";var{MAX_SAFE_COMPONENT_LENGTH:Oe,MAX_SAFE_BUILD_LENGTH:bn,MAX_LENGTH:wn}=xe(),Tn=$e();F=nt.exports={};var En=F.re=[],yn=F.safeRe=[],h=F.src=[],vn=F.safeSrc=[],f=F.t={},Pn=0,Fe="[a-zA-Z0-9-]",Rn=[["\\s",1],["\\d",wn],[Fe,bn]],In=s=>{for(let[e,t]of Rn)s=s.split(`${e}*`).join(`${e}{0,${t}}`).split(`${e}+`).join(`${e}{1,${t}}`);return s},y=(s,e,t)=>{let n=In(e),i=Pn++;Tn(s,i,e),f[s]=i,h[i]=e,vn[i]=n,En[i]=new RegExp(e,t?"g":void 0),yn[i]=new RegExp(n,t?"g":void 0)};y("NUMERICIDENTIFIER","0|[1-9]\\d*");y("NUMERICIDENTIFIERLOOSE","\\d+");y("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${Fe}*`);y("MAINVERSION",`(${h[f.NUMERICIDENTIFIER]})\\.(${h[f.NUMERICIDENTIFIER]})\\.(${h[f.NUMERICIDENTIFIER]})`);y("MAINVERSIONLOOSE",`(${h[f.NUMERICIDENTIFIERLOOSE]})\\.(${h[f.NUMERICIDENTIFIERLOOSE]})\\.(${h[f.NUMERICIDENTIFIERLOOSE]})`);y("PRERELEASEIDENTIFIER",`(?:${h[f.NONNUMERICIDENTIFIER]}|${h[f.NUMERICIDENTIFIER]})`);y("PRERELEASEIDENTIFIERLOOSE",`(?:${h[f.NONNUMERICIDENTIFIER]}|${h[f.NUMERICIDENTIFIERLOOSE]})`);y("PRERELEASE",`(?:-(${h[f.PRERELEASEIDENTIFIER]}(?:\\.${h[f.PRERELEASEIDENTIFIER]})*))`);y("PRERELEASELOOSE",`(?:-?(${h[f.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${h[f.PRERELEASEIDENTIFIERLOOSE]})*))`);y("BUILDIDENTIFIER",`${Fe}+`);y("BUILD",`(?:\\+(${h[f.BUILDIDENTIFIER]}(?:\\.${h[f.BUILDIDENTIFIER]})*))`);y("FULLPLAIN",`v?${h[f.MAINVERSION]}${h[f.PRERELEASE]}?${h[f.BUILD]}?`);y("FULL",`^${h[f.FULLPLAIN]}$`);y("LOOSEPLAIN",`[v=\\s]*${h[f.MAINVERSIONLOOSE]}${h[f.PRERELEASELOOSE]}?${h[f.BUILD]}?`);y("LOOSE",`^${h[f.LOOSEPLAIN]}$`);y("GTLT","((?:<|>)?=?)");y("XRANGEIDENTIFIERLOOSE",`${h[f.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);y("XRANGEIDENTIFIER",`${h[f.NUMERICIDENTIFIER]}|x|X|\\*`);y("XRANGEPLAIN",`[v=\\s]*(${h[f.XRANGEIDENTIFIER]})(?:\\.(${h[f.XRANGEIDENTIFIER]})(?:\\.(${h[f.XRANGEIDENTIFIER]})(?:${h[f.PRERELEASE]})?${h[f.BUILD]}?)?)?`);y("XRANGEPLAINLOOSE",`[v=\\s]*(${h[f.XRANGEIDENTIFIERLOOSE]})(?:\\.(${h[f.XRANGEIDENTIFIERLOOSE]})(?:\\.(${h[f.XRANGEIDENTIFIERLOOSE]})(?:${h[f.PRERELEASELOOSE]})?${h[f.BUILD]}?)?)?`);y("XRANGE",`^${h[f.GTLT]}\\s*${h[f.XRANGEPLAIN]}$`);y("XRANGELOOSE",`^${h[f.GTLT]}\\s*${h[f.XRANGEPLAINLOOSE]}$`);y("COERCEPLAIN",`(^|[^\\d])(\\d{1,${Oe}})(?:\\.(\\d{1,${Oe}}))?(?:\\.(\\d{1,${Oe}}))?`);y("COERCE",`${h[f.COERCEPLAIN]}(?:$|[^\\d])`);y("COERCEFULL",h[f.COERCEPLAIN]+`(?:${h[f.PRERELEASE]})?(?:${h[f.BUILD]})?(?:$|[^\\d])`);y("COERCERTL",h[f.COERCE],!0);y("COERCERTLFULL",h[f.COERCEFULL],!0);y("LONETILDE","(?:~>?)");y("TILDETRIM",`(\\s*)${h[f.LONETILDE]}\\s+`,!0);F.tildeTrimReplace="$1~";y("TILDE",`^${h[f.LONETILDE]}${h[f.XRANGEPLAIN]}$`);y("TILDELOOSE",`^${h[f.LONETILDE]}${h[f.XRANGEPLAINLOOSE]}$`);y("LONECARET","(?:\\^)");y("CARETTRIM",`(\\s*)${h[f.LONECARET]}\\s+`,!0);F.caretTrimReplace="$1^";y("CARET",`^${h[f.LONECARET]}${h[f.XRANGEPLAIN]}$`);y("CARETLOOSE",`^${h[f.LONECARET]}${h[f.XRANGEPLAINL
|
||
|
|
GitHub API rate limit exceeded:`,`
|
||
|
|
Request: ${u.requestUrl}`,`
|
||
|
|
Rate limits - Remaining: ${u.remaining}`,`
|
||
|
|
Reset in: ${u.getMinutesToReset()} minutes`),u}throw e&&console.log("GitHub request failed:",o),a}};var je={pluginList:[],pluginSubListFrozenVersion:[],themesList:[],updateAtStartup:!0,updateThemesAtStartup:!0,enableAfterInstall:!0,loggingEnabled:!1,loggingPath:"BRAT-log",loggingVerboseEnabled:!1,debuggingMode:!1,notificationsEnabled:!0,globalTokenName:"",personalAccessToken:"",selectLatestPluginVersionByDefault:!1,allowIncompatiblePlugins:!1};function Nt(s,e,t="latest",n=!1,i=""){let o=!1;s.settings.pluginList.contains(e)||(s.settings.pluginList.unshift(e),o=!0);let a=s.settings.pluginSubListFrozenVersion.find(c=>c.repo===e);a?(Object.assign(a,{repo:e,version:t,token:void 0,tokenName:i||a.tokenName,isIncompatible:n||void 0}),o=!0):(s.settings.pluginSubListFrozenVersion.unshift({repo:e,version:t,token:void 0,tokenName:i||void 0,isIncompatible:n||void 0}),o=!0),o&&s.saveSettings()}function Pe(s,e){return s.settings.pluginList.contains(e)}function At(s,e,t){let n={repo:e,lastUpdate:Z(t)};s.settings.themesList.unshift(n),s.saveSettings()}function Ct(s,e){return!!s.settings.themesList.find(n=>n.repo===e)}function ze(s,e,t){let n=s.settings.pluginSubListFrozenVersion.find(i=>i.repo===e);n&&(n.tokenName=t||void 0,s.saveSettings())}function Lt(s,e,t){for(let n of s.settings.themesList)n.repo===e&&(n.lastUpdate=t,s.saveSettings())}var L=require("obsidian");var j=class{constructor(e){this.statusEl=e}async validateToken(e,t){var n,i,o,a,c,u,g,m,l;if(!e)return(n=this.statusEl)==null||n.setText("No token provided"),(i=this.statusEl)==null||i.addClass("invalid"),(o=this.statusEl)==null||o.removeClass("valid"),!1;try{let r=await Et(e,t);return(a=this.statusEl)==null||a.removeClass("invalid","valid"),(c=this.statusEl)==null||c.empty(),r.validToken?((u=this.statusEl)==null||u.addClass("valid"),this.showValidTokenInfo(r),!0):((g=this.statusEl)==null||g.addClass("invalid"),this.showErrorMessage(r.error),!1)}catch(r){return console.error("Token validation error:",r),(m=this.statusEl)==null||m.setText("Failed to validate token"),(l=this.statusEl)==null||l.addClass("invalid"),!1}}showValidTokenInfo(e){var n,i;let t=(n=this.statusEl)==null?void 0:n.createDiv({cls:"brat-token-details"});if(t&&(t.createDiv({text:"\u2713 Valid token",cls:"brat-token-status valid"}),(i=e.currentScopes)!=null&&i.length&&t.createDiv({text:`Scopes: ${e.currentScopes.join(", ")}`,cls:"brat-token-scopes"}),e.rateLimit&&t.createDiv({text:`Rate Limit: ${e.rateLimit.remaining}/${e.rateLimit.limit}`,cls:"brat-token-rate"}),e.expirationDate)){let o=new Date(e.expirationDate),a=Math.ceil((o.getTime()-Date.now())/(1e3*60*60*24));a<7&&t.createDiv({text:`\u26A0\uFE0F Token expires in ${a} days`,cls:"brat-token-warning"})}}showErrorMessage(e){var n,i,o;let t=(n=this.statusEl)==null?void 0:n.createDiv({cls:"brat-token-error"});if(t&&(t.createDiv({text:e.message}),e.details))switch(e.type){case"invalid_prefix":t.createDiv({text:`Valid prefixes: ${(i=e.details.validPrefixes)==null?void 0:i.join(", ")}`});break;case"insufficient_scope":t.createDiv({text:`Required scopes: ${(o=e.details.requiredScopes)==null?void 0:o.join(", ")}`});break}}};function te(s,e){let t=new DocumentFragment,n=document.createElement("a");if(n.textContent=s,n.href=`https://github.com/${s}`,n.target="_blank",t.appendChild(n),e){let i=document.createTextNode(e);t.appendChild(i)}return t}function kt({prependText:s,url:e,text:t,appendText:n}){let i=new DocumentFragment,o=document.createElement("a");if(o.textContent=t,o.href=e,s){let a=document.createTextNode(s);i.appendChild(a)}if(i.appendChild(o),n){let a=document.createTextNode(n);i.appendChild(a)}return i}var Re=require("obsidian");function E(s,e,t=10,n){if(!s.settings.notificationsEnabled)return;let i=n?Re.Platform.isDesktop?"(click=dismiss, right-click=Info)":"(click=dismiss)":"",o=new Re.Notice(`BRAT
|
||
|
|
${e}
|
||
|
|
${i}`,t*1e3);n&&(o.noticeEl.oncontextmenu=()=>{n()})}var z=(s,e=!0)=>{let t=s.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");let n=t.createDiv("coffee");n.addClass("ex-twitter-span"),n.style.paddingLeft="10px";let i=n.createDiv();i.innerText="Learn more about my work at:",n.appendChild(i);let o=n.createEl("a",{href:"https://tfthacker.com"});return o.innerText="https://tfthacker.com",t};var St=require("obsidian"),Ie=class extends St.SuggestModal{constructor(e,t,n,i,o){super(e),this.versions=n,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){let t=e.toLowerCase();return this.versions.filter(n=>n.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()}};var U=class extends L.Modal{constructor(t,n,i=!1,o=!1,a="",c="",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=n,this.address=a,this.version=c,this.secretName=u,this.openSettingsTabAfterwards=i,this.updateVersion=o,this.enableAfterInstall=t.settings.enableAfterInstall}async submitForm(){var o,a,c,u,g,m,l,r;if(this.address==="")return;let t=ye(this.address);if(this.plugin.settings.pluginSubListFrozenVersion.find(d=>d.repo===t)){await this.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!0,this.enableAfterInstall,this.secretName)&&this.close(),(o=this.cancelButton)==null||o.setDisabled(!1),(a=this.addPluginButton)==null||a.setDisabled(!1),(c=this.addPluginButton)==null||c.setButtonText("Add Plugin"),(u=this.versionSetting)==null||u.setDisabled(!1);return}if(!this.version&&Pe(this.plugin,t)){E(this.plugin,"This plugin is already in the list for beta testing",10);return}await this.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!1,this.enableAfterInstall,this.secretName)&&this.close(),(g=this.cancelButton)==null||g.setDisabled(!1),(m=this.addPluginButton)==null||m.setDisabled(!1),(l=this.addPluginButton)==null||l.setButtonText("Add Plugin"),(r=this.versionSetting)==null||r.setDisabled(!1)}updateVersionDropdown(t,n,i=""){let o;t.clear(),n.length>0&&!i&&this.plugin.settings.selectLatestPluginVersionByDefault?(o="latest",this.version="latest"):o=i,n.length<20||L.Platform.isMobile?t.addDropdown(c=>{c.addOption("","Select a version"),c.addOption("latest","Latest version");for(let u of n)c.addOption(u.version,`${u.version} ${u.prerelease?"(Prerelease)":""}`);c.onChange(u=>{var g;this.version=u,(g=this.addPluginButton)==null||g.setDisabled(this.version==="")}),c.setValue(o),c.selectEl.addClass("brat-version-selector"),c.selectEl.style.width="100%"}):t.addButton(c=>{c.setButtonText(o==="latest"?"Latest version":o||"Select a version...").setClass("brat-version-selector").setClass("button").onClick(()=>{let g=[{version:"latest",prerelease:!1},...n];new Ie(this.app,this.address,g,o,l=>{var r;this.version=l,c.setButtonText(l==="latest"?"Latest version":l||"Select a version..."),(r=this.addPluginButton)==null||r.setDisabled(this.version==="")}).open()})})}onOpen(){let t=this.contentEl.createEl("h4");this.address?(t.appendText("Change plugin version: "),t.appendChild(te(this.address))):t.setText("Github repository for beta plugin:"),this.contentEl.createEl("form",{},n=>{var g;n.addClass("brat-modal"),(!this.address||!this.updateVersion)&&new L.Setting(n).setClass("repository-setting").then(l=>{l.addText(r=>{this.repositoryAddressEl=r,r.setPlaceholder("Repository (example: https://github.com/GitHubUserN
|
||
|
|
This does not seem to be an obsidian plugin with valid releases, as there are no releases available.`,15),console.error("BRAT: validateRepository",e,t,n)),null;let m=await Q(g,"manifest.json",this.plugin.settings.debuggingMode,u,c);if(!m)return n&&(E(this.plugin,`${e}
|
||
|
|
This does not seem to be an obsidian plugin, as there is no manifest.json file.`,15),console.error("BRAT: validateRepository",e,t,n)),null;let l=JSON.parse(m);if(!("id"in l))return n&&E(this.plugin,`${e}
|
||
|
|
The plugin id attribute for the release is missing from the manifest file`,15),null;if(!("version"in l))return n&&E(this.plugin,`${e}
|
||
|
|
The version attribute for the release is missing from the manifest file`,15),null;try{let r=Ae(g.tag_name,{includePrerelease:!0,loose:!0}),d=Ae(l.version,{includePrerelease:!0,loose:!0});$t(r,d)!==0&&(n&&E(this.plugin,`${e}
|
||
|
|
Version mismatch detected:
|
||
|
|
Release tag version: ${g.tag_name}
|
||
|
|
Manifest version: ${l.version}
|
||
|
|
|
||
|
|
The release tag version will be used to ensure consistency.`,15),l.version=r.version)}catch(r){}return l}catch(u){if(u instanceof D){let g=`GitHub API rate limit exceeded. Reset in ${u.getMinutesToReset()} minutes.`;throw n&&E(this.plugin,g,15),console.error(`BRAT: validateRepository ${u}`),E(this.plugin,`${u.message} Consider adding a personal access token in BRAT settings for higher limits. See documentation for details.`,20,()=>{window.open("https://github.com/TfTHacker/obsidian42-brat/blob/main/BRAT-DEVELOPER-GUIDE.md#github-api-rate-limits")}),u}if(u instanceof O)throw n&&(u.status===401?E(this.plugin,`${e}
|
||
|
|
GitHub API Authentication error. Please verify that your personal access token is valid and set correctly.`,15):E(this.plugin,`${e}
|
||
|
|
GitHub API error ${u.status}: ${u.message}`,15)),console.error(`BRAT: validateRepository ${u}`),u;return n&&E(this.plugin,`${e}
|
||
|
|
Unspecified error encountered: ${u}, verify debug for more information.`,15),null}}async getAllReleaseFiles(e,t,n="",i=""){let o=i,a=await He(e,this.plugin.settings.debuggingMode,o),c=await Ge(e,n,t,this.plugin.settings.debuggingMode,a,o);if(!c)return Promise.reject("No release found");let u=t||n!=="";return console.log({reallyGetManifestOrNot:u,version:c.tag_name}),{mainJs:await Q(c,"main.js",this.plugin.settings.debuggingMode,a,o),manifest:u?await Q(c,"manifest.json",this.plugin.settings.debuggingMode,a,o):"",styles:await Q(c,"styles.css",this.plugin.settings.debuggingMode,a,o)}}async writeReleaseFilesToPluginFolder(e,t){var o,a;let n=`${(0,k.normalizePath)(`${this.plugin.app.vault.configDir}/plugins/${e}`)}/`,{adapter:i}=this.plugin.app.vault;await i.exists(n)||await i.mkdir(n),await i.write(`${n}main.js`,(o=t.mainJs)!=null?o:""),await i.write(`${n}manifest.json`,(a=t.manifest)!=null?a:""),t.styles&&await i.write(`${n}styles.css`,t.styles)}async addPlugin(e,t=!1,n=!1,i=!1,o="",a=!1,c=this.plugin.settings.enableAfterInstall,u=""){try{this.plugin.settings.debuggingMode&&console.log("BRAT: addPlugin",e,t,n,i,o,a,c,u?"with secret":"public");let g="";u&&u.trim()!==""?(g=await this.plugin.app.secretStorage.getSecret(u)||"",g||E(this.plugin,`Secret not found for token name: ${u}. Please add it to SecretStorage or clear the token name for this plugin.`,10)):this.plugin.settings.globalTokenName&&(g=await this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName)||"");let m=10,l=await this.validateRepository(e,!0,!0,o,g),r=!!l;if(r||(l=await this.validateRepository(e,!1,!0,o,g)),l===null){let w=`${e}
|
||
|
|
A manifest.json file does not exist in the latest release of the repository. This plugin cannot be installed.`;return await this.plugin.log(w,!0),E(this.plugin,w,m),!1}if(!Object.hasOwn(l,"version")){let w=`${e}
|
||
|
|
The manifest.json file in the latest release or pre-release of the repository does not have a version number in the file. This plugin cannot be installed.`;return await this.plugin.log(w,!0),E(this.plugin,w,m),!1}let d=!1;if(Object.hasOwn(l,"minAppVersion")&&!(0,k.requireApiVersion)(l.minAppVersion)){if(o===""||o==="latest"||!this.plugin.settings.allowIncompatiblePlugins){let p=`Plugin: ${e}
|
||
|
|
|
||
|
|
The manifest.json for this plugin indicates that the Obsidian version of the app needs to be ${l.minAppVersion}, but this installation of Obsidian is ${k.apiVersion}.
|
||
|
|
|
||
|
|
You will need to update your Obsidian to use this plugin or contact the plugin developer for more information.`;return await this.plugin.log(p,!0),E(this.plugin,p,30),!1}if(!await De({app:this.plugin.app,message:createFragment(p=>{p.appendText("Plugin: "),p.createEl("code",{text:e}),p.createEl("br"),p.appendText("The "),p.createEl("code",{text:"manifest.json"}),p.appendText(" for this plugin indicates that the Obsidian version of the app needs to be "),p.createEl("code",{text:l.minAppVersion}),p.appendText(", but this installation of Obsidian is "),p.createEl("code",{text:k.apiVersion}),p.appendText("."),p.createEl("br"),p.appendText("Using this plugin is not recommended and may not work as expected. Use at your own risk."),p.createEl("br"),p.appendText("Do you want to install it anyways?")})}))return!1;d=!0}let b=async()=>{var T,C;let w=await this.getAllReleaseFiles(e,r,o,g);console.log("rFiles",w),(r||w.manifest==="")&&(w.manifest=JSON.stringify(l));let p=JSON.parse((T=w.manifest)!=null?T:"");if(d&&(p.brat={isIncompatible:!0,minAppVersionOriginal:p.minAppVersion},p.minAppVersion=k.apiVersion),k.Platform.isMobile&&p.isDesktopOnly)if(this.plugin.settings.allowIncompatiblePlugins){if(!await De({app:this.plugin.app,message:createFragment(R=>{R.appendText("Plugin: "),R.createEl("code",{text:e}),R.createEl("br"),R.appendText("The "),R.createEl("code",{text:"manifest.json"}),R.appendText(" for this plugin indicates that the plugin has "),R.createEl("code",{text:"isDesktopOnly: true"}),R.appendText(", but you are using a mobile device."),R.createEl("br"),R.appendText("Using this plugin is not recommended and may not work as expected. Use at your own risk."),R.createEl("br"),R.appendText("Do you want to forcefully run it on mobile anyways?")})}))return null;p.isDesktopOnly=!1,(C=p.brat)!=null||(p.brat={}),p.brat.isDesktopOnlyOriginal=!0,p.brat.isIncompatible=!0,d=!0}else{let N=`Plugin: ${e}
|
||
|
|
|
||
|
|
The manifest.json for this plugin indicates that the plugin has isDesktopOnly: true, but you are using a mobile device.
|
||
|
|
|
||
|
|
The plugin will not be installed.`;return await this.plugin.log(N,!0),E(this.plugin,N,30),null}if(d&&(w.manifest=JSON.stringify(p)),this.plugin.settings.debuggingMode&&console.log("BRAT: rFiles.manifest",r,w),w.mainJs===null){let N=`${e}
|
||
|
|
The release is not complete and cannot be downloaded. main.js is missing from the Release`;return await this.plugin.log(N,!0),E(this.plugin,N,m),null}return w};if(!t||a){let w=await b();if(w===null)return!1;if(await this.writeReleaseFilesToPluginFolder(l.id,w),Nt(this.plugin,e,o,d,u),c){let{plugins:p}=this.plugin.app,T=(0,k.normalizePath)(`${p.getPluginFolder()}/${l.id}`);await p.loadManifest(T),await p.enablePluginAndSave(l.id)}if(await this.plugin.app.plugins.loadManifests(),a)await this.reloadPlugin(l.id),await this.plugin.log(`${e} reinstalled`,!0),E(this.plugin,`${e}
|
||
|
|
Plugin has been reinstalled and reloaded with version ${l.version}`,m);else{let p=o===""?"":` (version: ${o})`,T=`${e}${p}
|
||
|
|
The plugin has been registered with BRAT.`;c||(T+=" You may still need to enable it the Community Plugin List."),await this.plugin.log(T,!0),E(this.plugin,T,m)}}else{let w=`${this.plugin.app.vault.configDir}/plugins/${l.id}/`,p="";try{p=await this.plugin.app.vault.adapter.read(`${w}manifest.json`)}catch(R){if(R.errno===-4058||R.errno===-2)return await this.addPlugin(e,!1,r,!1,o,!1,c,u),!0;console.log("BRAT - Local Manifest Load",l.id,JSON.stringify(R,null,2))}if(o!==""&&o!=="latest")return E(this.plugin,`The version of ${e} is frozen, not updating.`,3),!1;let T=await JSON.parse(p),C=Ae(T.version,{includePrerelease:!0,loose:!0}),N=Ae(l.version,{includePrerelease:!0,loose:!0});if($t(C,N)===-1){let R=await b();if(R===null)return!1;if(n){let J=`There is an update available for ${l.id} from version ${T.version} to ${l.version}. `;return await this.plugin.log(`${J}[Release Info](https://github.com/${e}/releases/tag/${l.version})`,!0),E(this.plugin,J,30,()=>{l&&window.open(`https://github.com/${e}/releases/tag/${l.version}`)}),!1}await this.writeReleaseFilesToPluginFolder(l.id,R),await this.plugin.app.plugins.loadManifests(),await this.reloadPlugin(l.id);let P=`${l.id}
|
||
|
|
Plugin has been updated from version ${T.version} to ${l.version}. `;return await this.plugin.log(`${P}[Release Info](https://github.com/${e}/releases/tag/${l.version})`,!0),E(this.plugin,P,30,()=>{l&&window.open(`https://github.com/${e}/releases/tag/${l.version}`)}),!0}return i&&E(this.plugin,`No update available for ${e}`,3),!0}}catch(g){console.error(`BRAT: Error adding plugin ${e}:`,{error:g,updatePluginFiles:t,seeIfUpdatedOnly:n,specifyVersion:o,forceReinstall:a});let m=g instanceof Error?g.message:"Unknown error occurred";return await this.plugin.log(`Error ${t?"updating":"adding"} plugin ${e}: ${m}`,!0),!1}return!0}async reloadPlugin(e){let{plugins:t}=this.plugin.app;try{await t.disablePlugin(e),await t.enablePlugin(e)}catch(n){this.plugin.settings.debuggingMode&&console.log("reload plugin",n)}}async updatePlugin(e,t=!1,n=!1,i=!1,o=""){let a=await this.addPlugin(e,!0,t,n,"",i,!1,o);return!a&&!t&&E(this.plugin,`${e}
|
||
|
|
Update of plugin failed.`),a}async checkForPluginUpdatesAndInstallUpdates(e=!1,t=!1){if(!await Ne()){console.log("BRAT: No internet detected.");return}let n,i="Checking for plugin updates STARTED";await this.plugin.log(i,!0),e&&this.plugin.settings.notificationsEnabled&&(n=new k.Notice(`BRAT
|
||
|
|
${i}`,3e4));let o=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(u=>[u.repo,u.version])),a=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(u=>[u.repo,u.tokenName||""]));for(let u of this.plugin.settings.pluginList){let g=o.get(u);g&&g!=="latest"||await this.updatePlugin(u,t,!1,!1,a.get(u)||"")}let c="Checking for plugin updates COMPLETED";await this.plugin.log(c,!0),e&&(n&&n.hide(),E(this.plugin,c,10))}deletePlugin(e){let t=`Removed ${e} from BRAT plugin list`;this.plugin.log(t,!0),this.plugin.settings.pluginList=this.plugin.settings.pluginList.filter(n=>n!==e),this.plugin.settings.pluginSubListFrozenVersion=this.plugin.settings.pluginSubListFrozenVersion.filter(n=>n.repo!==e),this.plugin.saveSettings()}getEnabledDisabledPlugins(e){let t=this.plugin.app.plugins,n=Object.values(t.manifests),i=Object.values(t.plugins).map(o=>o.manifest);return e?n.filter(o=>i.find(a=>o.id===a.id)):n.filter(o=>!i.find(a=>o.id===a.id))}checkIncompatiblePlugins(){let e=this.plugin.settings.pluginSubListFrozenVersion.filter(t=>t.isIncompatible).map(t=>t.repo);e.length>0&&E(this.plugin,`The following incompatible plugins were forcefully installed by BRAT and may not work as expected:
|
||
|
|
${e.join(`
|
||
|
|
`)}`,30)}};var _=require("obsidian");var se=async(s,e,t)=>{let n=await G(e,!0,s.settings.debuggingMode);if(n||(n=await G(e,!1,s.settings.debuggingMode)),!n)return E(s,"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 Rt(e,s.settings.debuggingMode);if(!i)return E(s,"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),a=(0,_.normalizePath)(Un(s)+o.name),{adapter:c}=s.app.vault;await c.exists(a)||await c.mkdir(a),await c.write((0,_.normalizePath)(`${a}/theme.css`),n),await c.write((0,_.normalizePath)(`${a}/manifest.json`),i),Lt(s,e,Z(n));let u="";return t?(At(s,e,n),u=`${o.name} theme installed from ${e}. `,setTimeout(()=>{s.app.customCss.setTheme(o.name)},500)):u=`${o.name} theme updated from ${e}.`,s.log(`${u}[Theme Info](https://github.com/${e})`,!1),E(s,u,20,()=>{window.open(`https://github.com/${e}`)}),!0},q=async(s,e)=>{if(!await Ne()){console.log("BRAT: No internet detected.");return}let t,n="Checking for beta theme updates STARTED";await s.log(n,!0),e&&s.settings.notificationsEnabled&&(t=new _.Notice(`BRAT
|
||
|
|
${n}`,3e4));for(let o of s.settings.themesList){let a=await ee(o.repo,!0,s.settings.debuggingMode);a==="0"&&(a=await ee(o.repo,!1,s.settings.debuggingMode)),console.log("BRAT: lastUpdateOnline",a),a!==o.lastUpdate&&await se(s,o.repo,!1)}let i="Checking for beta theme updates COMPLETED";(async()=>await s.log(i,!0))(),e&&(s.settings.notificationsEnabled&&t&&t.hide(),E(s,i))},Ce=(s,e)=>{s.settings.themesList=s.settings.themesList.filter(n=>n.repo!==e),s.saveSettings();let t=`Removed ${e} from BRAT themes list and will no longer be updated. However, the theme files still exist in the vault. To remove them, go into Settings > Appearance and remove the theme.`;s.log(t,!0),E(s,t)},Un=s=>`${(0,_.normalizePath)(`${s.app.vault.configDir}/themes`)}/`;var xt="brat-migrations";async function _n(s,e){try{let t=await s.vault.adapter.read(`${s.vault.configDir}/plugins/obsidian42-brat/${xt}.json`);return JSON.parse(t).appliedMigrations.includes(e)}catch(t){return!1}}async function Hn(s,e){try{let t=`${s.vault.configDir}/plugins/obsidian42-brat/${xt}.json`,n={appliedMigrations:[]};try{let i=await s.vault.adapter.read(t);n=JSON.parse(i)}catch(i){}n.appliedMigrations.includes(e)||(n.appliedMigrations.push(e),await s.vault.adapter.write(t,JSON.stringify(n,null,2)))}catch(t){console.error(`BRAT: Failed to mark migration ${e} complete:`,t)}}async function Ot(s,e,t){let n="tokens-to-secretstorage-v1";if(!await _n(s,n))try{let i=0,o=u=>{let m=`brat-gh-${u.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}`;return m.length>64?m.substring(0,64).replace(/-$/,""):m},a=u=>{let g=s.secretStorage.listSecrets();for(let m of g)if(s.secretStorage.getSecret(m)===u)return m;return null},c=(u,g)=>{let m=a(u);return m?(console.log(`BRAT: Reusing existing secret "${m}"`),m):(s.secretStorage.setSecret(g,u),console.log(`BRAT: Created new secret "${g}"`),g)};if(e.personalAccessToken&&e.personalAccessToken.trim()!==""){let u=e.personalAccessToken.trim(),m=c(u,"brat-gh-global");e.globalTokenName=m,e.personalAccessToken="",i++}if(e.pluginSubListFrozenVersion){for(let u of e.pluginSubListFrozenVersion)if(u.token&&u.token.trim()!==""){let g=u.token.trim(),m=o(u.repo),l=c(g,m);u.tokenName=l,u.token=void 0,i++}}i>0&&(await t(),console.log(`BRAT: Migrated ${i} token(s) to SecretStorage`)),await Hn(s,n)}catch(i){console.error("BRAT: Failed to migrate tokens to SecretStorage:",i)}}var H=require("obsidian");var B=class extends H.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(Ct(this.plugin,e)){E(this.plugin,"This theme is already in the list for beta testing",10);return}await se(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 H.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 H.ButtonComponent(i).setButtonText("Never mind").onClick(()=>{this.close()}),new H.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 n=t.createSpan();n.createEl("a",{href:"https://bit.ly/o42-twitter",text:"TFTHacker"}),n.appendText(" and "),n.createEl("a",{href:"https://github.com/johannrichard",text:"johannrichard"}),n.style.fontStyle="italic",t.appendChild(n),z(t,!1),window.setTimeout(()=>{let i=e.querySelectorAll(".brat-modal .setting-item-info");for(let o of
|
||
|
|
${o}`,3),this.plugin.betaPlugins.updatePlugin(i.info,!1,!0,!1,a==null?void 0:a.token)})}},{id:"reinstallOnePlugin",icon:"BratIcon",name:"Plugins: Choose a single plugin to reinstall",showInRibbon:!0,callback:()=>{let e=new Set(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})),n=new S(this.plugin);n.setSuggesterData(t),n.display(i=>{let o=`Reinstalling ${i.info}`;E(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:()=>{let e=Object.values(this.plugin.app.plugins.manifests).map(n=>({display:n.id,info:n.id})),t=new S(this.plugin);t.setSuggesterData(e),t.display(n=>{E(this.plugin,`${n.info}
|
||
|
|
Plugin reloading .....`,5),this.plugin.betaPlugins.reloadPlugin(n.info)})}},{id:"disablePlugin",icon:"BratIcon",name:"Plugins: Disable a plugin - toggle it off",showInRibbon:!0,callback:()=>{let e=this.plugin.betaPlugins.getEnabledDisabledPlugins(!0).map(n=>({display:`${n.name} (${n.id})`,info:n.id})),t=new S(this.plugin);t.setSuggesterData(e),t.display(n=>{this.plugin.log(`${n.display} plugin disabled`,!1),this.plugin.settings.debuggingMode&&console.log(n.info),this.plugin.app.plugins.disablePluginAndSave(n.info)})}},{id:"enablePlugin",icon:"BratIcon",name:"Plugins: Enable a plugin - toggle it on",showInRibbon:!0,callback:()=>{let e=this.plugin.betaPlugins.getEnabledDisabledPlugins(!1).map(n=>({display:`${n.name} (${n.id})`,info:n.id})),t=new S(this.plugin);t.setSuggesterData(e),t.display(n=>{this.plugin.log(`${n.display} plugin enabled`,!1),this.plugin.app.plugins.enablePluginAndSave(n.info)})}},{id:"openGitHubZRepository",icon:"BratIcon",name:"Plugins: Open the GitHub repository for a plugin",showInRibbon:!0,callback:async()=>{let e=await vt(this.plugin.settings.debuggingMode);if(e){let t=Object.values(e).map(o=>({display:`Plugin: ${o.name} (${o.repo})`,info:o.repo})),n=Object.values(this.plugin.settings.pluginList).map(o=>({display:`BRAT: ${o}`,info:o}));for(let o of t)n.push(o);let i=new S(this.plugin);i.setSuggesterData(n),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()=>{let e=await Pt(this.plugin.settings.debuggingMode);if(e){let t=Object.values(e).map(i=>({display:`Theme: ${i.name} (${i.repo})`,info:i.repo})),n=new S(this.plugin);n.setSuggesterData(t),n.display(i=>{i.info&&window.open(`https://github.com/${i.info}`)})}}},{id:"opentPluginSettings",icon:"BratIcon",name:"Plugins: Open Plugin Settings Tab",showInRibbon:!0,callback:()=>{let e=this.plugin.app.setting,t=Object.values(e.pluginTabs).map(o=>({display:`Plugin: ${o.name}`,info:o.id})),n=new S(this.plugin),i=Object.values(e.settingTabs).map(o=>({display:`Core: ${o.name}`,info:o.id}));for(let o of t)i.push(o);n.setSuggesterData(i),n.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:()=>{new B(this.plugin).open()}},{id:"updateBetaThemes",icon:"BratIcon",name:"Themes: Update beta themes",showInRibbon:!0,callback:async()=>{await q(this.plugin,!0)}},{id:"allCommands",icon:"BratIcon",name:"All Commands list",showInRibbon:!1,callback:()=>{this.ribbonDisplayCommands()}}];this.plugin=e;for(let t of this.bratCommands)this.plugin.addCommand({id:t.id,name:t.name,icon:t.icon,callback:()=>{t.callback()}})}ribbonDisplayCommands(){let e=[];for(let a of this.bratCommands)a.showInRibbon&&e.push({display:a.name,info:a.callback});let t=new S(this.plugin),n=this.plugin.app.setting,i=Object.values(n.settingTabs).map(a=>({display:`Core: ${a.name}`,info:()=>{n.open(),n.openTabById(a.id)}})),o=Object.values(n.pluginTabs).map(a=>({display:`Plugin: ${a.name}`,info:()=>{n.open(),n.openTabById(a.id)}}));e.push({display:"---- Core Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let a of i)e.push(a);e.push({display:"---- Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let a of o)e.push(a);t.setSuggesterData(e),t.display(a=>{typeof a.info=="function"&&a.info()})}};var A=require("obsidian");var Le=class extends A.PluginSettingTab{constructor(t,n){super(t,n);this.accessTokenSetting=null;this.accessTokenButton=null;this.tokenInfo=null;this.validator=null;this.plugin=n}display(){let{containerEl:t}=this;t.empty(),t.addClass("brat-settings"),new A.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(l=>{l.setValue(this.plugin.settings.enableAfterInstall).onChange(async r=>{this
|
||
|
|
`," ")}
|
||
|
|
`,u=s.app.vault.getAbstractFileByPath(n);u?await s.app.vault.append(u,c):u=await s.app.vault.create(n,c)}}var ke=class extends tn.Plugin{constructor(){super(...arguments);this.APP_NAME="BRAT";this.APP_ID="obsidian42-brat";this.settings=je;this.betaPlugins=new ne(this);this.commands=new ie(this);this.bratApi=new oe(this);this.obsidianProtocolHandler=t=>{if(!t.plugin&&!t.theme){E(this,"Could not locate the repository from the URL.",10);return}for(let n of["plugin","theme"])if(t[n]){let i;switch(n){case"plugin":i=new U(this,this.betaPlugins,!0,!1,t[n],t.version?t.version:void 0),i.open();break;case"theme":i=new B(this),i.address=t[n],i.open();break}return}}}onload(){console.log(`loading ${this.APP_NAME}`),Bt(),this.addRibbonIcon("BratIcon","BRAT",()=>{this.commands.ribbonDisplayCommands()}),this.loadSettings().then(async()=>{await Ot(this.app,this.settings,()=>this.saveSettings()),this.app.workspace.onLayoutReady(()=>{this.addSettingTab(new Le(this.app,this)),this.registerObsidianProtocolHandler("brat",this.obsidianProtocolHandler),this.betaPlugins.checkIncompatiblePlugins(),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)})}async log(t,n=!1){await en(this,t,n)}onunload(){console.log(`unloading ${this.APP_NAME}`)}async loadSettings(){this.settings=Object.assign({},je,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};
|
||
|
|
|
||
|
|
/* nosourcemap */
|