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

2
jslib

@ -1 +1 @@
Subproject commit 5e7115f78d8a87b241a43fdcd6d53b67ccf0b605
Subproject commit 0fa9fc58eb82c98fedc729eef30521c88e105520

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');
}

View File

@ -34,7 +34,6 @@ import { SyncService } from 'jslib/abstractions/sync.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { TotpService } from 'jslib/abstractions/totp.service';
import { UserService } from 'jslib/abstractions/user.service';
import { UtilsService } from 'jslib/abstractions/utils.service';
import { AutofillService } from '../../services/abstractions/autofill.service';
import BrowserMessagingService from '../../services/browserMessaging.service';
@ -113,7 +112,6 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer
{ provide: TotpService, useFactory: getBgService<TotpService>('totpService'), deps: [] },
{ provide: TokenService, useFactory: getBgService<TokenService>('tokenService'), deps: [] },
{ provide: I18nService, useFactory: getBgService<I18nService>('i18nService'), deps: [] },
{ provide: UtilsService, useFactory: getBgService<UtilsService>('utilsService'), deps: [] },
{ provide: CryptoService, useFactory: getBgService<CryptoService>('cryptoService'), deps: [] },
{
provide: PlatformUtilsService,

View File

@ -22,12 +22,13 @@ import { CipherService } from 'jslib/abstractions/cipher.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SyncService } from 'jslib/abstractions/sync.service';
import { UtilsService } from 'jslib/abstractions/utils.service';
import { AutofillService } from '../../services/abstractions/autofill.service';
import { PopupUtilsService } from '../services/popup-utils.service';
import { Utils } from 'jslib/misc/utils';
const BroadcasterSubscriptionId = 'CurrentTabComponent';
@Component({
@ -55,8 +56,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
private analytics: Angulartics2, private toasterService: ToasterService,
private i18nService: I18nService, private router: Router,
private ngZone: NgZone, private broadcasterService: BroadcasterService,
private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService,
private utilsService: UtilsService) { }
private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService) { }
async ngOnInit() {
this.showLeftHeader = !this.platformUtilsService.isSafari();
@ -187,7 +187,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
return;
}
this.hostname = this.utilsService.getHostname(this.url);
this.hostname = Utils.getHostname(this.url);
BrowserApi.tabSendMessage(tab, {
command: 'collectPageDetails',
tab: tab,

View File

@ -9,8 +9,6 @@ import AutofillScript from '../models/autofillScript';
import { BrowserApi } from '../browser/browserApi';
import { UtilsService } from 'jslib/services';
import { AutofillService as AutofillServiceInterface } from './abstractions/autofill.service';
import {
@ -18,7 +16,6 @@ import {
PlatformUtilsService,
TokenService,
TotpService,
UtilsService as UtilsServiceAbstraction,
} from 'jslib/abstractions';
const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag',

View File

@ -7,8 +7,6 @@ import { DeviceType } from 'jslib/enums/deviceType';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { UtilsService } from 'jslib/services/utils.service';
const AnalyticsIds = {
[DeviceType.Chrome]: 'UA-81915606-6',
[DeviceType.Firefox]: 'UA-81915606-7',
@ -194,8 +192,28 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
}
copyToClipboard(text: string, options?: any): void {
const doc = options ? options.doc : null;
UtilsService.copyToClipboard(text, doc);
const doc = options ? options.doc : window.document;
if ((window as any).clipboardData && (window as any).clipboardData.setData) {
// IE specific code path to prevent textarea being shown while dialog is visible.
(window as any).clipboardData.setData('Text', text);
} else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
const textarea = doc.createElement('textarea');
textarea.textContent = text;
// Prevent scrolling to bottom of page in MS Edge.
textarea.style.position = 'fixed';
doc.body.appendChild(textarea);
textarea.select();
try {
// Security exception may be thrown by some browsers.
doc.execCommand('copy');
} catch (e) {
// tslint:disable-next-line
console.warn('Copy to clipboard failed.', e);
} finally {
doc.body.removeChild(textarea);
}
}
}
resolveDialogPromise(dialogId: number, confirmed: boolean) {