mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
Merge pull request #3366 from tridactyl/cache_native
WIP: cache getNativeMessengerVersion
This commit is contained in:
commit
ef4dd014cf
1 changed files with 8 additions and 1 deletions
|
@ -88,9 +88,13 @@ export async function getrc(): Promise<string> {
|
|||
}
|
||||
}
|
||||
|
||||
let NATIVE_VERSION_CACHE: string
|
||||
export async function getNativeMessengerVersion(
|
||||
quiet = false,
|
||||
): Promise<string> {
|
||||
if (NATIVE_VERSION_CACHE !== undefined) {
|
||||
return NATIVE_VERSION_CACHE
|
||||
}
|
||||
const res = await sendNativeMsg("version", {}, quiet)
|
||||
if (res === undefined) {
|
||||
if (quiet) return undefined
|
||||
|
@ -98,7 +102,10 @@ export async function getNativeMessengerVersion(
|
|||
}
|
||||
if (res.version && !res.error) {
|
||||
logger.info(`Native version: ${res.version}`)
|
||||
return res.version.toString()
|
||||
NATIVE_VERSION_CACHE = res.version.toString()
|
||||
// Wipe cache after 500ms
|
||||
setTimeout(() => (NATIVE_VERSION_CACHE = undefined), 500)
|
||||
return NATIVE_VERSION_CACHE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue