import { useDialog } from "@/contexts/DialogProvider"; import useSettings from "@/hooks/useSettings"; import browserLocaleKey from "@/utils/browserLocaleKey"; import { Menu, MenuButtonProps, MenuItem, MenuList, MenuPopover, MenuTrigger, SplitButton } from "@fluentui/react-components"; import * as ic from "@fluentui/react-icons"; import CollectionContext, { CollectionContextType } from "../../contexts/CollectionContext"; import { useCollections } from "../../contexts/CollectionsProvider"; import { openCollection } from "../../utils/opener"; export default function OpenCollectionButton(): React.ReactElement { const [defaultAction] = useSettings("defaultRestoreAction"); const { removeItem } = useCollections(); const dialog = useDialog(); const { collection, collectionIndex } = useContext(CollectionContext); const OpenIcon = ic.bundleIcon(ic.Open20Filled, ic.Open20Regular); const RestoreIcon = ic.bundleIcon(ic.ArrowExportRtl20Filled, ic.ArrowExportRtl20Regular); const NewWindowIcon = ic.bundleIcon(ic.WindowNew20Filled, ic.WindowNew20Regular); const InPrivateIcon = ic.bundleIcon(ic.TabInPrivate20Filled, ic.TabInPrivate20Regular); const handleIncognito = async () => { if (await browser.extension.isAllowedIncognitoAccess()) openCollection(collection, "incognito"); else dialog.pushPrompt({ title: i18n.t("collections.incognito_check.title"), content: ( <> { i18n.t(`collections.incognito_check.message.${browserLocaleKey}.p1`) }

{ i18n.t(`collections.incognito_check.message.${browserLocaleKey}.p2`) } ), confirmText: i18n.t("collections.incognito_check.action"), onConfirm: async () => import.meta.env.FIREFOX ? await browser.runtime.openOptionsPage() : await browser.tabs.create({ url: `chrome://extensions/?id=${browser.runtime.id}`, active: true }) }); }; const handleOpen = (mode: "current" | "new") => () => openCollection(collection, mode); const handleRestore = async () => { await openCollection(collection); removeItem(collectionIndex); }; return ( { (triggerProps: MenuButtonProps) => defaultAction === "restore" ? } menuButton={ triggerProps } primaryActionButton={ { onClick: handleRestore } } > { i18n.t("collections.actions.restore") } : } menuButton={ triggerProps } primaryActionButton={ { onClick: handleOpen("current") } } > { i18n.t("collections.actions.open") } } { defaultAction === "restore" ? } onClick={ handleOpen("current") }> { i18n.t("collections.actions.open") } : } onClick={ handleRestore }> { i18n.t("collections.actions.restore") } } } onClick={ () => handleOpen("new") }> { i18n.t("collections.actions.new_window") } } onClick={ handleIncognito }> { i18n.t(`collections.actions.incognito.${browserLocaleKey}`) } ); }