Cleanup syncOptions

This commit is contained in:
Nathan Bierema 2024-08-11 09:43:29 -04:00
parent fae02a6d27
commit a7f6dbc0a2
3 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import configureStore from './store/backgroundStore'; import configureStore from './store/backgroundStore';
import openDevToolsWindow, { DevToolsPosition } from './openWindow'; import openDevToolsWindow, { DevToolsPosition } from './openWindow';
import { createMenu, removeMenu } from './contextMenus'; import { createMenu, removeMenu } from './contextMenus';
import syncOptions from '../options/syncOptions'; import createSyncOptions from '../options/syncOptions';
// Expose the extension's store globally to access it from the windows // Expose the extension's store globally to access it from the windows
// via chrome.runtime.getBackgroundPage // via chrome.runtime.getBackgroundPage
@ -16,7 +16,7 @@ chrome.commands.onCommand.addListener((shortcut) => {
chrome.runtime.onInstalled.addListener(() => { chrome.runtime.onInstalled.addListener(() => {
chrome.action.disable(); chrome.action.disable();
syncOptions().get((option) => { createSyncOptions().get((option) => {
if (option.showContextMenus) createMenu(); if (option.showContextMenus) createMenu();
}); });
}); });

View File

@ -11,7 +11,7 @@ import {
TOGGLE_PERSIST, TOGGLE_PERSIST,
UPDATE_STATE, UPDATE_STATE,
} from '@redux-devtools/app'; } from '@redux-devtools/app';
import syncOptions, { import createSyncOptions, {
Options, Options,
OptionsMessage, OptionsMessage,
} from '../../options/syncOptions'; } from '../../options/syncOptions';
@ -420,6 +420,8 @@ function toAllTabs(msg: TabMessage) {
}); });
} }
const syncOptions = createSyncOptions(toAllTabs);
function monitorInstances(shouldMonitor: boolean, id?: string) { function monitorInstances(shouldMonitor: boolean, id?: string) {
if (!id && isMonitored === shouldMonitor) return; if (!id && isMonitored === shouldMonitor) return;
const action = { const action = {
@ -497,7 +499,7 @@ function messaging<S, A extends Action<string>>(
return; return;
} }
if (request.type === 'GET_OPTIONS') { if (request.type === 'GET_OPTIONS') {
syncOptionsToAllTabs.get((options) => { syncOptions.get((options) => {
sendResponse!({ options }); sendResponse!({ options });
}); });
return; return;
@ -664,8 +666,6 @@ chrome.notifications.onClicked.addListener((id) => {
openDevToolsWindow('devtools-right'); openDevToolsWindow('devtools-right');
}); });
const syncOptionsToAllTabs = syncOptions(toAllTabs); // Expose to the options page
const api: Middleware<{}, BackgroundState, Dispatch<BackgroundAction>> = const api: Middleware<{}, BackgroundState, Dispatch<BackgroundAction>> =
(store) => (next) => (untypedAction) => { (store) => (next) => (untypedAction) => {
const action = untypedAction as BackgroundAction; const action = untypedAction as BackgroundAction;

View File

@ -154,7 +154,7 @@ export interface SyncOptions {
readonly subscribe: (callback: (options: Options) => void) => void; readonly subscribe: (callback: (options: Options) => void) => void;
} }
export default function syncOptions(toAllTabs?: ToAllTabs): SyncOptions { export default function createSyncOptions(toAllTabs?: ToAllTabs): SyncOptions {
if (toAllTabs && !options) get(() => {}); // Initialize if (toAllTabs && !options) get(() => {}); // Initialize
return { return {
save: save(toAllTabs), save: save(toAllTabs),