Skip to content

Commit

Permalink
take out tabSendMessageData call for inline menu visibility sub-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jprusik committed Oct 3, 2024
1 parent 6463191 commit ea58f9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export type AutofillExtensionMessage = {
data?: {
direction?: "previous" | "next" | "current";
forceCloseInlineMenu?: boolean;
settingType?: CipherType;
newSettingValue?: InlineMenuVisibilitySetting | boolean;
newSettingValue?: InlineMenuVisibilitySetting;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,34 +1358,15 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
}

/**
* Updates the local reference to the passed inline menu visibility setting.
* Updates the local reference to the inline menu visibility setting.
*
* @param data - The data object from the extension message.
*/
private updateInlineMenuVisibility({ data }: AutofillExtensionMessage) {
const settingNewValue = data?.newSettingValue;
const newSettingValue = data?.newSettingValue;

if (settingNewValue == null) {
return;
}

const settingType = data?.settingType;

// Setting value update is for overall inline menu visibility
if (settingType == null && !isNaN(settingNewValue as InlineMenuVisibilitySetting)) {
this.inlineMenuVisibility = settingNewValue as InlineMenuVisibilitySetting;

return;
}

if (typeof settingType === "boolean") {
if (settingType === CipherType.Card) {
this.showInlineMenuCards = settingNewValue as boolean;
}

if (settingType === CipherType.Identity) {
this.showInlineMenuIdentities = settingNewValue as boolean;
}
if (!isNaN(newSettingValue)) {
this.inlineMenuVisibility = newSettingValue;
}
}

Expand Down
50 changes: 18 additions & 32 deletions apps/browser/src/autofill/services/autofill.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,13 @@ export default class AutofillService implements AutofillServiceInterface {
this.autofillSettingsService.showInlineMenuCards$
.pipe(startWith(undefined), pairwise())
.subscribe(([previousSetting, currentSetting]) =>
this.handleInlineMenuVisibilitySettingsChange(
previousSetting,
currentSetting,
CipherType.Card,
),
this.handleInlineMenuVisibilitySettingsChange(previousSetting, currentSetting),
);

this.autofillSettingsService.showInlineMenuIdentities$
.pipe(startWith(undefined), pairwise())
.subscribe(([previousSetting, currentSetting]) =>
this.handleInlineMenuVisibilitySettingsChange(
previousSetting,
currentSetting,
CipherType.Identity,
),
this.handleInlineMenuVisibilitySettingsChange(previousSetting, currentSetting),
);
}

Expand Down Expand Up @@ -3059,36 +3051,30 @@ export default class AutofillService implements AutofillServiceInterface {
private async handleInlineMenuVisibilitySettingsChange(
oldSettingValue: InlineMenuVisibilitySetting | boolean,
newSettingValue: InlineMenuVisibilitySetting | boolean,
cipherType?: CipherType,
) {
if (oldSettingValue === undefined || oldSettingValue === newSettingValue) {
return;
}

const tabs = await BrowserApi.tabsQuery({});

// If the setting change is for the behavior of overall inline menu display
if (cipherType == null) {
const inlineMenuPreviouslyDisabled = oldSettingValue === AutofillOverlayVisibility.Off;
const inlineMenuCurrentlyDisabled = newSettingValue === AutofillOverlayVisibility.Off;
const isInlineMenuVisibilitySubSetting =
typeof oldSettingValue === "boolean" || typeof newSettingValue === "boolean";
const inlineMenuPreviouslyDisabled = oldSettingValue === AutofillOverlayVisibility.Off;
const inlineMenuCurrentlyDisabled = newSettingValue === AutofillOverlayVisibility.Off;

if (!inlineMenuPreviouslyDisabled && !inlineMenuCurrentlyDisabled) {
tabs.forEach((tab) =>
BrowserApi.tabSendMessageData(tab, "updateAutofillInlineMenuVisibility", {
newSettingValue,
}),
);
return;
}
if (
!isInlineMenuVisibilitySubSetting &&
!inlineMenuPreviouslyDisabled &&
!inlineMenuCurrentlyDisabled
) {
const tabs = await BrowserApi.tabsQuery({});
tabs.forEach((tab) =>
BrowserApi.tabSendMessageData(tab, "updateAutofillInlineMenuVisibility", {
newSettingValue,
}),
);
return;
}

tabs.forEach((tab) =>
BrowserApi.tabSendMessageData(tab, "updateAutofillInlineMenuVisibility", {
settingType: cipherType,
newSettingValue,
}),
);

await this.reloadAutofillScripts();
}
}

0 comments on commit ea58f9e

Please sign in to comment.