Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore ability to toggle sidebar via action click in MV3 #7429

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/background/browserAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { memoizeUntilSettled } from "@/utils/promiseUtils";
import { openSidePanel } from "@/mv3/sidePanelMigration";
import { setActionPopup } from "webext-tools";
import { getReasonByUrl } from "@/tinyPages/restrictedUrlPopupUtils";
import { messenger } from "webext-messenger";
import { getSidebarPath } from "@/sidebar/sidePanel/messenger/api";

/**
* Show a popover on restricted URLs because we're unable to inject content into the page. Previously we'd open
Expand Down Expand Up @@ -56,7 +58,19 @@ export default async function initBrowserAction(): Promise<void> {
});

browserAction.onClicked.addListener(async (tab) => {
// This handler relies on a race condition:
// - If the was open, openSidePanel will do nothing,
// but SIDEBAR_CLOSE will reach the sidebar and close it
// - If the sidebar was closed, openSidePanel will open it,
// and SIDEBAR_CLOSE will fail because the message won't reach the sidebar in time
await openSidePanel(tab.id);
await messenger(
"SIDEBAR_CLOSE",
{ isNotification: true, retry: false },
{
page: getSidebarPath(tab.id),
},
);
});
}

Expand Down
Loading