mirror of
https://github.com/bitwarden/browser
synced 2025-01-01 20:57:53 +01:00
rename browserType to deviceType
This commit is contained in:
parent
2ef937f333
commit
01cf48bbed
@ -1,4 +1,4 @@
|
||||
export enum BrowserType {
|
||||
export enum DeviceType {
|
||||
Chrome = 2,
|
||||
Firefox = 3,
|
||||
Opera = 4,
|
@ -1,15 +1,15 @@
|
||||
import { BrowserType } from '../../enums/browserType.enum';
|
||||
import { DeviceType } from '../../enums/deviceType.enum';
|
||||
import { BrowserUtilsService } from '../../services/abstractions/browserUtils.service';
|
||||
|
||||
class DeviceRequest {
|
||||
type: BrowserType;
|
||||
type: DeviceType;
|
||||
name: string;
|
||||
identifier: string;
|
||||
pushToken?: string;
|
||||
|
||||
constructor(appId: string, browserUtilsService: BrowserUtilsService) {
|
||||
this.type = browserUtilsService.getBrowser();
|
||||
this.name = browserUtilsService.getBrowserString();
|
||||
this.type = browserUtilsService.getDevice();
|
||||
this.name = browserUtilsService.getDeviceString();
|
||||
this.identifier = appId;
|
||||
this.pushToken = null;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { BrowserType } from '../../enums/browserType.enum';
|
||||
import { DeviceType } from '../../enums/deviceType.enum';
|
||||
|
||||
class DeviceResponse {
|
||||
id: string;
|
||||
name: number;
|
||||
identifier: string;
|
||||
type: BrowserType;
|
||||
type: DeviceType;
|
||||
creationDate: string;
|
||||
|
||||
constructor(response: any) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as angular from 'angular';
|
||||
import { BrowserType } from '../../../enums/browserType.enum';
|
||||
import { DeviceType } from '../../../enums/deviceType.enum';
|
||||
import { BrowserUtilsService } from '../../../services/abstractions/browserUtils.service';
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
import { MessagingService } from '../../../services/abstractions/messaging.service';
|
||||
@ -9,17 +9,17 @@ import ConstantsService from '../../../services/constants.service';
|
||||
import * as template from './settings.component.html';
|
||||
|
||||
const RateUrls = {
|
||||
[BrowserType.Chrome]:
|
||||
[DeviceType.Chrome]:
|
||||
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
|
||||
[BrowserType.Firefox]:
|
||||
[DeviceType.Firefox]:
|
||||
'https://addons.mozilla.org/en-US/firefox/addon/bitwarden-password-manager/#reviews',
|
||||
[BrowserType.Opera]:
|
||||
[DeviceType.Opera]:
|
||||
'https://addons.opera.com/en/extensions/details/bitwarden-free-password-manager/#feedback-container',
|
||||
[BrowserType.Edge]:
|
||||
[DeviceType.Edge]:
|
||||
'https://www.microsoft.com/store/p/bitwarden-free-password-manager/9p6kxl0svnnl',
|
||||
[BrowserType.Vivaldi]:
|
||||
[DeviceType.Vivaldi]:
|
||||
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
|
||||
[BrowserType.Safari]:
|
||||
[DeviceType.Safari]:
|
||||
'https://itunes.com', // TODO
|
||||
};
|
||||
|
||||
@ -147,7 +147,7 @@ export class SettingsController {
|
||||
rate() {
|
||||
this.$analytics.eventTrack('Rate Extension');
|
||||
chrome.tabs.create({
|
||||
url: RateUrls[this.browserUtilsService.getBrowser()],
|
||||
url: RateUrls[this.browserUtilsService.getDevice()],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { BrowserType } from '../../enums/browserType.enum';
|
||||
import { DeviceType } from '../../enums/deviceType.enum';
|
||||
|
||||
export interface BrowserUtilsService {
|
||||
getBrowser(): BrowserType;
|
||||
getBrowserString(): string;
|
||||
getDevice(): DeviceType;
|
||||
getDeviceString(): string;
|
||||
isFirefox(): boolean;
|
||||
isChrome(): boolean;
|
||||
isEdge(): boolean;
|
||||
|
@ -38,7 +38,7 @@ export default class ApiService {
|
||||
constructor(private tokenService: TokenService, browserUtilsService: BrowserUtilsService,
|
||||
logoutCallback: Function) {
|
||||
this.logoutCallback = logoutCallback;
|
||||
this.deviceType = browserUtilsService.getBrowser().toString();
|
||||
this.deviceType = browserUtilsService.getDevice().toString();
|
||||
}
|
||||
|
||||
setUrls(urls: EnvironmentUrls) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import BrowserUtilsService from './browserUtils.service';
|
||||
import { BrowserType } from '../enums/browserType.enum';
|
||||
import { DeviceType } from '../enums/deviceType.enum';
|
||||
|
||||
describe('Browser Utils Service', () => {
|
||||
describe('getDomain', () => {
|
||||
@ -48,7 +48,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserUtilsService = new BrowserUtilsService();
|
||||
expect(browserUtilsService.getBrowser()).toBe(BrowserType.Chrome);
|
||||
expect(browserUtilsService.getDevice()).toBe(DeviceType.Chrome);
|
||||
});
|
||||
|
||||
it('should detect firefox', () => {
|
||||
@ -58,7 +58,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserUtilsService = new BrowserUtilsService();
|
||||
expect(browserUtilsService.getBrowser()).toBe(BrowserType.Firefox);
|
||||
expect(browserUtilsService.getDevice()).toBe(DeviceType.Firefox);
|
||||
});
|
||||
|
||||
it('should detect opera', () => {
|
||||
@ -68,7 +68,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserUtilsService = new BrowserUtilsService();
|
||||
expect(browserUtilsService.getBrowser()).toBe(BrowserType.Opera);
|
||||
expect(browserUtilsService.getDevice()).toBe(DeviceType.Opera);
|
||||
});
|
||||
|
||||
it('should detect edge', () => {
|
||||
@ -78,7 +78,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserUtilsService = new BrowserUtilsService();
|
||||
expect(browserUtilsService.getBrowser()).toBe(BrowserType.Edge);
|
||||
expect(browserUtilsService.getDevice()).toBe(DeviceType.Edge);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,14 +1,14 @@
|
||||
import * as tldjs from 'tldjs';
|
||||
import { BrowserType } from '../enums/browserType.enum';
|
||||
import { DeviceType } from '../enums/deviceType.enum';
|
||||
import { BrowserUtilsService as BrowserUtilsServiceInterface } from './abstractions/browserUtils.service';
|
||||
|
||||
const AnalyticsIds = {
|
||||
[BrowserType.Chrome]: 'UA-81915606-6',
|
||||
[BrowserType.Firefox]: 'UA-81915606-7',
|
||||
[BrowserType.Opera]: 'UA-81915606-8',
|
||||
[BrowserType.Edge]: 'UA-81915606-9',
|
||||
[BrowserType.Vivaldi]: 'UA-81915606-15',
|
||||
[BrowserType.Safari]: 'UA-81915606-16',
|
||||
[DeviceType.Chrome]: 'UA-81915606-6',
|
||||
[DeviceType.Firefox]: 'UA-81915606-7',
|
||||
[DeviceType.Opera]: 'UA-81915606-8',
|
||||
[DeviceType.Edge]: 'UA-81915606-9',
|
||||
[DeviceType.Vivaldi]: 'UA-81915606-15',
|
||||
[DeviceType.Safari]: 'UA-81915606-16',
|
||||
};
|
||||
|
||||
export default class BrowserUtilsService implements BrowserUtilsServiceInterface {
|
||||
@ -49,56 +49,56 @@ export default class BrowserUtilsService implements BrowserUtilsServiceInterface
|
||||
return ipRegex.test(ipString);
|
||||
}
|
||||
|
||||
private browserCache: BrowserType = null;
|
||||
private deviceCache: DeviceType = null;
|
||||
private analyticsIdCache: string = null;
|
||||
|
||||
getBrowser(): BrowserType {
|
||||
if (this.browserCache) {
|
||||
return this.browserCache;
|
||||
getDevice(): DeviceType {
|
||||
if (this.deviceCache) {
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
if (navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1) {
|
||||
this.browserCache = BrowserType.Firefox;
|
||||
this.deviceCache = DeviceType.Firefox;
|
||||
} else if ((!!(window as any).opr && !!opr.addons) || !!(window as any).opera ||
|
||||
navigator.userAgent.indexOf(' OPR/') >= 0) {
|
||||
this.browserCache = BrowserType.Opera;
|
||||
this.deviceCache = DeviceType.Opera;
|
||||
} else if (navigator.userAgent.indexOf(' Edge/') !== -1) {
|
||||
this.browserCache = BrowserType.Edge;
|
||||
this.deviceCache = DeviceType.Edge;
|
||||
} else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) {
|
||||
this.browserCache = BrowserType.Vivaldi;
|
||||
this.deviceCache = DeviceType.Vivaldi;
|
||||
} else if ((window as any).chrome) {
|
||||
this.browserCache = BrowserType.Chrome;
|
||||
this.deviceCache = DeviceType.Chrome;
|
||||
}
|
||||
|
||||
return this.browserCache;
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
getBrowserString(): string {
|
||||
return BrowserType[this.getBrowser()].toLowerCase();
|
||||
getDeviceString(): string {
|
||||
return DeviceType[this.getDevice()].toLowerCase();
|
||||
}
|
||||
|
||||
isFirefox(): boolean {
|
||||
return this.getBrowser() === BrowserType.Firefox;
|
||||
return this.getDevice() === DeviceType.Firefox;
|
||||
}
|
||||
|
||||
isChrome(): boolean {
|
||||
return this.getBrowser() === BrowserType.Chrome;
|
||||
return this.getDevice() === DeviceType.Chrome;
|
||||
}
|
||||
|
||||
isEdge(): boolean {
|
||||
return this.getBrowser() === BrowserType.Edge;
|
||||
return this.getDevice() === DeviceType.Edge;
|
||||
}
|
||||
|
||||
isOpera(): boolean {
|
||||
return this.getBrowser() === BrowserType.Opera;
|
||||
return this.getDevice() === DeviceType.Opera;
|
||||
}
|
||||
|
||||
isVivaldi(): boolean {
|
||||
return this.getBrowser() === BrowserType.Vivaldi;
|
||||
return this.getDevice() === DeviceType.Vivaldi;
|
||||
}
|
||||
|
||||
isSafari(): boolean {
|
||||
return this.getBrowser() === BrowserType.Safari;
|
||||
return this.getDevice() === DeviceType.Safari;
|
||||
}
|
||||
|
||||
analyticsId(): string {
|
||||
@ -106,7 +106,7 @@ export default class BrowserUtilsService implements BrowserUtilsServiceInterface
|
||||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
this.analyticsIdCache = AnalyticsIds[this.getBrowser()];
|
||||
this.analyticsIdCache = AnalyticsIds[this.getDevice()];
|
||||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
@ -215,11 +215,18 @@ export default class BrowserUtilsService implements BrowserUtilsServiceInterface
|
||||
|
||||
isViewOpen(): boolean {
|
||||
const popupOpen = chrome.extension.getViews({ type: 'popup' }).length > 0;
|
||||
const tabOpen = chrome.extension.getViews({ type: 'tab' }).length > 0;
|
||||
if (popupOpen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const sidebarView = this.sidebarViewName();
|
||||
const sidebarOpen = sidebarView != null && chrome.extension.getViews({ type: sidebarView }).length > 0;
|
||||
if (sidebarOpen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return popupOpen || tabOpen || sidebarOpen;
|
||||
const tabOpen = chrome.extension.getViews({ type: 'tab' }).length > 0;
|
||||
return tabOpen;
|
||||
}
|
||||
|
||||
private sidebarViewName(): string {
|
||||
|
Loading…
Reference in New Issue
Block a user