Skip to content

refactor(browser-platform-utils): Remove Deprecation and Fix Code #14709

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

Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions apps/browser/src/platform/listeners/update-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { getOptionalUserId } from "@bitwarden/common/auth/services/account.service";
import { BadgeSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/badge-settings.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";

import MainBackground from "../../background/main.background";
import IconDetails from "../../vault/background/models/icon-details";
import { BrowserApi } from "../browser/browser-api";
import { BrowserPlatformUtilsService } from "../services/platform-utils/browser-platform-utils.service";

export type BadgeOptions = {
tab?: chrome.tabs.Tab;
Expand All @@ -28,6 +28,7 @@
private badgeAction: typeof chrome.action | typeof chrome.browserAction;
private sidebarAction: OperaSidebarAction | FirefoxSidebarAction;
private win: Window & typeof globalThis;
private platformUtilsService: PlatformUtilsService;

constructor(win: Window & typeof globalThis, services: MainBackground) {
this.badgeAction = BrowserApi.getBrowserAction();
Expand All @@ -38,6 +39,7 @@
this.authService = services.authService;
this.cipherService = services.cipherService;
this.accountService = services.accountService;
this.platformUtilsService = services.platformUtilsService;

Check warning on line 42 in apps/browser/src/platform/listeners/update-badge.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/platform/listeners/update-badge.ts#L42

Added line #L42 was not covered by tests
}

async run(opts?: { tabId?: number; windowId?: number }): Promise<void> {
Expand Down Expand Up @@ -129,7 +131,7 @@
38: "/images/icon38" + iconSuffix + ".png",
},
};
if (windowId && BrowserPlatformUtilsService.isFirefox()) {
if (windowId && this.platformUtilsService.isFirefox()) {
options.windowId = windowId;
}

Expand Down Expand Up @@ -204,9 +206,7 @@
}

private get useSyncApiCalls() {
return (
BrowserPlatformUtilsService.isFirefox() || BrowserPlatformUtilsService.isSafari(this.win)
);
return this.platformUtilsService.isFirefox() || this.platformUtilsService.isSafari();
}

private isOperaSidebar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ describe("Browser Utils Service", () => {
configurable: true,
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0",
});
jest.spyOn(BrowserPlatformUtilsService, "isFirefox");

browserPlatformUtilsService.getDevice();

expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.FirefoxExtension);
expect(BrowserPlatformUtilsService.isFirefox).toHaveBeenCalledTimes(1);
expect(browserPlatformUtilsService.isFirefox()).toBe(true);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return ClientType.Browser;
}

/**
* @deprecated Do not call this directly, use getDevice() instead
*/
static isFirefox(): boolean {
private static isFirefox(): boolean {
return (
navigator.userAgent.indexOf(" Firefox/") !== -1 ||
navigator.userAgent.indexOf(" Gecko/") !== -1
Expand All @@ -74,9 +71,6 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return this.getDevice() === DeviceType.FirefoxExtension;
}

/**
* @deprecated Do not call this directly, use getDevice() instead
*/
private static isChrome(globalContext: Window | ServiceWorkerGlobalScope): boolean {
return globalContext.chrome && navigator.userAgent.indexOf(" Chrome/") !== -1;
}
Expand All @@ -85,9 +79,6 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return this.getDevice() === DeviceType.ChromeExtension;
}

/**
* @deprecated Do not call this directly, use getDevice() instead
*/
private static isEdge(): boolean {
return navigator.userAgent.indexOf(" Edg/") !== -1;
}
Expand All @@ -96,9 +87,6 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return this.getDevice() === DeviceType.EdgeExtension;
}

/**
* @deprecated Do not call this directly, use getDevice() instead
*/
private static isOpera(globalContext: Window | ServiceWorkerGlobalScope): boolean {
return (
!!globalContext.opr?.addons ||
Expand All @@ -111,9 +99,6 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return this.getDevice() === DeviceType.OperaExtension;
}

/**
* @deprecated Do not call this directly, use getDevice() instead
*/
private static isVivaldi(): boolean {
return navigator.userAgent.indexOf(" Vivaldi/") !== -1;
}
Expand All @@ -122,10 +107,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return this.getDevice() === DeviceType.VivaldiExtension;
}

/**
* @deprecated Do not call this directly, use getDevice() instead
*/
static isSafari(globalContext: Window | ServiceWorkerGlobalScope): boolean {
private static isSafari(globalContext: Window | ServiceWorkerGlobalScope): boolean {
// Opera masquerades as Safari, so make sure we're not there first
return (
!BrowserPlatformUtilsService.isOpera(globalContext) &&
Expand All @@ -137,6 +119,10 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return navigator.userAgent.match("Version/([0-9.]*)")?.[1];
}

isSafari(): boolean {
return this.getDevice() === DeviceType.SafariExtension;
}

/**
* Safari previous to version 16.1 had a bug which caused artifacts on hover in large extension popups.
* https://bugs.webkit.org/show_bug.cgi?id=218704
Expand All @@ -151,10 +137,6 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return parts?.[0] < 16 || (parts?.[0] === 16 && parts?.[1] === 0);
}

isSafari(): boolean {
return this.getDevice() === DeviceType.SafariExtension;
}

isIE(): boolean {
return false;
}
Expand Down
Loading