mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
add exmcmds to load RC file from url
This commit is contained in:
parent
c8b0f18cb3
commit
8f0b2a5ab8
2 changed files with 39 additions and 0 deletions
|
@ -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") {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue