mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
Refactor for barrels. Utils service to jslib
This commit is contained in:
@@ -3,7 +3,8 @@ import BrowserApi from '../browser/browserApi';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import PasswordGenerationService from '../services/passwordGeneration.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
|
||||
export default class CommandsBackground {
|
||||
private commands: any;
|
||||
@@ -34,7 +35,7 @@ export default class CommandsBackground {
|
||||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = PasswordGenerationService.generatePassword(options);
|
||||
UtilsService.copyToClipboard(password);
|
||||
Services.UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
|
||||
@@ -4,7 +4,8 @@ import MainBackground from './main.background';
|
||||
|
||||
import CipherService from '../services/cipher.service';
|
||||
import PasswordGenerationService from '../services/passwordGeneration.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
|
||||
export default class ContextMenusBackground {
|
||||
private contextMenus: any;
|
||||
@@ -32,7 +33,7 @@ export default class ContextMenusBackground {
|
||||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = PasswordGenerationService.generatePassword(options);
|
||||
UtilsService.copyToClipboard(password);
|
||||
Services.UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
@@ -68,13 +69,13 @@ export default class ContextMenusBackground {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Username From Context Menu',
|
||||
});
|
||||
UtilsService.copyToClipboard(cipher.login.username);
|
||||
Services.UtilsService.copyToClipboard(cipher.login.username);
|
||||
} else if (info.parentMenuItemId === 'copy-password') {
|
||||
(window as any).ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Password From Context Menu',
|
||||
});
|
||||
UtilsService.copyToClipboard(cipher.login.password);
|
||||
Services.UtilsService.copyToClipboard(cipher.login.password);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -2,13 +2,13 @@ import ConstantsService from '../services/constants.service';
|
||||
import LockService from '../services/lock.service';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class IdleBackground {
|
||||
private idle: any;
|
||||
|
||||
constructor(private main: MainBackground, private lockService: LockService,
|
||||
private storageService: StorageService) {
|
||||
private storageService: Abstractions.StorageService) {
|
||||
this.idle = chrome.idle;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import { Cipher } from '../models/domain/cipher';
|
||||
|
||||
@@ -33,16 +33,13 @@ import SyncService from '../services/sync.service';
|
||||
import TokenService from '../services/token.service';
|
||||
import TotpService from '../services/totp.service';
|
||||
import UserService from '../services/user.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { MessagingService, PlatformUtilsService, StorageService } from '@bitwarden/jslib';
|
||||
|
||||
export default class MainBackground {
|
||||
messagingService: MessagingService;
|
||||
storageService: StorageService;
|
||||
messagingService: Abstractions.MessagingService;
|
||||
storageService: Abstractions.StorageService;
|
||||
i18nService: any;
|
||||
platformUtilsService: PlatformUtilsService;
|
||||
utilsService: UtilsService;
|
||||
platformUtilsService: Abstractions.PlatformUtilsService;
|
||||
utilsService: Abstractions.UtilsService;
|
||||
constantsService: ConstantsService;
|
||||
cryptoService: CryptoService;
|
||||
tokenService: TokenService;
|
||||
@@ -80,7 +77,7 @@ export default class MainBackground {
|
||||
|
||||
constructor() {
|
||||
// Services
|
||||
this.utilsService = new UtilsService();
|
||||
this.utilsService = new Services.UtilsService();
|
||||
this.platformUtilsService = new BrowserPlatformUtilsService();
|
||||
this.messagingService = new BrowserMessagingService(this.platformUtilsService);
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService);
|
||||
@@ -348,7 +345,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
private async loadLoginContextMenuOptions(cipher: any) {
|
||||
if (cipher == null || cipher.type !== CipherType.Login) {
|
||||
if (cipher == null || cipher.type !== Enums.CipherType.Login) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -365,7 +362,7 @@ export default class MainBackground {
|
||||
|
||||
private async loadContextMenuOptions(title: string, idSuffix: string, cipher: any) {
|
||||
if (!chrome.contextMenus || this.menuOptionsLoaded.indexOf(idSuffix) > -1 ||
|
||||
(cipher != null && cipher.type !== CipherType.Login)) {
|
||||
(cipher != null && cipher.type !== Enums.CipherType.Login)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import BrowserApi from '../browser/browserApi';
|
||||
|
||||
@@ -6,9 +6,6 @@ import MainBackground from './main.background';
|
||||
|
||||
import AutofillService from '../services/autofill.service';
|
||||
import CipherService from '../services/cipher.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
|
||||
export default class RuntimeBackground {
|
||||
private runtime: any;
|
||||
@@ -16,7 +13,7 @@ export default class RuntimeBackground {
|
||||
private pageDetailsToAutoFill: any[] = [];
|
||||
|
||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService) {
|
||||
private cipherService: CipherService, private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
this.runtime = chrome.runtime;
|
||||
}
|
||||
|
||||
@@ -149,7 +146,7 @@ export default class RuntimeBackground {
|
||||
favorite: false,
|
||||
name: loginInfo.name,
|
||||
notes: null,
|
||||
type: CipherType.Login,
|
||||
type: Enums.CipherType.Login,
|
||||
login: {
|
||||
uri: loginInfo.uri,
|
||||
username: loginInfo.username,
|
||||
@@ -180,7 +177,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
this.main.loginsToAdd.splice(i, 1);
|
||||
const hostname = UtilsService.getHostname(tab.url);
|
||||
const hostname = Services.UtilsService.getHostname(tab.url);
|
||||
await this.cipherService.saveNeverDomain(hostname);
|
||||
BrowserApi.tabSendMessage(tab, 'closeNotificationBar');
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import CipherService from '../services/cipher.service';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class WebRequestBackground {
|
||||
private pendingAuthRequests: any[] = [];
|
||||
private webRequest: any;
|
||||
private isFirefox: boolean;
|
||||
|
||||
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService) {
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private cipherService: CipherService) {
|
||||
this.webRequest = (window as any).chrome.webRequest;
|
||||
this.isFirefox = platformUtilsService.isFirefox();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user