diff --git a/jslib b/jslib index f16fc58d70..9ba3c17626 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit f16fc58d707b9ed55355e62440fb95185f972090 +Subproject commit 9ba3c176262b7d06209998305ab73d91c3e72458 diff --git a/src/popup/services/popup-search.service.ts b/src/popup/services/popup-search.service.ts new file mode 100644 index 0000000000..fee1bab3e9 --- /dev/null +++ b/src/popup/services/popup-search.service.ts @@ -0,0 +1,23 @@ +import { CipherService } from 'jslib/abstractions/cipher.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; + +import { SearchService } from 'jslib/services/search.service'; + +export class PopupSearchService extends SearchService { + constructor(private mainSearchService: SearchService, cipherService: CipherService, + platformUtilsService: PlatformUtilsService) { + super(cipherService, platformUtilsService); + } + + clearIndex() { + throw new Error('Not available.'); + } + + indexCiphers(): Promise { + throw new Error('Not available.'); + } + + getIndexForSearch() { + return this.mainSearchService.getIndexForSearch(); + } +} diff --git a/src/popup/services/services.module.ts b/src/popup/services/services.module.ts index 9f510d9465..0f6a3e54c6 100644 --- a/src/popup/services/services.module.ts +++ b/src/popup/services/services.module.ts @@ -29,7 +29,7 @@ import { LockService } from 'jslib/abstractions/lock.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; -import { SearchService } from 'jslib/abstractions/search.service'; +import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service'; import { SettingsService } from 'jslib/abstractions/settings.service'; import { StateService as StateServiceAbstraction } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; @@ -43,10 +43,12 @@ import BrowserMessagingService from '../../services/browserMessaging.service'; import { AuthService } from 'jslib/services/auth.service'; import { ConstantsService } from 'jslib/services/constants.service'; +import { SearchService } from 'jslib/services/search.service'; import { StateService } from 'jslib/services/state.service'; import { Analytics } from 'jslib/misc/analytics'; +import { PopupSearchService } from './popup-search.service'; import { PopupUtilsService } from './popup-utils.service'; function getBgService(service: string) { @@ -63,6 +65,8 @@ export const authService = new AuthService(getBgService('cryptoSe getBgService('tokenService')(), getBgService('appIdService')(), getBgService('i18nService')(), getBgService('platformUtilsService')(), messagingService); +export const searchService = new PopupSearchService(getBgService('searchService')(), + getBgService('cipherService')(), getBgService('platformUtilsService')()); export function initFactory(i18nService: I18nService, storageService: StorageService, popupUtilsService: PopupUtilsService): Function { @@ -113,6 +117,7 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer { provide: MessagingService, useValue: messagingService }, { provide: AuthServiceAbstraction, useValue: authService }, { provide: StateServiceAbstraction, useValue: stateService }, + { provide: SearchServiceAbstraction, useValue: searchService }, { provide: AuditService, useFactory: getBgService('auditService'), deps: [] }, { provide: CipherService, useFactory: getBgService('cipherService'), deps: [] }, { provide: FolderService, useFactory: getBgService('folderService'), deps: [] }, @@ -141,7 +146,6 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer { provide: AppIdService, useFactory: getBgService('appIdService'), deps: [] }, { provide: AutofillService, useFactory: getBgService('autofillService'), deps: [] }, { provide: ExportService, useFactory: getBgService('exportService'), deps: [] }, - { provide: SearchService, useFactory: getBgService('searchService'), deps: [] }, { provide: APP_INITIALIZER, useFactory: initFactory, diff --git a/src/popup/vault/groupings.component.ts b/src/popup/vault/groupings.component.ts index e08dbb7dd5..2edc7eae56 100644 --- a/src/popup/vault/groupings.component.ts +++ b/src/popup/vault/groupings.component.ts @@ -62,6 +62,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit private searchTimeout: any = null; private hasSearched = false; private hasLoadedAllCiphers = false; + private allCiphers: CipherView[] = null; constructor(collectionService: CollectionService, folderService: FolderService, private cipherService: CipherService, private router: Router, @@ -154,6 +155,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit } async loadCiphers() { + this.allCiphers = await this.cipherService.getAllDecrypted(); if (!this.hasLoadedAllCiphers) { this.hasLoadedAllCiphers = !this.searchService.isSearchable(this.searchText); } @@ -216,7 +218,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit } if (timeout == null) { this.hasSearched = this.searchService.isSearchable(this.searchText); - this.ciphers = await this.searchService.searchCiphers(this.searchText, null); + this.ciphers = await this.searchService.searchCiphers(this.searchText, null, this.allCiphers); return; } this.searchPending = true; @@ -225,7 +227,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit if (!this.hasLoadedAllCiphers && !this.hasSearched) { await this.loadCiphers(); } else { - this.ciphers = await this.searchService.searchCiphers(this.searchText, null); + this.ciphers = await this.searchService.searchCiphers(this.searchText, null, this.allCiphers); } this.searchPending = false; }, timeout);