mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 17:49:58 +00:00
Move options update handling to lib/options module
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { Options } from "../defaultOptions";
|
import defaultOptions, { Options } from "../defaultOptions";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +48,32 @@ async function set<T extends keyof Options> (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets existing options from storage and compares it
|
||||||
|
* against defaults. Any options in defaults and not in
|
||||||
|
* storage are set. Does not override any existing options.
|
||||||
|
*/
|
||||||
|
async function update (defaults = defaultOptions): Promise<void> {
|
||||||
|
const oldOpts = await getAll();
|
||||||
|
const newOpts: Partial<Options> = {};
|
||||||
|
|
||||||
|
// Find options not already in storage
|
||||||
|
for (const [ optName, optVal ] of Object.entries(defaults)) {
|
||||||
|
if (!oldOpts.hasOwnProperty(optName)) {
|
||||||
|
newOpts[optName] = optVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update storage with default values of new options
|
||||||
|
return setAll({
|
||||||
|
...oldOpts
|
||||||
|
, ...newOpts
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
get, getAll
|
get, getAll
|
||||||
, set, setAll
|
, set, setAll
|
||||||
}
|
, update
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import semver from "semver";
|
|||||||
import defaultOptions, { Options } from "./defaultOptions";
|
import defaultOptions, { Options } from "./defaultOptions";
|
||||||
import getBridgeInfo from "./lib/getBridgeInfo";
|
import getBridgeInfo from "./lib/getBridgeInfo";
|
||||||
import messageRouter from "./lib/messageRouter";
|
import messageRouter from "./lib/messageRouter";
|
||||||
import options from "./lib/options";
|
|
||||||
import nativeMessaging from "./lib/nativeMessaging";
|
import nativeMessaging from "./lib/nativeMessaging";
|
||||||
|
import options from "./lib/options";
|
||||||
|
|
||||||
import { getChromeUserAgent } from "./lib/userAgents";
|
import { getChromeUserAgent } from "./lib/userAgents";
|
||||||
import { getWindowCenteredProps } from "./lib/utils";
|
import { getWindowCenteredProps } from "./lib/utils";
|
||||||
@@ -33,25 +33,9 @@ browser.runtime.onInstalled.addListener(async details => {
|
|||||||
await options.setAll(defaultOptions);
|
await options.setAll(defaultOptions);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set newly added options
|
// Set newly added options
|
||||||
case "update": {
|
case "update": {
|
||||||
const existingOptions = await options.getAll();
|
await options.update(defaultOptions);
|
||||||
const newOptions: Partial<Options> = {};
|
|
||||||
|
|
||||||
// Find options not already in storage
|
|
||||||
for (const [ key, val ] of Object.entries(defaultOptions)) {
|
|
||||||
if (!existingOptions.hasOwnProperty(key)) {
|
|
||||||
(newOptions as any)[key] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update storage with default values of new options
|
|
||||||
options.setAll({
|
|
||||||
...existingOptions
|
|
||||||
, ...newOptions
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -513,7 +497,7 @@ browser.menus.onClicked.addListener(async (info, tab) => {
|
|||||||
userAgentWhitelist.push(matchPattern);
|
userAgentWhitelist.push(matchPattern);
|
||||||
|
|
||||||
// Update options
|
// Update options
|
||||||
await options.set("userAgentWhitelist", userAgentWhitelist)
|
await options.set("userAgentWhitelist", userAgentWhitelist);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import options from "../../lib/options";
|
|
||||||
import nativeMessaging from "../../lib/nativeMessaging";
|
import nativeMessaging from "../../lib/nativeMessaging";
|
||||||
|
import options from "../../lib/options";
|
||||||
|
|
||||||
import ReceiverSelectorManager, {
|
import ReceiverSelectorManager, {
|
||||||
ReceiverSelectorMediaType } from "../ReceiverSelectorManager";
|
ReceiverSelectorMediaType } from "../ReceiverSelectorManager";
|
||||||
|
|||||||
Reference in New Issue
Block a user