1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

refactor utils service to utils

This commit is contained in:
Kyle Spearrin
2018-04-23 13:04:11 -04:00
parent 97835f7627
commit c67b63a452
9 changed files with 41 additions and 33 deletions

View File

@@ -9,8 +9,6 @@ import {
PlatformUtilsService,
} from 'jslib/abstractions';
import { UtilsService } from 'jslib/services/utils.service';
export default class CommandsBackground {
private commands: any;
private isSafari: boolean;
@@ -67,7 +65,7 @@ export default class CommandsBackground {
const options = await this.passwordGenerationService.getOptions();
const password = await this.passwordGenerationService.generatePassword(options);
UtilsService.copyToClipboard(password);
this.platformUtilsService.copyToClipboard(password);
this.passwordGenerationService.addHistory(password);
this.analytics.ga('send', {

View File

@@ -7,15 +7,15 @@ import { Analytics } from 'jslib/misc';
import {
CipherService,
PasswordGenerationService,
PlatformUtilsService,
} from 'jslib/abstractions';
import { UtilsService } from 'jslib/services/utils.service';
export default class ContextMenusBackground {
private contextMenus: any;
constructor(private main: MainBackground, private cipherService: CipherService,
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics) {
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
private platformUtilsService: PlatformUtilsService) {
this.contextMenus = chrome.contextMenus;
}
@@ -36,8 +36,8 @@ export default class ContextMenusBackground {
private async generatePasswordToClipboard() {
const options = await this.passwordGenerationService.getOptions();
const password = this.passwordGenerationService.generatePassword(options);
UtilsService.copyToClipboard(password);
const password = await this.passwordGenerationService.generatePassword(options);
this.platformUtilsService.copyToClipboard(password);
this.passwordGenerationService.addHistory(password);
this.analytics.ga('send', {
@@ -73,13 +73,13 @@ export default class ContextMenusBackground {
hitType: 'event',
eventAction: 'Copied Username From Context Menu',
});
UtilsService.copyToClipboard(cipher.login.username);
this.platformUtilsService.copyToClipboard(cipher.login.username);
} else if (info.parentMenuItemId === 'copy-password') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Copied Password From Context Menu',
});
UtilsService.copyToClipboard(cipher.login.password);
this.platformUtilsService.copyToClipboard(cipher.login.password);
}
break;

View File

@@ -18,7 +18,6 @@ import {
TokenService,
TotpService,
UserService,
UtilsService,
} from 'jslib/services';
import { WebCryptoFunctionService } from 'jslib/services/webCryptoFunction.service';
@@ -42,7 +41,6 @@ import {
TokenService as TokenServiceAbstraction,
TotpService as TotpServiceAbstraction,
UserService as UserServiceAbstraction,
UtilsService as UtilsServiceAbstraction,
} from 'jslib/abstractions';
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from 'jslib/abstractions/cryptoFunction.service';
@@ -72,7 +70,6 @@ export default class MainBackground {
secureStorageService: StorageServiceAbstraction;
i18nService: I18nServiceAbstraction;
platformUtilsService: PlatformUtilsServiceAbstraction;
utilsService: UtilsServiceAbstraction;
constantsService: ConstantsService;
cryptoService: CryptoServiceAbstraction;
tokenService: TokenServiceAbstraction;
@@ -114,7 +111,6 @@ export default class MainBackground {
constructor() {
// Services
this.utilsService = new UtilsService();
this.messagingService = new BrowserMessagingService();
this.platformUtilsService = new BrowserPlatformUtilsService(this.messagingService);
this.storageService = new BrowserStorageService(this.platformUtilsService, false);
@@ -131,7 +127,7 @@ export default class MainBackground {
this.userService = new UserService(this.tokenService, this.storageService);
this.settingsService = new SettingsService(this.userService, this.storageService);
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
this.apiService, this.storageService, this.i18nService, this.platformUtilsService, this.utilsService);
this.apiService, this.storageService, this.i18nService, this.platformUtilsService);
this.folderService = new FolderService(this.cryptoService, this.userService,
() => this.i18nService.t('noneFolder'), this.apiService, this.storageService, this.i18nService);
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
@@ -168,7 +164,7 @@ export default class MainBackground {
if (!this.isSafari) {
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
this.passwordGenerationService, this.analytics);
this.passwordGenerationService, this.analytics, this.platformUtilsService);
this.idleBackground = new IdleBackground(this, this.lockService, this.storageService);
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService);
this.windowsBackground = new WindowsBackground(this);

View File

@@ -5,7 +5,6 @@ import { LoginUriView } from 'jslib/models/view/loginUriView';
import { LoginView } from 'jslib/models/view/loginView';
import { ConstantsService } from 'jslib/services/constants.service';
import { UtilsService } from 'jslib/services/utils.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
@@ -23,6 +22,8 @@ import MainBackground from './main.background';
import { AutofillService } from '../services/abstractions/autofill.service';
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
import { Utils } from 'jslib/misc/utils';
export default class RuntimeBackground {
private runtime: any;
private autofillTimeout: any;
@@ -200,7 +201,7 @@ export default class RuntimeBackground {
loginModel.username = loginInfo.username;
loginModel.password = loginInfo.password;
const model = new CipherView();
model.name = UtilsService.getHostname(loginInfo.uri) || loginInfo.domain;
model.name = Utils.getHostname(loginInfo.uri) || loginInfo.domain;
model.type = CipherType.Login;
model.login = loginModel;
@@ -228,7 +229,7 @@ export default class RuntimeBackground {
}
this.main.loginsToAdd.splice(i, 1);
const hostname = UtilsService.getHostname(tab.url);
const hostname = Utils.getHostname(tab.url);
await this.cipherService.saveNeverDomain(hostname);
BrowserApi.tabSendMessageData(tab, 'closeNotificationBar');
}