mirror of
https://github.com/tridactyl/tridactyl.git
synced 2026-09-10 07:16:33 -04:00
Fix #1905: run config update after RC import
This commit is contained in:
parent
edb5a60799
commit
4f3889d47d
25
src/background/config_rc.test.ts
Normal file
25
src/background/config_rc.test.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import * as controller from "@src/lib/controller"
|
||||
import * as config from "@src/lib/config"
|
||||
import { runRc } from "@src/background/config_rc"
|
||||
|
||||
jest.mock("@src/lib/controller")
|
||||
global.structuredClone ??= value => JSON.parse(JSON.stringify(value))
|
||||
|
||||
test("runRc updates and saves versioned config", async () => {
|
||||
await config.clear()
|
||||
jest.mocked(controller.acceptExCmd).mockImplementation(async cmd => {
|
||||
const [, key, value] = cmd.split(" ")
|
||||
await config.set(key, value)
|
||||
})
|
||||
|
||||
await runRc("set configversion 1.0\nset vimium-gi false")
|
||||
|
||||
expect(browser.storage.local.set).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
userconfig: expect.objectContaining({
|
||||
configversion: "2.0",
|
||||
gimode: "firefox",
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import * as controller from "@src/lib/controller"
|
||||
import * as config from "@src/lib/config"
|
||||
import * as Native from "@src/lib/native"
|
||||
|
||||
export async function source(filename = "auto") {
|
||||
|
|
@ -55,6 +56,8 @@ export async function runRc(rc: string) {
|
|||
for (const cmd of rcFileToExCmds(rc)) {
|
||||
await controller.acceptExCmd(cmd)
|
||||
}
|
||||
// Sourced commands have already been saved to the current local config.
|
||||
await config.update(true)
|
||||
}
|
||||
|
||||
export function rcFileToExCmds(rcText: string): string[] {
|
||||
|
|
|
|||
|
|
@ -2295,7 +2295,7 @@ export async function save() {
|
|||
When adding updaters, don't forget to set("configversion", newversionnumber)!
|
||||
@hidden
|
||||
*/
|
||||
export async function update() {
|
||||
export async function update(useCurrentConfig = false) {
|
||||
const set = (...args) => setDeepProperty(USERCONFIG, args.pop(), args)
|
||||
const unset = (...target) => {
|
||||
const key = target.pop()
|
||||
|
|
@ -2509,9 +2509,9 @@ export async function update() {
|
|||
: sync?.storageloc !== undefined
|
||||
? sync.storageloc
|
||||
: "sync"
|
||||
if (current_storageloc == "sync") {
|
||||
if (!useCurrentConfig && current_storageloc == "sync") {
|
||||
USERCONFIG = sync || o({})
|
||||
} else if (current_storageloc != "local") {
|
||||
} else if (!useCurrentConfig && current_storageloc != "local") {
|
||||
throw new Error(
|
||||
"storageloc was set to something weird: " +
|
||||
current_storageloc +
|
||||
|
|
|
|||
Loading…
Reference in a new issue