mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Turn numerical config settings into numbers
This commit turns every numerical config settings into numbers. Previously, they were stored as string as casting the arguments of the set excmd was slightly complicated. However, now that arguments are automatically cast, there is no reason to keep using strings. In fact, switching to number makes things simpler and fixes a few bugs where the config setting was accessed without being cast, like in text_to_speech.ts or completions/History.ts.
This commit is contained in:
parent
4d0f7c84eb
commit
d80fa64b03
5 changed files with 47 additions and 18 deletions
|
@ -115,7 +115,7 @@ export class HistoryCompletionSource extends Completions.CompletionSourceFuse {
|
|||
// Search history, dedupe and sort by frecency
|
||||
let history = await browserBg.history.search({
|
||||
text: query,
|
||||
maxResults: Number(config.get("historyresults")),
|
||||
maxResults: config.get("historyresults"),
|
||||
startTime: 0,
|
||||
})
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ async function getSmooth() {
|
|||
async function getDuration() {
|
||||
if (opts.duration === null)
|
||||
opts.duration = await config.getAsync("scrollduration")
|
||||
return Number.parseInt(opts.duration)
|
||||
return opts.duration
|
||||
}
|
||||
browser.storage.onChanged.addListener(changes => {
|
||||
if ("userconfig" in changes) {
|
||||
if ("smoothscroll" in changes.userconfig.newValue)
|
||||
opts.smooth = changes.userconfig.newValue["smoothscroll"]
|
||||
if ("scrollduration" in changes.userconfig.newValue)
|
||||
opts.duration = Number.parseInt(changes.userconfig.newValue["scrollduration"])
|
||||
opts.duration = changes.userconfig.newValue["scrollduration"]
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -65,7 +65,7 @@ class ScrollingData {
|
|||
if (elapsed >= this.duration || this.elem[this.pos] == this.endPos)
|
||||
return this.endPos
|
||||
|
||||
let result = (this.endPos - this.startPos) * elapsed / this.duration
|
||||
let result = ((this.endPos - this.startPos) * elapsed) / this.duration
|
||||
if (result >= 1 || result <= -1) return this.startPos + result
|
||||
return this.elem[this.pos] + (this.startPos < this.endPos ? 1 : -1)
|
||||
}
|
||||
|
|
|
@ -758,7 +758,7 @@ export function addJump(scrollEvent: UIEvent) {
|
|||
list.push({ x: pageX, y: pageY })
|
||||
jumps.cur = jumps.list.length - 1
|
||||
saveJumps(alljumps)
|
||||
}, Number.parseInt(config.get("jumpdelay")))
|
||||
}, config.get("jumpdelay"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class default_config {
|
|||
/**
|
||||
* Internal field to handle site-specific config priorities. Use :seturl/:unseturl to change this value.
|
||||
*/
|
||||
priority = "0"
|
||||
priority = 0
|
||||
|
||||
// Note to developers: When creating new <modifier-letter> maps, make sure to make the modifier uppercase (e.g. <C-a> instead of <c-a>) otherwise some commands might not be able to find them (e.g. `bind <c-a>`)
|
||||
|
||||
|
@ -548,7 +548,7 @@ class default_config {
|
|||
*
|
||||
* The point of this is to prevent accidental execution of normal mode binds due to people typing more than is necessary to choose a hint.
|
||||
*/
|
||||
hintdelay = "300"
|
||||
hintdelay = 300
|
||||
|
||||
/**
|
||||
* Controls whether the page can focus elements for you via js
|
||||
|
@ -572,7 +572,7 @@ class default_config {
|
|||
/**
|
||||
* How viscous you want smooth scrolling to feel.
|
||||
*/
|
||||
scrollduration = "100"
|
||||
scrollduration = 100
|
||||
|
||||
/**
|
||||
* Where to open tabs opened with `tabopen` - to the right of the current tab, or at the end of the tabs.
|
||||
|
@ -590,15 +590,15 @@ class default_config {
|
|||
/**
|
||||
* Controls text-to-speech volume. Has to be a number between 0 and 1.
|
||||
*/
|
||||
ttsvolume = "1"
|
||||
ttsvolume = 1
|
||||
/**
|
||||
* Controls text-to-speech speed. Has to be a number between 0.1 and 10.
|
||||
*/
|
||||
ttsrate = "1"
|
||||
ttsrate = 1
|
||||
/**
|
||||
* Controls text-to-speech pitch. Has to be between 0 and 2.
|
||||
*/
|
||||
ttspitch = "1"
|
||||
ttspitch = 1
|
||||
|
||||
/**
|
||||
* If nextinput, <Tab> after gi brings selects the next input
|
||||
|
@ -627,7 +627,7 @@ class default_config {
|
|||
/**
|
||||
* Milliseconds before registering a scroll in the jumplist
|
||||
*/
|
||||
jumpdelay = "3000"
|
||||
jumpdelay = 3000
|
||||
|
||||
/**
|
||||
* Logging levels. Unless you're debugging Tridactyl, it's unlikely you'll ever need to change these.
|
||||
|
@ -713,7 +713,7 @@ class default_config {
|
|||
/**
|
||||
* Number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones.
|
||||
*/
|
||||
historyresults = "50"
|
||||
historyresults = 50
|
||||
|
||||
/**
|
||||
* Change this to "clobber" to ruin the "Content Security Policy" of all sites a bit and make Tridactyl run a bit better on some of them, e.g. raw.github*
|
||||
|
@ -807,8 +807,8 @@ export function getURL(url, target) {
|
|||
// Sort them from highest to lowest priority, default to a priority of 10
|
||||
.sort(
|
||||
(k1, k2) =>
|
||||
(Number(USERCONFIG.subconfigs[k2].priority) || 10) -
|
||||
(Number(USERCONFIG.subconfigs[k1].priority) || 10),
|
||||
(USERCONFIG.subconfigs[k2].priority || 10) -
|
||||
(USERCONFIG.subconfigs[k1].priority || 10),
|
||||
)
|
||||
// Get the first config name that has `target`
|
||||
.find(k => getDeepProperty(USERCONFIG.subconfigs[k], target))
|
||||
|
@ -1004,6 +1004,35 @@ export async function update() {
|
|||
})
|
||||
set("configversion", "1.3")
|
||||
},
|
||||
"1.3": () => {
|
||||
// Updates a value both in the main config and in sub (=site specific) configs
|
||||
let updateAll = (setting: any[], fn: (any) => any) => {
|
||||
let val = getDeepProperty(USERCONFIG, setting)
|
||||
if (val) {
|
||||
set(...setting, fn(val))
|
||||
}
|
||||
let subconfigs = getDeepProperty(USERCONFIG, ["subconfigs"])
|
||||
if (subconfigs) {
|
||||
Object.keys(subconfigs)
|
||||
.map(pattern => [pattern, getURL(pattern, setting)])
|
||||
.filter(([pattern, value]) => value)
|
||||
.forEach(([pattern, value]) =>
|
||||
setURL(pattern, ...setting, fn(value)),
|
||||
)
|
||||
}
|
||||
}
|
||||
;[
|
||||
"priority",
|
||||
"hintdelay",
|
||||
"scrollduration",
|
||||
"ttsvolume",
|
||||
"ttsrate",
|
||||
"ttspitch",
|
||||
"jumpdelay",
|
||||
"historyresults",
|
||||
].forEach(setting => updateAll([setting], parseInt))
|
||||
set("configversion", "1.4")
|
||||
},
|
||||
}
|
||||
if (!get("configversion")) set("configversion", "0.0")
|
||||
const updatetest = v => {
|
||||
|
|
|
@ -27,10 +27,10 @@ export function readText(text: string): void {
|
|||
|
||||
let utterance = new SpeechSynthesisUtterance(text)
|
||||
|
||||
let pitch = Number.parseFloat(Config.get("ttspitch"))
|
||||
let pitch = Config.get("ttspitch")
|
||||
let voice = Config.get("ttsvoice")
|
||||
let volume = Number.parseFloat(Config.get("ttsvolume"))
|
||||
let rate = Number.parseFloat(Config.get("ttsrate"))
|
||||
let volume = Config.get("ttsvolume")
|
||||
let rate = Config.get("ttsrate")
|
||||
|
||||
if (pitch >= 0 && pitch < 2) utterance.pitch = pitch
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue