add exmcmds to load RC file from url

This commit is contained in:
rektrex 2019-09-19 22:14:51 +05:30
parent c8b0f18cb3
commit 8f0b2a5ab8
2 changed files with 39 additions and 0 deletions

View file

@ -13,6 +13,25 @@ export async function source(filename = "auto") {
return true
}
async function fetchConfig(url: string) {
const response = await fetch(url)
const reader = response.body.getReader()
let rctext = ""
const decoder = new TextDecoder("utf-8")
while (true) {
const { value: chunk, done: isDone } = await reader.read()
if (isDone) return rctext
rctext += decoder.decode(chunk)
}
}
export async function sourceFromUrl(url: string) {
const rctext = await fetchConfig(url)
if (!rctext) return false
await runRc(rctext)
return true
}
export async function writeRc(conf: string, force = false, filename = "auto") {
let path: string
if (filename === "auto") {

View file

@ -751,6 +751,26 @@ export async function source_quiet(...fileArr: string[]) {
}
}
/** Use tridactylrc located at the given url
* @param url the url where the raw version of tridactylrc can be found
*/
//#background
export async function source_from_url(url: string) {
if (!url) return
await rc.sourceFromUrl(url)
}
/**
* Same as [[source_from_url]] but suppresses all errors
*/
//#background
export async function source_from_url_quiet(url: string) {
if (!url) return
try {
await rc.sourceFromUrl(url)
} catch (e) {}
}
/**
* Updates the native messenger if it is installed, using our GitHub repo. This is run every time Tridactyl is updated.
*