mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Add unchecked gets for runtime usage.
Also make config.getAsync use the same type checking and document a hitherto undocumented setting that it surfaced.
This commit is contained in:
parent
ce237daa3f
commit
905f0c50fe
4 changed files with 33 additions and 12 deletions
|
@ -3020,7 +3020,7 @@ export function bind(...args: string[]) {
|
|||
for (let i = 0; i < args_obj.key.length; i++) {
|
||||
// Check if any initial subsequence of the key exists and will shadow the new binding
|
||||
const key_sub = args_obj.key.slice(0, i)
|
||||
if (config.get(args_obj.configName as keyof config.default_config, key_sub)) {
|
||||
if (config.getDynamic(args_obj.configName, key_sub)) {
|
||||
fillcmdline_notrail("# Warning: bind `" + key_sub + "` exists and will shadow `" + args_obj.key + "`. Try running `:unbind --mode=" + args_obj.mode + " " + key_sub + "`")
|
||||
break
|
||||
}
|
||||
|
@ -3028,7 +3028,7 @@ export function bind(...args: string[]) {
|
|||
p = config.set(args_obj.configName, args_obj.key, args_obj.excmd)
|
||||
} else if (args_obj.key.length) {
|
||||
// Display the existing bind
|
||||
p = fillcmdline_notrail("#", args_obj.key, "=", config.get(args_obj.configName as keyof config.default_config, args_obj.key))
|
||||
p = fillcmdline_notrail("#", args_obj.key, "=", config.getDynamic(args_obj.configName, args_obj.key))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
@ -3457,9 +3457,7 @@ export async function quickmark(key: string, ...addressarr: string[]) {
|
|||
//#background
|
||||
export function get(...keys: string[]) {
|
||||
const target = keys.join(".").split(".")
|
||||
const value = config.get(
|
||||
target[0] as keyof config.default_config, ...target.slice(1)
|
||||
)
|
||||
const value = config.getDynamic(...target)
|
||||
console.log(value)
|
||||
if (typeof value === "object") {
|
||||
fillcmdline_notrail(`# ${keys.join(".")} = ${JSON.stringify(value)}`)
|
||||
|
@ -3489,7 +3487,7 @@ export function viewconfig(key?: string) {
|
|||
else
|
||||
window.location.href =
|
||||
"data:application/json," +
|
||||
JSON.stringify(config.get(key as keyof config.default_config))
|
||||
JSON.stringify(config.getDynamic(key))
|
||||
.replace(/#/g, "%23")
|
||||
.replace(/ /g, "%20")
|
||||
// base 64 encoding is a cleverer way of doing this, but it doesn't seem to work for the whole config.
|
||||
|
|
|
@ -53,7 +53,7 @@ async function addSetting(settingName: string) {
|
|||
{},
|
||||
)
|
||||
|
||||
const settings = await config.getAsync(settingName)
|
||||
const settings = await config.getAsyncDynamic(settingName)
|
||||
// For each setting
|
||||
for (const setting of Object.keys(settings)) {
|
||||
let excmd = settings[setting].split(" ")
|
||||
|
@ -150,7 +150,7 @@ function addSettingInputs() {
|
|||
const section = a.parentNode
|
||||
|
||||
const settingName = a.name.split(".")
|
||||
const value = await config.getAsync(settingName)
|
||||
const value = await config.getAsyncDynamic(...settingName)
|
||||
if (!value) return console.log("Failed to grab value of ", a)
|
||||
if (!["number", "boolean", "string"].includes(typeof value))
|
||||
return console.log(
|
||||
|
|
|
@ -668,6 +668,13 @@ export class default_config {
|
|||
*/
|
||||
theme = "default"
|
||||
|
||||
/**
|
||||
* Storage for custom themes
|
||||
*
|
||||
* Maps theme names to CSS. Predominantly used automatically by [[colourscheme]] to store themes read from disk, as documented by [[colourscheme]]. Setting this manually is untested but might work provided that [[colourscheme]] is then used to change the theme to the right theme name.
|
||||
*/
|
||||
customthemes = {}
|
||||
|
||||
/**
|
||||
* Whether to display the mode indicator or not.
|
||||
*/
|
||||
|
@ -1032,18 +1039,34 @@ export function get(target_typed?: keyof default_config, ...target: string[]) {
|
|||
}
|
||||
}
|
||||
|
||||
/** Get the value of the key target.
|
||||
|
||||
Please only use this with targets that will be used at runtime - it skips static checks. Prefer [[get]].
|
||||
*/
|
||||
export function getDynamic(...target: string[]) {
|
||||
return get(target[0] as keyof default_config, ...target.slice(1))
|
||||
}
|
||||
|
||||
/** Get the value of the key target.
|
||||
|
||||
Please only use this with targets that will be used at runtime - it skips static checks. Prefer [[getAsync]].
|
||||
*/
|
||||
export async function getAsyncDynamic(...target: string[]) {
|
||||
return getAsync(target[0] as keyof default_config, ...target.slice(1))
|
||||
}
|
||||
|
||||
/** Get the value of the key target, but wait for config to be loaded from the
|
||||
database first if it has not been at least once before.
|
||||
|
||||
This is useful if you are a content script and you've just been loaded.
|
||||
@hidden
|
||||
*/
|
||||
export async function getAsync(...target) {
|
||||
export async function getAsync(target_typed?: keyof default_config, ...target: string[]) {
|
||||
if (INITIALISED) {
|
||||
return get(...target)
|
||||
return get(target_typed, ...target)
|
||||
} else {
|
||||
return new Promise(resolve =>
|
||||
WAITERS.push(() => resolve(get(...target))),
|
||||
WAITERS.push(() => resolve(get(target_typed, ...target))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -709,7 +709,7 @@ export async function getConfElsePref(
|
|||
confName: string,
|
||||
prefName: string,
|
||||
): Promise<any> {
|
||||
let option = await config.getAsync(confName)
|
||||
let option = await config.getAsyncDynamic(confName)
|
||||
if (option === undefined) {
|
||||
try {
|
||||
option = await getPref(prefName)
|
||||
|
|
Loading…
Add table
Reference in a new issue