Skip to content

Commit

Permalink
Fix export options for debug options
Browse files Browse the repository at this point in the history
1. Change a debug option.
2. Restart the browser.
3. Reset the debug option.
4. Click Export.

The debug option was reset correctly, but the export still included the
changed debug option (until you restarted the browser).
  • Loading branch information
lydell committed Feb 22, 2020
1 parent e7a8edf commit 4bb2d2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/background/Program.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
diffOptions,
flattenOptions,
getDefaults,
getRawOptions,
makeOptionsDecoder,
unflattenOptions,
} from "../shared/options";
Expand Down Expand Up @@ -1919,7 +1920,7 @@ export default class BackgroundProgram {
const info = await browser.runtime.getPlatformInfo();
const mac = info.os === "mac";
const defaults = getDefaults({ mac });
const rawOptions = await browser.storage.sync.get();
const rawOptions = await getRawOptions();
const defaulted = { ...flattenOptions(defaults), ...rawOptions };
const unflattened = unflattenOptions(defaulted);
const decoder = makeOptionsDecoder(defaults);
Expand Down Expand Up @@ -1954,7 +1955,7 @@ export default class BackgroundProgram {
// flattening `partialOptions` and storing that would mean that you couldn't
// remove any `options.keys`, for example.
try {
const rawOptions = await browser.storage.sync.get();
const rawOptions = await getRawOptions();
const { keysToRemove, optionsToSet } = diffOptions(
flattenOptions(this.options.defaults),
flattenOptions({ ...this.options.values, ...partialOptions }),
Expand Down
12 changes: 9 additions & 3 deletions src/shared/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ export function unflattenOptions(object: FlatOptions): FlatOptions {

export const DEBUG_PREFIX = "debug.";

export async function getRawOptions(): FlatOptions {
const raw = await browser.storage.sync.get();
// Exclude all tweakables since they are handled completely differently.
return Object.fromEntries(
Object.entries(raw).filter(([key]) => !key.startsWith(DEBUG_PREFIX))
);
}

export function diffOptions(
defaults: FlatOptions,
fullOptions: FlatOptions,
Expand All @@ -385,9 +393,7 @@ export function diffOptions(
]);

for (const key of allKeys) {
if (key.startsWith(DEBUG_PREFIX)) {
continue;
} else if (
if (
{}.hasOwnProperty.call(defaults, key) &&
!{}.hasOwnProperty.call(fullOptions, key)
) {
Expand Down

0 comments on commit 4bb2d2a

Please sign in to comment.