Skip to content

Commit cb770f5

Browse files
refactor(browser-platform-utils): Remove Deprecation and Fix Code (#14709)
* refactor(browser-platform-utils): Remove Deprecation and Fix Code - Changed usages of firefox to private and moved the usages to the preferred public method and removed the deprecations. * fix(browser-platform-utils): Remove Deprecation and Fix Code - Tiny changes. * test(browser-platform-utils): Remove Deprecation and Fix Code - Fixed up test
1 parent 88bc762 commit cb770f5

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
77
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
88
import { getOptionalUserId } from "@bitwarden/common/auth/services/account.service";
99
import { BadgeSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/badge-settings.service";
10+
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
1011
import { Utils } from "@bitwarden/common/platform/misc/utils";
1112
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
1213

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

1818
export type BadgeOptions = {
1919
tab?: chrome.tabs.Tab;
@@ -28,6 +28,7 @@ export class UpdateBadge {
2828
private badgeAction: typeof chrome.action | typeof chrome.browserAction;
2929
private sidebarAction: OperaSidebarAction | FirefoxSidebarAction;
3030
private win: Window & typeof globalThis;
31+
private platformUtilsService: PlatformUtilsService;
3132

3233
constructor(win: Window & typeof globalThis, services: MainBackground) {
3334
this.badgeAction = BrowserApi.getBrowserAction();
@@ -38,6 +39,7 @@ export class UpdateBadge {
3839
this.authService = services.authService;
3940
this.cipherService = services.cipherService;
4041
this.accountService = services.accountService;
42+
this.platformUtilsService = services.platformUtilsService;
4143
}
4244

4345
async run(opts?: { tabId?: number; windowId?: number }): Promise<void> {
@@ -129,7 +131,7 @@ export class UpdateBadge {
129131
38: "/images/icon38" + iconSuffix + ".png",
130132
},
131133
};
132-
if (windowId && BrowserPlatformUtilsService.isFirefox()) {
134+
if (windowId && this.platformUtilsService.isFirefox()) {
133135
options.windowId = windowId;
134136
}
135137

@@ -204,9 +206,7 @@ export class UpdateBadge {
204206
}
205207

206208
private get useSyncApiCalls() {
207-
return (
208-
BrowserPlatformUtilsService.isFirefox() || BrowserPlatformUtilsService.isSafari(this.win)
209-
);
209+
return this.platformUtilsService.isFirefox() || this.platformUtilsService.isSafari();
210210
}
211211

212212
private isOperaSidebar(

apps/browser/src/platform/services/platform-utils/browser-platform-utils.service.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,11 @@ describe("Browser Utils Service", () => {
126126
configurable: true,
127127
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0",
128128
});
129-
jest.spyOn(BrowserPlatformUtilsService, "isFirefox");
130129

131130
browserPlatformUtilsService.getDevice();
132131

133132
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.FirefoxExtension);
134-
expect(BrowserPlatformUtilsService.isFirefox).toHaveBeenCalledTimes(1);
133+
expect(browserPlatformUtilsService.isFirefox()).toBe(true);
135134
});
136135
});
137136

apps/browser/src/platform/services/platform-utils/browser-platform-utils.service.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
6060
return ClientType.Browser;
6161
}
6262

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

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

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

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

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

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

122+
isSafari(): boolean {
123+
return this.getDevice() === DeviceType.SafariExtension;
124+
}
125+
140126
/**
141127
* Safari previous to version 16.1 had a bug which caused artifacts on hover in large extension popups.
142128
* https://bugs.webkit.org/show_bug.cgi?id=218704
@@ -151,10 +137,6 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
151137
return parts?.[0] < 16 || (parts?.[0] === 16 && parts?.[1] === 0);
152138
}
153139

154-
isSafari(): boolean {
155-
return this.getDevice() === DeviceType.SafariExtension;
156-
}
157-
158140
isIE(): boolean {
159141
return false;
160142
}

0 commit comments

Comments
 (0)