Skip to content

Commit

Permalink
refactor(background): simplify initIconAndBadgeUpdater (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
WofWca committed Jan 1, 2023
1 parent 791236f commit 01cd0df
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/entry-points/background/initIconAndBadgeUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,30 @@ export default async function initIconAndBadgeUpdater(): Promise<void> {
/**
* @param changes - pass `null` to initialize.
*/
function handleSettingsChanges(changes: MyStorageChanges | null) {
function handleSettingsChanges(changes: MyStorageChanges) {
if (changes) {
Object.assign(settings, settingsChanges2NewValues(changes));
}

setIcon(settings);

if (changes) {
// TODO improvement: also display `video.volume` changes? Perhaps this script belongs to `content/main.ts`?
const orderedSetingsNames =
['soundedSpeed', 'silenceSpeedRaw', 'volumeThreshold', 'marginBefore', 'marginAfter'] as const;
for (const settingName of orderedSetingsNames) {
const currSettingChange = changes[settingName];
if (currSettingChange) {
temporarelySetBadge(...settingToBadgeParams(settingName, currSettingChange.newValue!), settings);
break;
}
}
// TODO refactor: it would be cooler if we wrote the badge's dependencies more declaratively.
if (changes.badgeWhatSettingToDisplayByDefault || changes.enabled) {
setBadgeToDefault(settings);
// TODO improvement: also display `video.volume` changes? Perhaps this script belongs to `content/main.ts`?
const orderedSetingsNames =
['soundedSpeed', 'silenceSpeedRaw', 'volumeThreshold', 'marginBefore', 'marginAfter'] as const;
for (const settingName of orderedSetingsNames) {
const currSettingChange = changes[settingName];
if (currSettingChange) {
temporarelySetBadge(...settingToBadgeParams(settingName, currSettingChange.newValue!), settings);
break;
}
} else {
setBadgeToDefault(settings); // In case e.g. `settings.badgeWhatSettingToDisplayByDefault !== 'none'`
}
// TODO refactor: it would be cooler if we wrote the badge's dependencies more declaratively.
if (changes.badgeWhatSettingToDisplayByDefault || changes.enabled) {
setBadgeToDefault(settings);
}
setBadgeToDefault(settings); // In case e.g. `settings.badgeWhatSettingToDisplayByDefault !== 'none'`
}
handleSettingsChanges(null);
setBadgeToDefault(settings);
setIcon(settings);
addOnStorageChangedListener(handleSettingsChanges);
}

0 comments on commit 01cd0df

Please sign in to comment.