Skip to content

Commit

Permalink
Fix Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
perry-mitchell committed Mar 26, 2024
1 parent 6e249a4 commit 1edc9f2
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 34 deletions.
25 changes: 24 additions & 1 deletion source/background/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ import { getRecents, trackRecentUsage } from "./recents.js";
import { openEntryPageInNewTab } from "./entry.js";
import { getAutoLoginForTab, registerAutoLogin } from "./autoLogin.js";
import { extractDomainFromCredentials } from "../library/domain.js";
import { BackgroundMessage, BackgroundMessageType, BackgroundResponse, LocalStorageItem } from "../types.js";
import {
BackgroundMessage,
BackgroundMessageType,
BackgroundResponse,
LocalStorageItem,
TabEventType
} from "../types.js";
import { markNotificationRead } from "./notifications.js";
import { createNewTab, getExtensionURL } from "../../shared/library/extension.js";
import { sendTabsMessage } from "./tabs.js";

async function handleMessage(
msg: BackgroundMessage,
Expand Down Expand Up @@ -79,6 +87,9 @@ async function handleMessage(
const { credentialsID } = msg;
log(`clear saved credentials prompt: ${credentialsID}`);
stopPromptForID(credentialsID);
await sendTabsMessage({
type: TabEventType.CloseSaveDialog
});
sendResponse({});
break;
}
Expand All @@ -104,6 +115,9 @@ async function handleMessage(
} catch (err) {
throw new Layerr(err, "Failed disabling save prompt for domain");
}
await sendTabsMessage({
type: TabEventType.CloseSaveDialog
});
sendResponse({});
break;
}
Expand Down Expand Up @@ -203,6 +217,7 @@ async function handleMessage(
case BackgroundMessageType.InitiateDesktopConnection: {
log("start desktop authentication");
await initiateConnection();
await createNewTab(getExtensionURL("full.html#/connect"));
sendResponse({});
break;
}
Expand All @@ -228,6 +243,14 @@ async function handleMessage(
sendResponse({ opened: true });
break;
}
case BackgroundMessageType.OpenSaveCredentialsPage: {
await createNewTab(getExtensionURL("full.html#/save-credentials"));
await sendTabsMessage({
type: TabEventType.CloseSaveDialog
});
sendResponse({});
break;
}
case BackgroundMessageType.PromptLockSource: {
const { sourceID } = msg;
log(`request lock source: ${sourceID}`);
Expand Down
18 changes: 18 additions & 0 deletions source/background/services/tabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getExtensionAPI } from "../../shared/extension.js";
import { TabEvent } from "../types.js";

export async function sendTabsMessage(payload: TabEvent, tabIDs: Array<number> | null = null): Promise<void> {
const browser = getExtensionAPI();
const targetTabIDs = Array.isArray(tabIDs)
? tabIDs
: (
await browser.tabs.query({
status: "complete"
})
).map((tab) => tab.id);
await Promise.all(
targetTabIDs.map(async (tabID) => {
await browser.tabs.sendMessage(tabID, payload);
})
);
}
4 changes: 1 addition & 3 deletions source/popup/components/navigation/Navigator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, useCallback, useState } from "react";
import React, { useCallback, useState } from "react";
import styled from "styled-components";
import { Classes, Divider, Icon, Intent, Tab, Tabs } from "@blueprintjs/core";
import { VaultsPage, VaultsPageControls } from "../pages/VaultsPage.js";
Expand All @@ -7,7 +7,6 @@ import { getToaster } from "../../../shared/services/notifications.js";
import { localisedErrorMessage } from "../../../shared/library/error.js";
import { t } from "../../../shared/i18n/trans.js";
import { clearDesktopConnectionAuth, initiateDesktopConnectionRequest } from "../../queries/desktop.js";
import { createNewTab, getExtensionURL } from "../../../shared/library/extension.js";
import { OTPsPage } from "../pages/OTPsPage.js";
import { SettingsPage } from "../pages/SettingsPage.js";
import { AboutPage } from "../pages/AboutPage.js";
Expand Down Expand Up @@ -63,7 +62,6 @@ export function Navigator(props: NavigatorProps) {
const handleConnectClick = useCallback(async () => {
try {
await initiateDesktopConnectionRequest();
await createNewTab(getExtensionURL("full.html#/connect"));
} catch (err) {
console.error(err);
getToaster().show({
Expand Down
9 changes: 9 additions & 0 deletions source/popup/components/pages/EntriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ function EntriesPageList(props: EntriesPageProps) {
/>
);
}
if (urlEntries.length <= 0 && recentEntries.length <= 0) {
return (
<InvalidState
title={t("popup.no-entries.title")}
description={t("popup.no-entries.description")}
icon="clean"
/>
);
}
return (
<EntryItemList
entries={{
Expand Down
19 changes: 7 additions & 12 deletions source/popup/components/pages/SaveDialogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { getToaster } from "../../../shared/services/notifications.js";
import { clearSavedLoginPrompt } from "../../queries/loginMemory.js";
import { localisedErrorMessage } from "../../../shared/library/error.js";
import { extractDomain } from "../../../shared/library/domain.js";
import { sendTabsMessage } from "../../../shared/services/messaging.js";
import { createNewTab, getExtensionURL } from "../../../shared/library/extension.js";
import { TabEventType } from "../../types.js";
import { BackgroundMessageType } from "../../types.js";
import { disableDomainForLogin } from "../../queries/disabledDomains.js";
import { sendBackgroundMessage } from "../../../shared/services/messaging.js";

const Buttons = styled.div`
width: 100%;
Expand Down Expand Up @@ -94,9 +93,9 @@ export function SaveDialogPage() {
const [disableConfirm, setDisableConfirm] = useState<boolean>(false);
const handleViewClick = useCallback(async () => {
try {
await createNewTab(getExtensionURL("full.html#/save-credentials"));
await sendTabsMessage({
type: TabEventType.CloseSaveDialog
// Open save page and close dialog
await sendBackgroundMessage({
type: BackgroundMessageType.OpenSaveCredentialsPage
});
} catch (err) {
console.error(err);
Expand All @@ -109,10 +108,8 @@ export function SaveDialogPage() {
}, [loginID]);
const handleCloseClick = useCallback(async () => {
try {
// Clear prompt and close dialog
await clearSavedLoginPrompt(loginID);
await sendTabsMessage({
type: TabEventType.CloseSaveDialog
});
} catch (err) {
console.error(err);
getToaster().show({
Expand All @@ -128,10 +125,8 @@ export function SaveDialogPage() {
return;
}
try {
// Disable domain and close dialog
await disableDomainForLogin(loginID);
await sendTabsMessage({
type: TabEventType.CloseSaveDialog
});
} catch (err) {
console.error(err);
getToaster().show({
Expand Down
3 changes: 3 additions & 0 deletions source/shared/extension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export function getExtensionAPI(): typeof chrome {
if (BROWSER === "firefox") {
return browser;
}
return self.chrome || self["browser"];
}
4 changes: 4 additions & 0 deletions source/shared/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
"placeholder": "Search..."
}
},
"no-entries": {
"description": "No available entries - recent items and results for the current tab will appear here.",
"title": "No Entries"
},
"no-otps": {
"description": "No OTP entries found in unlocked vaults.",
"title": "No OTP Entries"
Expand Down
2 changes: 1 addition & 1 deletion source/shared/library/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Do not edit this file - it is generated automatically at build time

export const BUILD_DATE = "2024-03-24";
export const BUILD_DATE = "2024-03-25";
export const VERSION = "3.0.0";
16 changes: 0 additions & 16 deletions source/shared/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,3 @@ export async function sendBackgroundMessage(
});
});
}

export async function sendTabsMessage(payload: TabEvent, tabIDs: Array<number> | null = null): Promise<void> {
const browser = getExtensionAPI();
const targetTabIDs = Array.isArray(tabIDs)
? tabIDs
: (
await browser.tabs.query({
status: "complete"
})
).map((tab) => tab.id);
await Promise.all(
targetTabIDs.map(async (tabID) => {
await browser.tabs.sendMessage(tabID, payload);
})
);
}
1 change: 1 addition & 0 deletions source/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export enum BackgroundMessageType {
GetSavedCredentialsForID = "getCredentialsForID",
MarkNotificationRead = "markNotificationRead",
OpenEntryPage = "openEntryPage",
OpenSaveCredentialsPage = "openSaveCredentials",
PromptLockSource = "promptLockSource",
PromptUnlockSource = "promptUnlockSource",
ResetSettings = "resetSettings",
Expand Down
2 changes: 2 additions & 0 deletions source/typings/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare var BROWSER: "chrome" | "edge" | "firefox";
declare var browser: typeof chrome;
8 changes: 7 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import packageInfo from "./package.json" assert { type: "json" };
import manifestV2 from "./resources/manifest.v2.json" assert { type: "json" };
import manifestV3 from "./resources/manifest.v3.json" assert { type: "json" };

const { BannerPlugin } = webpack;
const { BannerPlugin, DefinePlugin } = webpack;
const { BROWSER } = process.env;
const V3_BROWSERS = ["chrome", "edge"];
const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -118,6 +118,12 @@ function getBaseConfig() {
maxAssetSize: 768000
},

plugins: [
new DefinePlugin({
BROWSER: JSON.stringify(BROWSER)
})
],

resolve: {
alias: {
iocane: "iocane/web",
Expand Down

0 comments on commit 1edc9f2

Please sign in to comment.