BEEEP: Refactor services DI (#2201)

This commit is contained in:
Oscar Hinton 2021-12-06 11:21:07 +00:00 committed by GitHub
parent 616b2e139a
commit 3eb860f464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 55 additions and 57 deletions

2
jslib

@ -1 +1 @@
Subproject commit 78429aa7201989ad74a9ca36cc6832fcce0d4aee
Subproject commit 5db94cc9d06ba478a29e9b625993108dfa0d7ec8

View File

@ -21,8 +21,8 @@
"dist:safari:mas": "npm run build:prod && gulp dist:safari:mas",
"dist:safari:masdev": "npm run build:prod && gulp dist:safari:masdev",
"dist:safari:dmg": "npm run build:prod && gulp dist:safari:dmg",
"lint": "tslint src/**/*.ts",
"lint:fix": "tslint src/**/*.ts --fix",
"lint": "tslint 'src/**/*.ts'",
"lint:fix": "tslint 'src/**/*.ts' --fix",
"test": "karma start --single-run",
"test:watch": "karma start"
},

View File

@ -9,6 +9,7 @@ import { TwoFactorProviderType } from 'jslib-common/enums/twoFactorProviderType'
import { ApiService } from 'jslib-common/abstractions/api.service';
import { AuthService } from 'jslib-common/abstractions/auth.service';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@ -18,8 +19,6 @@ import { StateService } from 'jslib-common/abstractions/state.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
import { SyncService } from 'jslib-common/abstractions/sync.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { TwoFactorComponent as BaseTwoFactorComponent } from 'jslib-angular/components/two-factor.component';
import { PopupUtilsService } from '../services/popup-utils.service';

View File

@ -22,9 +22,8 @@ import {
RouterOutlet,
} from '@angular/router';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { AuthService } from 'jslib-common/abstractions/auth.service';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';

View File

@ -12,6 +12,7 @@ import { SendView } from 'jslib-common/models/view/sendView';
import { SendComponent as BaseSendComponent } from 'jslib-angular/components/send/send.component';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@ -23,8 +24,6 @@ import { StateService } from 'jslib-common/abstractions/state.service';
import { SyncService } from 'jslib-common/abstractions/sync.service';
import { UserService } from 'jslib-common/abstractions/user.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { PopupUtilsService } from '../services/popup-utils.service';
import { SendType } from 'jslib-common/enums/sendType';

View File

@ -17,6 +17,7 @@ import { SendView } from 'jslib-common/models/view/sendView';
import { SendComponent as BaseSendComponent } from 'jslib-angular/components/send/send.component';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@ -27,8 +28,6 @@ import { SendService } from 'jslib-common/abstractions/send.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { UserService } from 'jslib-common/abstractions/user.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { PopupUtilsService } from '../services/popup-utils.service';
import { SendType } from 'jslib-common/enums/sendType';

View File

@ -6,7 +6,7 @@ import {
Router,
} from '@angular/router';
import { UnauthGuardService } from './unauth-guard.service';
import { UnauthGuardService } from 'jslib-angular/services/unauth-guard.service';
@Injectable()
export class LaunchGuardService implements CanActivate {

View File

@ -4,18 +4,15 @@ import {
NgModule,
} from '@angular/core';
import { ToasterModule } from 'angular2-toaster';
import { DebounceNavigationService } from './debounceNavigationService';
import { LaunchGuardService } from './launch-guard.service';
import { LockGuardService } from './lock-guard.service';
import { PasswordRepromptService } from './password-reprompt.service';
import { UnauthGuardService } from './unauth-guard.service';
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { ModalService } from 'jslib-angular/services/modal.service';
import { ValidationService } from 'jslib-angular/services/validation.service';
import { JslibServicesModule } from 'jslib-angular/services/jslib-services.module';
import { LockGuardService as BaseLockGuardService } from 'jslib-angular/services/lock-guard.service';
import { UnauthGuardService as BaseUnauthGuardService } from 'jslib-angular/services/unauth-guard.service';
import { BrowserApi } from '../../browser/browserApi';
@ -76,14 +73,9 @@ function getBgService<T>(service: string) {
const isPrivateMode = BrowserApi.getBackgroundPage() == null;
const stateService = new StateService();
const messagingService = new BrowserMessagingService();
const logService = getBgService<ConsoleLogService>('logService')();
const searchService = isPrivateMode ? null : new PopupSearchService(getBgService<SearchService>('searchService')(),
getBgService<CipherService>('cipherService')(), logService, getBgService<I18nService>('i18nService')());
export function initFactory(platformUtilsService: PlatformUtilsService, i18nService: I18nService, storageService: StorageService,
popupUtilsService: PopupUtilsService): Function {
export function initFactory(platformUtilsService: PlatformUtilsService, i18nService: I18nService,
storageService: StorageService, popupUtilsService: PopupUtilsService, stateService: StateServiceAbstraction,
logService: LogServiceAbstraction): Function {
return async () => {
if (!popupUtilsService.inPopup(window)) {
window.document.body.classList.add('body-full');
@ -130,23 +122,48 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
@NgModule({
imports: [
ToasterModule,
JslibServicesModule,
],
declarations: [],
providers: [
ValidationService,
AuthGuardService,
LockGuardService,
{
provide: LOCALE_ID,
useFactory: () => isPrivateMode ? null : getBgService<I18nService>('i18nService')().translationLocale,
deps: [],
},
{
provide: APP_INITIALIZER,
useFactory: initFactory,
deps: [
PlatformUtilsService,
I18nService,
StorageService,
PopupUtilsService,
StateServiceAbstraction,
LogServiceAbstraction,
],
multi: true,
},
LaunchGuardService,
UnauthGuardService,
{ provide: BaseLockGuardService, useClass: LockGuardService },
{ provide: BaseUnauthGuardService, useClass: UnauthGuardService },
DebounceNavigationService,
PopupUtilsService,
BroadcasterService,
ModalService,
{ provide: MessagingService, useValue: messagingService },
{ provide: MessagingService, useClass: BrowserMessagingService },
{ provide: AuthServiceAbstraction, useFactory: getBgService<AuthService>('authService'), deps: [] },
{ provide: StateServiceAbstraction, useValue: stateService },
{ provide: SearchServiceAbstraction, useValue: searchService },
{ provide: StateServiceAbstraction, useClass: StateService },
{
provide: SearchServiceAbstraction,
useFactory: (cipherService: CipherService, logService: ConsoleLogService, i18nService: I18nService) => {
return isPrivateMode ? null : new PopupSearchService(getBgService<SearchService>('searchService')(),
cipherService, logService, i18nService);
},
deps: [
CipherService,
LogServiceAbstraction,
I18nService,
],
},
{ provide: AuditService, useFactory: getBgService<AuditService>('auditService'), deps: [] },
{ provide: FileUploadService, useFactory: getBgService<FileUploadService>('fileUploadService'), deps: [] },
{ provide: CipherService, useFactory: getBgService<CipherService>('cipherService'), deps: [] },
@ -200,17 +217,7 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
useFactory: getBgService<NotificationsService>('notificationsService'),
deps: [],
},
{
provide: APP_INITIALIZER,
useFactory: initFactory,
deps: [PlatformUtilsService, I18nService, StorageService, PopupUtilsService],
multi: true,
},
{
provide: LOCALE_ID,
useFactory: () => isPrivateMode ? null : getBgService<I18nService>('i18nService')().translationLocale,
deps: [],
},
{ provide: LogServiceAbstraction, useFactory: getBgService<ConsoleLogService>('logService'), deps: [] },
{ provide: PasswordRepromptServiceAbstraction, useClass: PasswordRepromptService },
],
})

View File

@ -9,12 +9,11 @@ import { Router } from '@angular/router';
import { ConstantsService } from 'jslib-common/services/constants.service';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { BrowserApi } from '../../browser/browserApi';
import { Utils } from 'jslib-common/misc/utils';

View File

@ -15,6 +15,7 @@ import { first } from 'rxjs/operators';
import { BrowserApi } from '../../browser/browserApi';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service';
import { FolderService } from 'jslib-common/abstractions/folder.service';
@ -31,8 +32,6 @@ import { FolderView } from 'jslib-common/models/view/folderView';
import { TreeNode } from 'jslib-common/models/domain/treeNode';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { CiphersComponent as BaseCiphersComponent } from 'jslib-angular/components/ciphers.component';
import { PopupUtilsService } from '../services/popup-utils.service';

View File

@ -12,13 +12,12 @@ import { ToasterService } from 'angular2-toaster';
import { BrowserApi } from '../../browser/browserApi';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType';
import { CipherType } from 'jslib-common/enums/cipherType';
import { CipherView } from 'jslib-common/models/view/cipherView';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service';

View File

@ -21,6 +21,7 @@ import { CipherView } from 'jslib-common/models/view/cipherView';
import { CollectionView } from 'jslib-common/models/view/collectionView';
import { FolderView } from 'jslib-common/models/view/folderView';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service';
import { FolderService } from 'jslib-common/abstractions/folder.service';
@ -31,8 +32,6 @@ import { StorageService } from 'jslib-common/abstractions/storage.service';
import { SyncService } from 'jslib-common/abstractions/sync.service';
import { UserService } from 'jslib-common/abstractions/user.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { GroupingsComponent as BaseGroupingsComponent } from 'jslib-angular/components/groupings.component';
import { PopupUtilsService } from '../services/popup-utils.service';

View File

@ -13,6 +13,7 @@ import { first } from 'rxjs/operators';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { AuditService } from 'jslib-common/abstractions/audit.service';
import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EventService } from 'jslib-common/abstractions/event.service';
@ -25,8 +26,6 @@ import { TokenService } from 'jslib-common/abstractions/token.service';
import { TotpService } from 'jslib-common/abstractions/totp.service';
import { UserService } from 'jslib-common/abstractions/user.service';
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { Cipher } from 'jslib-common/models/domain/cipher';
import { LoginUriView } from 'jslib-common/models/view/loginUriView';