Initial swap from activeAccount to stateService

This commit is contained in:
Robyn MacCallum 2021-11-12 16:11:38 -05:00
parent 85e3436de6
commit d476d4961a
39 changed files with 282 additions and 317 deletions

View File

@ -249,7 +249,7 @@
"message": "View" "message": "View"
}, },
"noItemsInList": { "noItemsInList": {
"message": "There are no items to list." "message": "There are no items to list. :D"
}, },
"itemInformation": { "itemInformation": {
"message": "Item Information" "message": "Item Information"

View File

@ -1,9 +1,7 @@
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { NotificationsService } from 'jslib-common/abstractions/notifications.service'; import { NotificationsService } from 'jslib-common/abstractions/notifications.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service'; import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
import { StorageKey } from 'jslib-common/enums/storageKey';
const IdleInterval = 60 * 5; // 5 minutes const IdleInterval = 60 * 5; // 5 minutes
export default class IdleBackground { export default class IdleBackground {
@ -11,7 +9,7 @@ export default class IdleBackground {
private idleTimer: number = null; private idleTimer: number = null;
private idleState = 'active'; private idleState = 'active';
constructor(private vaultTimeoutService: VaultTimeoutService, private activeAccount: ActiveAccountService, constructor(private vaultTimeoutService: VaultTimeoutService, private stateService: StateService,
private notificationsService: NotificationsService) { private notificationsService: NotificationsService) {
this.idle = chrome.idle || (browser != null ? browser.idle : null); this.idle = chrome.idle || (browser != null ? browser.idle : null);
} }
@ -38,9 +36,9 @@ export default class IdleBackground {
if (this.idle.onStateChanged) { if (this.idle.onStateChanged) {
this.idle.onStateChanged.addListener(async (newState: string) => { this.idle.onStateChanged.addListener(async (newState: string) => {
if (newState === 'locked') { // If the screen is locked or the screensaver activates if (newState === 'locked') { // If the screen is locked or the screensaver activates
const timeout = await this.activeAccount.getInformation<number>(StorageKey.VaultTimeout); const timeout = await this.stateService.getVaultTimeout();
if (timeout === -2) { // On System Lock vault timeout option if (timeout === -2) { // On System Lock vault timeout option
const action = await this.activeAccount.getInformation<string>(StorageKey.VaultTimeoutAction); const action = await this.stateService.getVaultTimeoutAction();
if (action === 'logOut') { if (action === 'logOut') {
await this.vaultTimeoutService.logOut(); await this.vaultTimeoutService.logOut();
} else { } else {

View File

@ -1,9 +1,6 @@
import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType'; import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType';
import { CipherType } from 'jslib-common/enums/cipherType'; import { CipherType } from 'jslib-common/enums/cipherType';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { AccountsManagementService } from 'jslib-common/services/accountsManagement.service';
import { ActiveAccountService } from 'jslib-common/services/activeAccount.service';
import { ApiService } from 'jslib-common/services/api.service'; import { ApiService } from 'jslib-common/services/api.service';
import { AppIdService } from 'jslib-common/services/appId.service'; import { AppIdService } from 'jslib-common/services/appId.service';
import { AuditService } from 'jslib-common/services/audit.service'; import { AuditService } from 'jslib-common/services/audit.service';
@ -17,6 +14,7 @@ import { EventService } from 'jslib-common/services/event.service';
import { ExportService } from 'jslib-common/services/export.service'; import { ExportService } from 'jslib-common/services/export.service';
import { FileUploadService } from 'jslib-common/services/fileUpload.service'; import { FileUploadService } from 'jslib-common/services/fileUpload.service';
import { FolderService } from 'jslib-common/services/folder.service'; import { FolderService } from 'jslib-common/services/folder.service';
import { KeyConnectorService } from 'jslib-common/services/keyConnector.service';
import { NotificationsService } from 'jslib-common/services/notifications.service'; import { NotificationsService } from 'jslib-common/services/notifications.service';
import { OrganizationService } from 'jslib-common/services/organization.service'; import { OrganizationService } from 'jslib-common/services/organization.service';
import { PasswordGenerationService } from 'jslib-common/services/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib-common/services/passwordGeneration.service';
@ -26,15 +24,12 @@ import { SearchService } from 'jslib-common/services/search.service';
import { SendService } from 'jslib-common/services/send.service'; import { SendService } from 'jslib-common/services/send.service';
import { SettingsService } from 'jslib-common/services/settings.service'; import { SettingsService } from 'jslib-common/services/settings.service';
import { StateService } from 'jslib-common/services/state.service'; import { StateService } from 'jslib-common/services/state.service';
import { StoreService } from 'jslib-common/services/store.service';
import { SyncService } from 'jslib-common/services/sync.service'; import { SyncService } from 'jslib-common/services/sync.service';
import { SystemService } from 'jslib-common/services/system.service'; import { SystemService } from 'jslib-common/services/system.service';
import { TokenService } from 'jslib-common/services/token.service'; import { TokenService } from 'jslib-common/services/token.service';
import { TotpService } from 'jslib-common/services/totp.service'; import { TotpService } from 'jslib-common/services/totp.service';
import { WebCryptoFunctionService } from 'jslib-common/services/webCryptoFunction.service'; import { WebCryptoFunctionService } from 'jslib-common/services/webCryptoFunction.service';
import { AccountsManagementService as AccountsManagementServiceAbstraction } from 'jslib-common/abstractions/accountsManagement.service';
import { ActiveAccountService as ActiveAccountServiceAbstraction } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService as ApiServiceAbstraction } from 'jslib-common/abstractions/api.service'; import { ApiService as ApiServiceAbstraction } from 'jslib-common/abstractions/api.service';
import { AppIdService as AppIdServiceAbstraction } from 'jslib-common/abstractions/appId.service'; import { AppIdService as AppIdServiceAbstraction } from 'jslib-common/abstractions/appId.service';
import { AuditService as AuditServiceAbstraction } from 'jslib-common/abstractions/audit.service'; import { AuditService as AuditServiceAbstraction } from 'jslib-common/abstractions/audit.service';
@ -49,6 +44,7 @@ import { ExportService as ExportServiceAbstraction } from 'jslib-common/abstract
import { FileUploadService as FileUploadServiceAbstraction } from 'jslib-common/abstractions/fileUpload.service'; import { FileUploadService as FileUploadServiceAbstraction } from 'jslib-common/abstractions/fileUpload.service';
import { FolderService as FolderServiceAbstraction } from 'jslib-common/abstractions/folder.service'; import { FolderService as FolderServiceAbstraction } from 'jslib-common/abstractions/folder.service';
import { I18nService as I18nServiceAbstraction } from 'jslib-common/abstractions/i18n.service'; import { I18nService as I18nServiceAbstraction } from 'jslib-common/abstractions/i18n.service';
import { KeyConnectorService as KeyConnectorServiceAbstraction } from 'jslib-common/abstractions/keyConnector.service';
import { LogService as LogServiceAbstraction } from 'jslib-common/abstractions/log.service'; import { LogService as LogServiceAbstraction } from 'jslib-common/abstractions/log.service';
import { MessagingService as MessagingServiceAbstraction } from 'jslib-common/abstractions/messaging.service'; import { MessagingService as MessagingServiceAbstraction } from 'jslib-common/abstractions/messaging.service';
import { NotificationsService as NotificationsServiceAbstraction } from 'jslib-common/abstractions/notifications.service'; import { NotificationsService as NotificationsServiceAbstraction } from 'jslib-common/abstractions/notifications.service';
@ -127,10 +123,9 @@ export default class MainBackground {
popupUtilsService: PopupUtilsService; popupUtilsService: PopupUtilsService;
sendService: SendServiceAbstraction; sendService: SendServiceAbstraction;
fileUploadService: FileUploadServiceAbstraction; fileUploadService: FileUploadServiceAbstraction;
activeAccount: ActiveAccountServiceAbstraction;
accountsManagementService: AccountsManagementServiceAbstraction;
organizationService: OrganizationServiceAbstraction; organizationService: OrganizationServiceAbstraction;
providerService: ProviderServiceAbstraction; providerService: ProviderServiceAbstraction;
keyConnectorSerivce: KeyConnectorServiceAbstraction;
onUpdatedRan: boolean; onUpdatedRan: boolean;
onReplacedRan: boolean; onReplacedRan: boolean;
@ -157,10 +152,8 @@ export default class MainBackground {
this.messagingService = new BrowserMessagingService(); this.messagingService = new BrowserMessagingService();
this.storageService = new BrowserStorageService(); this.storageService = new BrowserStorageService();
this.secureStorageService = new BrowserStorageService(); this.secureStorageService = new BrowserStorageService();
const storeService = new StoreService(this.storageService, this.secureStorageService); // const storeService = new StoreService(this.storageService, this.secureStorageService);
this.accountsManagementService = new AccountsManagementService(this.storageService, this.secureStorageService); this.platformUtilsService = new BrowserPlatformUtilsService(this.messagingService, this.stateService,
this.activeAccount = new ActiveAccountService(this.accountsManagementService, storeService);
this.platformUtilsService = new BrowserPlatformUtilsService(this.messagingService, this.activeAccount,
(clipboardValue, clearMs) => { (clipboardValue, clearMs) => {
if (this.systemService != null) { if (this.systemService != null) {
this.systemService.clearClipboard(clipboardValue, clearMs); this.systemService.clearClipboard(clipboardValue, clearMs);
@ -183,30 +176,32 @@ export default class MainBackground {
this.cryptoFunctionService = new WebCryptoFunctionService(window, this.platformUtilsService); this.cryptoFunctionService = new WebCryptoFunctionService(window, this.platformUtilsService);
this.logService = new ConsoleLogService(false); this.logService = new ConsoleLogService(false);
this.cryptoService = new BrowserCryptoService(this.cryptoFunctionService, this.platformUtilsService, this.cryptoService = new BrowserCryptoService(this.cryptoFunctionService, this.platformUtilsService,
this.logService, this.activeAccount); this.logService, this.stateService);
this.tokenService = new TokenService(this.activeAccount); this.tokenService = new TokenService(this.stateService);
this.appIdService = new AppIdService(this.storageService); this.appIdService = new AppIdService(this.storageService);
this.environmentService = new EnvironmentService(this.activeAccount); this.environmentService = new EnvironmentService(this.stateService);
this.apiService = new ApiService(this.tokenService, this.platformUtilsService, this.environmentService, this.apiService = new ApiService(this.tokenService, this.platformUtilsService, this.environmentService,
(expired: boolean) => this.logout(expired)); (expired: boolean) => this.logout(expired));
this.settingsService = new SettingsService(this.activeAccount); this.settingsService = new SettingsService(this.stateService);
this.fileUploadService = new FileUploadService(this.logService, this.apiService); this.fileUploadService = new FileUploadService(this.logService, this.apiService);
this.cipherService = new CipherService(this.cryptoService, this.settingsService, this.cipherService = new CipherService(this.cryptoService, this.settingsService,
this.apiService, this.fileUploadService, this.apiService, this.fileUploadService,
this.i18nService, () => this.searchService, this.i18nService, () => this.searchService,
this.activeAccount); this.logService, this.stateService);
this.folderService = new FolderService(this.cryptoService, this.apiService, this.folderService = new FolderService(this.cryptoService, this.apiService,
this.i18nService, this.cipherService, this.i18nService, this.cipherService,
this.activeAccount); this.stateService);
this.collectionService = new CollectionService(this.cryptoService, this.i18nService, this.collectionService = new CollectionService(this.cryptoService, this.i18nService,
this.activeAccount); this.stateService);
this.searchService = new SearchService(this.cipherService, this.logService, this.i18nService); this.searchService = new SearchService(this.cipherService, this.logService, this.i18nService);
this.sendService = new SendService(this.cryptoService, this.apiService, this.sendService = new SendService(this.cryptoService, this.apiService,
this.fileUploadService, this.i18nService, this.fileUploadService, this.i18nService,
this.cryptoFunctionService, this.activeAccount); this.cryptoFunctionService, this.stateService);
this.stateService = new StateService(); this.stateService = new StateService(this.storageService, this.secureStorageService, this.logService);
this.organizationService = new OrganizationService(this.activeAccount); this.organizationService = new OrganizationService(this.stateService);
this.policyService = new PolicyService(this.activeAccount, this.organizationService); this.policyService = new PolicyService(this.stateService, this.organizationService, this.apiService);
this.keyConnectorSerivce = new KeyConnectorService(this.stateService, this.cryptoService,
this.apiService, this.environmentService, this.tokenService, this.logService, this.organizationService);
const vaultTimeoutServiceCallbacks = { const vaultTimeoutServiceCallbacks = {
locked: async () => { locked: async () => {
@ -226,23 +221,23 @@ export default class MainBackground {
this.collectionService, this.cryptoService, this.collectionService, this.cryptoService,
this.platformUtilsService, this.messagingService, this.platformUtilsService, this.messagingService,
this.searchService, this.tokenService, this.searchService, this.tokenService,
this.policyService, this.activeAccount, this.policyService, this.keyConnectorSerivce, this.stateService,
vaultTimeoutServiceCallbacks.locked, vaultTimeoutServiceCallbacks.logout); vaultTimeoutServiceCallbacks.locked, vaultTimeoutServiceCallbacks.logout);
this.providerService = new ProviderService(this.activeAccount); this.providerService = new ProviderService(this.stateService);
this.syncService = new SyncService(this.apiService, this.settingsService, this.syncService = new SyncService(this.apiService, this.settingsService,
this.folderService, this.cipherService, this.folderService, this.cipherService,
this.cryptoService, this.collectionService, this.cryptoService, this.collectionService,
this.messagingService, this.policyService, this.messagingService, this.policyService,
this.sendService, async (expired: boolean) => await this.logout(expired), this.sendService, this.logService, this.keyConnectorSerivce,
this.activeAccount, this.organizationService, this.stateService, this.organizationService,
this.providerService); this.providerService, async (expired: boolean) => await this.logout(expired));
this.eventService = new EventService(this.apiService, this.cipherService, this.eventService = new EventService(this.apiService, this.cipherService,
this.activeAccount, this.organizationService); this.stateService, this.logService, this.organizationService);
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.policyService, this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.policyService,
this.activeAccount); this.stateService);
this.totpService = new TotpService(this.cryptoFunctionService, this.activeAccount); this.totpService = new TotpService(this.cryptoFunctionService, this.logService, this.stateService);
this.autofillService = new AutofillService(this.cipherService, this.activeAccount, this.autofillService = new AutofillService(this.cipherService, this.stateService,
this.totpService, this.eventService); this.totpService, this.eventService);
this.containerService = new ContainerService(this.cryptoService); this.containerService = new ContainerService(this.cryptoService);
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService); this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);
@ -251,7 +246,7 @@ export default class MainBackground {
this.notificationsService = new NotificationsService(this.syncService, this.appIdService, this.notificationsService = new NotificationsService(this.syncService, this.appIdService,
this.apiService, this.vaultTimeoutService, this.apiService, this.vaultTimeoutService,
this.environmentService, () => this.logout(true), this.environmentService, () => this.logout(true),
this.logService, this.activeAccount); this.logService, this.stateService);
this.popupUtilsService = new PopupUtilsService(this.platformUtilsService); this.popupUtilsService = new PopupUtilsService(this.platformUtilsService);
const systemUtilsServiceReloadCallback = () => { const systemUtilsServiceReloadCallback = () => {
@ -260,8 +255,8 @@ export default class MainBackground {
BrowserApi.reloadExtension(forceWindowReload ? window : null); BrowserApi.reloadExtension(forceWindowReload ? window : null);
return Promise.resolve(); return Promise.resolve();
}; };
this.systemService = new SystemService(this.vaultTimeoutService, this.systemService = new SystemService(
this.messagingService, this.platformUtilsService, systemUtilsServiceReloadCallback, this.activeAccount); this.messagingService, this.platformUtilsService, systemUtilsServiceReloadCallback, this.stateService);
// Other fields // Other fields
this.isSafari = this.platformUtilsService.isSafari(); this.isSafari = this.platformUtilsService.isSafari();
@ -270,23 +265,22 @@ export default class MainBackground {
// Background // Background
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService, this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.platformUtilsService as BrowserPlatformUtilsService,
this.i18nService, this.notificationsService, this.i18nService, this.notificationsService,
this.systemService, this.vaultTimeoutService, this.systemService, this.vaultTimeoutService,
this.environmentService, this.policyService, this.environmentService, this.policyService,
this.messagingService, this.folderService); this.messagingService, this.folderService, this.stateService);
this.nativeMessagingBackground = new NativeMessagingBackground(this.storageService, this.cryptoService, this.nativeMessagingBackground = new NativeMessagingBackground(this.cryptoService,
this.cryptoFunctionService, this.vaultTimeoutService, this.cryptoFunctionService, this.runtimeBackground,
this.runtimeBackground, this.i18nService, this.i18nService, this.messagingService, this.appIdService,
this.messagingService, this.appIdService, this.platformUtilsService, this.stateService);
this.platformUtilsService, this.activeAccount);
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService, this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
this.platformUtilsService, this.vaultTimeoutService); this.platformUtilsService, this.vaultTimeoutService);
this.tabsBackground = new TabsBackground(this); this.tabsBackground = new TabsBackground(this);
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService, this.passwordGenerationService, this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService, this.passwordGenerationService,
this.platformUtilsService, this.vaultTimeoutService, this.eventService, this.totpService); this.platformUtilsService, this.vaultTimeoutService, this.eventService, this.totpService);
this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.activeAccount, this.idleBackground = new IdleBackground(this.vaultTimeoutService, this.stateService,
this.notificationsService); this.notificationsService);
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService, this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
this.vaultTimeoutService); this.vaultTimeoutService);
@ -305,7 +299,7 @@ export default class MainBackground {
this.tokenService, this.appIdService, this.tokenService, this.appIdService,
this.i18nService, this.platformUtilsService, this.i18nService, this.platformUtilsService,
backgroundMessagingService, this.vaultTimeoutService, backgroundMessagingService, this.vaultTimeoutService,
this.logService, this.activeAccount, this.accountsManagementService); this.logService, this.cryptoFunctionService, this.keyConnectorSerivce, this.environmentService, this.stateService);
} }
async bootstrap() { async bootstrap() {
@ -341,7 +335,7 @@ export default class MainBackground {
return; return;
} }
const isAuthenticated = this.activeAccount.isAuthenticated; const isAuthenticated = await this.stateService.getIsAuthenticated();
const locked = await this.vaultTimeoutService.isLocked(); const locked = await this.vaultTimeoutService.isLocked();
let suffix = ''; let suffix = '';
@ -360,7 +354,7 @@ export default class MainBackground {
return; return;
} }
const menuDisabled = await this.storageService.get<boolean>(StorageKey.DisableContextMenuItem); const menuDisabled = await this.stateService.getDisableContextMenuItem();
if (!menuDisabled) { if (!menuDisabled) {
await this.buildContextMenu(); await this.buildContextMenu();
} else { } else {
@ -381,7 +375,7 @@ export default class MainBackground {
async logout(expired: boolean) { async logout(expired: boolean) {
await this.eventService.uploadEvents(); await this.eventService.uploadEvents();
const userId = this.activeAccount.userId; const userId = await this.stateService.getUserId();
await Promise.all([ await Promise.all([
this.eventService.clearEvents(), this.eventService.clearEvents(),
@ -461,7 +455,7 @@ export default class MainBackground {
return; return;
} }
const currentVaultTimeout = await this.storageService.get<number>(StorageKey.VaultTimeout); const currentVaultTimeout = await this.stateService.getVaultTimeout();
if (currentVaultTimeout == null) { if (currentVaultTimeout == null) {
return; return;
} }
@ -524,7 +518,7 @@ export default class MainBackground {
title: this.i18nService.t('copyPassword'), title: this.i18nService.t('copyPassword'),
}); });
if (this.activeAccount.canAccessPremium) { if (await this.stateService.getCanAccessPremium()) {
await this.contextMenusCreate({ await this.contextMenusCreate({
type: 'normal', type: 'normal',
id: 'copy-totp', id: 'copy-totp',
@ -584,7 +578,7 @@ export default class MainBackground {
}); });
} }
const disableBadgeCounter = await this.storageService.get<boolean>(StorageKey.DisableBadgeCounter); const disableBadgeCounter = await this.stateService.getDisableBadgeCounter();
let theText = ''; let theText = '';
if (!disableBadgeCounter) { if (!disableBadgeCounter) {
@ -611,7 +605,7 @@ export default class MainBackground {
private async loadMenuAndUpdateBadgeForNoAccessState(contextMenuEnabled: boolean) { private async loadMenuAndUpdateBadgeForNoAccessState(contextMenuEnabled: boolean) {
if (contextMenuEnabled) { if (contextMenuEnabled) {
const authed = this.activeAccount.isAuthenticated; const authed = await this.stateService.getIsAuthenticated();
await this.loadNoLoginsContextMenuOptions(this.i18nService.t(authed ? 'vaultLocked' : 'vaultLoggedOut')); await this.loadNoLoginsContextMenuOptions(this.i18nService.t(authed ? 'vaultLocked' : 'vaultLoggedOut'));
} }
@ -680,7 +674,7 @@ export default class MainBackground {
}); });
} }
const canAccessPremium = this.activeAccount.canAccessPremium; const canAccessPremium = await this.stateService.getCanAccessPremium();
if (canAccessPremium && (cipher == null || (cipher.login.totp && cipher.login.totp !== ''))) { if (canAccessPremium && (cipher == null || (cipher.login.totp && cipher.login.totp !== ''))) {
await this.contextMenusCreate({ await this.contextMenusCreate({
type: 'normal', type: 'normal',

View File

@ -1,15 +1,13 @@
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { AppIdService } from 'jslib-common/abstractions/appId.service'; import { AppIdService } from 'jslib-common/abstractions/appId.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { StorageService } from 'jslib-common/abstractions/storage.service'; import { StorageService } from 'jslib-common/abstractions/storage.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service'; import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { Utils } from 'jslib-common/misc/utils'; import { Utils } from 'jslib-common/misc/utils';
import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey'; import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey';
@ -32,24 +30,24 @@ export class NativeMessagingBackground {
private appId: string; private appId: string;
private validatingFingerprint: boolean; private validatingFingerprint: boolean;
constructor(private storageService: StorageService, private cryptoService: CryptoService, constructor(private cryptoService: CryptoService,
private cryptoFunctionService: CryptoFunctionService, private vaultTimeoutService: VaultTimeoutService, private cryptoFunctionService: CryptoFunctionService,
private runtimeBackground: RuntimeBackground, private i18nService: I18nService, private runtimeBackground: RuntimeBackground, private i18nService: I18nService,
private messagingService: MessagingService, private appIdService: AppIdService, private messagingService: MessagingService, private appIdService: AppIdService,
private platformUtilsService: PlatformUtilsService, private activeAccount: ActiveAccountService) { private platformUtilsService: PlatformUtilsService, private stateService: StateService) {
this.storageService.save(StorageKey.BiometricFingerprintValidated, false); this.stateService.setBiometricFingerprintValidated(false);
if (chrome?.permissions?.onAdded) { if (chrome?.permissions?.onAdded) {
// Reload extension to activate nativeMessaging // Reload extension to activate nativeMessaging
chrome.permissions.onAdded.addListener(permissions => { chrome.permissions.onAdded.addListener(permissions => {
BrowserApi.reloadExtension(null); BrowserApi.reloadExtension(null);
}); });
}
} }
}
async connect() { async connect() {
this.appId = await this.appIdService.getAppId(); this.appId = await this.appIdService.getAppId();
this.storageService.save(StorageKey.BiometricFingerprintValidated, false); this.stateService.setBiometricFingerprintValidated(false);
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
this.port = BrowserApi.connectNative('com.8bit.bitwarden'); this.port = BrowserApi.connectNative('com.8bit.bitwarden');
@ -97,7 +95,7 @@ export class NativeMessagingBackground {
if (this.validatingFingerprint) { if (this.validatingFingerprint) {
this.validatingFingerprint = false; this.validatingFingerprint = false;
this.storageService.save(StorageKey.BiometricFingerprintValidated, true); this.stateService.setBiometricFingerprintValidated(true);
} }
this.sharedSecret = new SymmetricCryptoKey(decrypted); this.sharedSecret = new SymmetricCryptoKey(decrypted);
this.secureSetupResolve(); this.secureSetupResolve();
@ -179,7 +177,7 @@ export class NativeMessagingBackground {
if (this.platformUtilsService.isSafari()) { if (this.platformUtilsService.isSafari()) {
this.postMessage(message); this.postMessage(message);
} else { } else {
this.postMessage({appId: this.appId, message: await this.encryptMessage(message)}); this.postMessage({ appId: this.appId, message: await this.encryptMessage(message) });
} }
} }
@ -234,7 +232,7 @@ export class NativeMessagingBackground {
switch (message.command) { switch (message.command) {
case 'biometricUnlock': case 'biometricUnlock':
await this.storageService.remove(StorageKey.BiometricAwaitingAcceptance); await this.stateService.setBiometricAwaitingAcceptance(null);
if (message.response === 'not enabled') { if (message.response === 'not enabled') {
this.messagingService.send('showDialog', { this.messagingService.send('showDialog', {
@ -254,16 +252,16 @@ export class NativeMessagingBackground {
break; break;
} }
const enabled = await this.storageService.get(StorageKey.BiometricUnlock); const enabled = await this.stateService.getBiometricUnlock();
if (enabled === null || enabled === false) { if (enabled === null || enabled === false) {
if (message.response === 'unlocked') { if (message.response === 'unlocked') {
await this.storageService.save(StorageKey.BiometricUnlock, true); await this.stateService.setBiometricUnlock(true);
} }
break; break;
} }
// Ignore unlock if already unlockeded // Ignore unlock if already unlockeded
if (!this.vaultTimeoutService.biometricLocked) { if (!this.stateService.getBiometricLocked()) {
break; break;
} }
@ -272,7 +270,7 @@ export class NativeMessagingBackground {
// Verify key is correct by attempting to decrypt a secret // Verify key is correct by attempting to decrypt a secret
try { try {
await this.cryptoService.getFingerprint(this.activeAccount.userId); await this.cryptoService.getFingerprint(await this.stateService.getUserId());
} catch (e) { } catch (e) {
// tslint:disable-next-line // tslint:disable-next-line
console.error('Unable to verify key:', e); console.error('Unable to verify key:', e);
@ -283,8 +281,8 @@ export class NativeMessagingBackground {
break; break;
} }
this.vaultTimeoutService.biometricLocked = false; await this.stateService.setBiometricLocked(false);
this.runtimeBackground.processMessage({command: 'unlocked'}, null, null); this.runtimeBackground.processMessage({ command: 'unlocked' }, null, null);
} }
break; break;
default: default:
@ -305,7 +303,7 @@ export class NativeMessagingBackground {
this.sendUnencrypted({ this.sendUnencrypted({
command: 'setupEncryption', command: 'setupEncryption',
publicKey: Utils.fromBufferToB64(publicKey), publicKey: Utils.fromBufferToB64(publicKey),
userId: this.activeAccount.userId, userId: await this.stateService.getUserId(),
}); });
return new Promise((resolve, reject) => this.secureSetupResolve = resolve); return new Promise((resolve, reject) => this.secureSetupResolve = resolve);
@ -318,11 +316,11 @@ export class NativeMessagingBackground {
message.timestamp = Date.now(); message.timestamp = Date.now();
this.postMessage({appId: this.appId, message: message}); this.postMessage({ appId: this.appId, message: message });
} }
private async showFingerprintDialog() { private async showFingerprintDialog() {
const fingerprint = (await this.cryptoService.getFingerprint(this.activeAccount.userId, this.publicKey)).join(' '); const fingerprint = (await this.cryptoService.getFingerprint(await this.stateService.getUserId(), this.publicKey)).join(' ');
this.messagingService.send('showDialog', { this.messagingService.send('showDialog', {
html: `${this.i18nService.t('desktopIntegrationVerificationText')}<br><br><strong>${fingerprint}</strong>`, html: `${this.i18nService.t('desktopIntegrationVerificationText')}<br><br><strong>${fingerprint}</strong>`,

View File

@ -24,7 +24,7 @@ import MainBackground from './main.background';
import { Utils } from 'jslib-common/misc/utils'; import { Utils } from 'jslib-common/misc/utils';
import { PolicyType } from 'jslib-common/enums/policyType'; import { PolicyType } from 'jslib-common/enums/policyType';
import { StorageKey } from 'jslib-common/enums/storageKey'; import { StateService } from 'jslib-common/abstractions/state.service';
export default class RuntimeBackground { export default class RuntimeBackground {
private runtime: any; private runtime: any;
@ -34,11 +34,11 @@ export default class RuntimeBackground {
constructor(private main: MainBackground, private autofillService: AutofillService, constructor(private main: MainBackground, private autofillService: AutofillService,
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService, private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
private storageService: StorageService, private i18nService: I18nService, private i18nService: I18nService,
private notificationsService: NotificationsService, private systemService: SystemService, private notificationsService: NotificationsService, private systemService: SystemService,
private vaultTimeoutService: VaultTimeoutService, private environmentService: EnvironmentService, private vaultTimeoutService: VaultTimeoutService, private environmentService: EnvironmentService,
private policyService: PolicyService, private messagingService: MessagingService, private policyService: PolicyService, private messagingService: MessagingService,
private folderService: FolderService) { private folderService: FolderService, private stateService: StateService) {
// onInstalled listener must be wired up before anything else, so we do it in the ctor // onInstalled listener must be wired up before anything else, so we do it in the ctor
chrome.runtime.onInstalled.addListener((details: any) => { chrome.runtime.onInstalled.addListener((details: any) => {
@ -328,8 +328,7 @@ export default class RuntimeBackground {
const usernameMatches = ciphers.filter(c => const usernameMatches = ciphers.filter(c =>
c.login.username != null && c.login.username.toLowerCase() === normalizedUsername); c.login.username != null && c.login.username.toLowerCase() === normalizedUsername);
if (usernameMatches.length === 0) { if (usernameMatches.length === 0) {
const disabledAddLogin = await this.storageService.get<boolean>( const disabledAddLogin = await this.stateService.getDisableAddLoginNotification();
StorageKey.DisableAddLoginNotification);
if (disabledAddLogin) { if (disabledAddLogin) {
return; return;
} }
@ -351,8 +350,7 @@ export default class RuntimeBackground {
}); });
await this.main.checkNotificationQueue(tab); await this.main.checkNotificationQueue(tab);
} else if (usernameMatches.length === 1 && usernameMatches[0].login.password !== loginInfo.password) { } else if (usernameMatches.length === 1 && usernameMatches[0].login.password !== loginInfo.password) {
const disabledChangePassword = await this.storageService.get<boolean>( const disabledChangePassword = await this.stateService.getDisableChangedPasswordNotification();
StorageKey.DisableChangedPasswordNotification);
if (disabledChangePassword) { if (disabledChangePassword) {
return; return;
} }
@ -422,30 +420,27 @@ export default class RuntimeBackground {
private async setDefaultSettings() { private async setDefaultSettings() {
// Default timeout option to "on restart". // Default timeout option to "on restart".
const currentVaultTimeout = await this.storageService.get<number>(StorageKey.VaultTimeout); const currentVaultTimeout = await this.stateService.getVaultTimeout();
if (currentVaultTimeout == null) { if (currentVaultTimeout == null) {
await this.storageService.save(StorageKey.VaultTimeout, -1); await this.stateService.setVaultTimeout(-1);
} }
// Default action to "lock". // Default action to "lock".
const currentVaultTimeoutAction = await this.storageService.get<string>(StorageKey.VaultTimeoutAction); const currentVaultTimeoutAction = await this.stateService.getVaultTimeoutAction();
if (currentVaultTimeoutAction == null) { if (currentVaultTimeoutAction == null) {
await this.storageService.save(StorageKey.VaultTimeoutAction, 'lock'); await this.stateService.setVaultTimeoutAction('lock');
} }
} }
private async getDataForTab(tab: any, responseCommand: string) { private async getDataForTab(tab: any, responseCommand: string) {
const responseData: any = {}; const responseData: any = {};
if (responseCommand === 'notificationBarDataResponse') { if (responseCommand === 'notificationBarDataResponse') {
responseData.neverDomains = await this.storageService.get<any>(StorageKey.NeverDomains); responseData.neverDomains = await this.stateService.getNeverDomains();
const disableAddLoginFromOptions = await this.storageService.get<boolean>( const disableAddLoginFromOptions = await this.stateService.getDisableAddLoginNotification();
StorageKey.DisableAddLoginNotification);
responseData.disabledAddLoginNotification = disableAddLoginFromOptions || !(await this.allowPersonalOwnership()); responseData.disabledAddLoginNotification = disableAddLoginFromOptions || !(await this.allowPersonalOwnership());
responseData.disabledChangedPasswordNotification = await this.storageService.get<boolean>( responseData.disabledChangedPasswordNotification = await this.stateService.getDisableChangedPasswordNotification();
StorageKey.DisableChangedPasswordNotification);
} else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') { } else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') {
responseData.autofillEnabled = await this.storageService.get<boolean>( responseData.autofillEnabled = await this.stateService.getEnableAutoFillOnPageLoad();
StorageKey.EnableAutoFillOnPageLoad);
} else if (responseCommand === 'notificationBarFrameDataResponse') { } else if (responseCommand === 'notificationBarFrameDataResponse') {
responseData.i18n = { responseData.i18n = {
appName: this.i18nService.t('appName'), appName: this.i18nService.t('appName'),

View File

@ -6,6 +6,7 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { HintComponent as BaseHintComponent } from 'jslib-angular/components/hint.component'; import { HintComponent as BaseHintComponent } from 'jslib-angular/components/hint.component';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-hint', selector: 'app-hint',
@ -13,7 +14,7 @@ import { HintComponent as BaseHintComponent } from 'jslib-angular/components/hin
}) })
export class HintComponent extends BaseHintComponent { export class HintComponent extends BaseHintComponent {
constructor(router: Router, platformUtilsService: PlatformUtilsService, constructor(router: Router, platformUtilsService: PlatformUtilsService,
i18nService: I18nService, apiService: ApiService) { i18nService: I18nService, apiService: ApiService, logService: LogService) {
super(router, i18nService, apiService, platformUtilsService); super(router, i18nService, apiService, platformUtilsService, logService);
} }
} }

View File

@ -1,22 +1,20 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { Utils } from 'jslib-common/misc/utils'; import { Utils } from 'jslib-common/misc/utils';
import { StorageKey } from 'jslib-common/enums/storageKey';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
templateUrl: 'home.component.html', templateUrl: 'home.component.html',
}) })
export class HomeComponent { export class HomeComponent {
constructor(protected platformUtilsService: PlatformUtilsService, constructor(protected platformUtilsService: PlatformUtilsService,
private passwordGenerationService: PasswordGenerationService, private activeAccount: ActiveAccountService, private passwordGenerationService: PasswordGenerationService, private stateService: StateService,
private cryptoFunctionService: CryptoFunctionService, private environmentService: EnvironmentService) { } private cryptoFunctionService: CryptoFunctionService, private environmentService: EnvironmentService) { }
async launchSsoBrowser() { async launchSsoBrowser() {
@ -35,8 +33,8 @@ export class HomeComponent {
const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, 'sha256'); const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, 'sha256');
const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash); const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash);
await this.activeAccount.saveInformation(StorageKey.SsoCodeVerifier, codeVerifier); await this.stateService.setSsoCodeVerifier(codeVerifier);
await this.activeAccount.saveInformation(StorageKey.SsoState, state); await this.stateService.setSsoState(state);
let url = this.environmentService.getWebVaultUrl(); let url = this.environmentService.getWebVaultUrl();
if (url == null) { if (url == null) {

View File

@ -1,7 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
@ -14,7 +13,8 @@ import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.serv
import { LockComponent as BaseLockComponent } from 'jslib-angular/components/lock.component'; import { LockComponent as BaseLockComponent } from 'jslib-angular/components/lock.component';
import Swal from 'sweetalert2'; import Swal from 'sweetalert2';
import { StorageKey } from 'jslib-common/enums/storageKey'; import { LogService } from 'jslib-common/abstractions/log.service';
import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service';
@Component({ @Component({
selector: 'app-lock', selector: 'app-lock',
@ -24,21 +24,19 @@ export class LockComponent extends BaseLockComponent {
private isInitialLockScreen: boolean; private isInitialLockScreen: boolean;
constructor(router: Router, i18nService: I18nService, constructor(router: Router, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, messagingService: MessagingService, platformUtilsService: PlatformUtilsService, messagingService: MessagingService, cryptoService: CryptoService,
activeAccount: ActiveAccountService, cryptoService: CryptoService,
vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService, vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService,
stateService: StateService, apiService: ApiService) { stateService: StateService, apiService: ApiService, logService: LogService, keyConnectorService: KeyConnectorService) {
super(router, i18nService, platformUtilsService, super(router, i18nService, platformUtilsService,
messagingService, cryptoService, vaultTimeoutService, messagingService, cryptoService, vaultTimeoutService,
environmentService, stateService, apiService, activeAccount); environmentService, stateService, apiService, logService, keyConnectorService);
this.successRoute = '/tabs/current'; this.successRoute = '/tabs/current';
this.isInitialLockScreen = (window as any).previousPopupUrl == null; this.isInitialLockScreen = (window as any).previousPopupUrl == null;
} }
async ngOnInit() { async ngOnInit() {
await super.ngOnInit(); await super.ngOnInit();
const disableAutoBiometricsPrompt = await this.activeAccount.getInformation<boolean>( const disableAutoBiometricsPrompt = await this.stateService.getDisableAutoBiometricsPrompt() ?? true;
StorageKey.DisableAutoBiometricsPrompt) ?? true;
window.setTimeout(async () => { window.setTimeout(async () => {
document.getElementById(this.pinLock ? 'pin' : 'masterPassword').focus(); document.getElementById(this.pinLock ? 'pin' : 'masterPassword').focus();

View File

@ -1,7 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { AuthService } from 'jslib-common/abstractions/auth.service'; import { AuthService } from 'jslib-common/abstractions/auth.service';
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
@ -13,6 +12,7 @@ import { StorageService } from 'jslib-common/abstractions/storage.service';
import { SyncService } from 'jslib-common/abstractions/sync.service'; import { SyncService } from 'jslib-common/abstractions/sync.service';
import { LoginComponent as BaseLoginComponent } from 'jslib-angular/components/login.component'; import { LoginComponent as BaseLoginComponent } from 'jslib-angular/components/login.component';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
@ -23,11 +23,11 @@ export class LoginComponent extends BaseLoginComponent {
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
protected stateService: StateService, protected environmentService: EnvironmentService, protected stateService: StateService, protected environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationService, protected passwordGenerationService: PasswordGenerationService,
protected cryptoFunctionService: CryptoFunctionService, storageService: StorageService, protected cryptoFunctionService: CryptoFunctionService, logService: LogService,
syncService: SyncService, protected activeAccount: ActiveAccountService) { syncService: SyncService) {
super(authService, router, platformUtilsService, i18nService, super(authService, router, platformUtilsService, i18nService,
stateService, environmentService, passwordGenerationService, cryptoFunctionService, stateService, environmentService, passwordGenerationService, cryptoFunctionService,
storageService, activeAccount); logService);
super.onSuccessfulLogin = async () => { super.onSuccessfulLogin = async () => {
await syncService.fullSync(true); await syncService.fullSync(true);
}; };

View File

@ -11,6 +11,7 @@ import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.se
import { StateService } from 'jslib-common/abstractions/state.service'; import { StateService } from 'jslib-common/abstractions/state.service';
import { RegisterComponent as BaseRegisterComponent } from 'jslib-angular/components/register.component'; import { RegisterComponent as BaseRegisterComponent } from 'jslib-angular/components/register.component';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-register', selector: 'app-register',
@ -20,8 +21,8 @@ export class RegisterComponent extends BaseRegisterComponent {
constructor(authService: AuthService, router: Router, constructor(authService: AuthService, router: Router,
i18nService: I18nService, cryptoService: CryptoService, i18nService: I18nService, cryptoService: CryptoService,
apiService: ApiService, stateService: StateService, platformUtilsService: PlatformUtilsService, apiService: ApiService, stateService: StateService, platformUtilsService: PlatformUtilsService,
passwordGenerationService: PasswordGenerationService, environmentService: EnvironmentService) { passwordGenerationService: PasswordGenerationService, environmentService: EnvironmentService, logService: LogService) {
super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService, super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService,
passwordGenerationService, environmentService); passwordGenerationService, environmentService, logService);
} }
} }

View File

@ -5,7 +5,6 @@ import {
Router, Router,
} from '@angular/router'; } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
@ -13,6 +12,7 @@ import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { SyncService } from 'jslib-common/abstractions/sync.service'; import { SyncService } from 'jslib-common/abstractions/sync.service';
import { import {
@ -26,11 +26,11 @@ import {
export class SetPasswordComponent extends BaseSetPasswordComponent { export class SetPasswordComponent extends BaseSetPasswordComponent {
constructor(apiService: ApiService, i18nService: I18nService, constructor(apiService: ApiService, i18nService: I18nService,
cryptoService: CryptoService, messagingService: MessagingService, cryptoService: CryptoService, messagingService: MessagingService,
activeAccount: ActiveAccountService, passwordGenerationService: PasswordGenerationService, stateService: StateService, passwordGenerationService: PasswordGenerationService,
platformUtilsService: PlatformUtilsService, policyService: PolicyService, router: Router, platformUtilsService: PlatformUtilsService, policyService: PolicyService, router: Router,
syncService: SyncService, route: ActivatedRoute) { syncService: SyncService, route: ActivatedRoute) {
super(i18nService, cryptoService, messagingService, passwordGenerationService, super(i18nService, cryptoService, messagingService, passwordGenerationService,
platformUtilsService, policyService, router, apiService, syncService, route, activeAccount); platformUtilsService, policyService, router, apiService, syncService, route, stateService);
} }
get masterPasswordScoreWidth() { get masterPasswordScoreWidth() {

View File

@ -18,6 +18,7 @@ import { SyncService } from 'jslib-common/abstractions/sync.service';
import { SsoComponent as BaseSsoComponent } from 'jslib-angular/components/sso.component'; import { SsoComponent as BaseSsoComponent } from 'jslib-angular/components/sso.component';
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-sso', selector: 'app-sso',
@ -29,9 +30,9 @@ export class SsoComponent extends BaseSsoComponent {
storageService: StorageService, stateService: StateService, storageService: StorageService, stateService: StateService,
platformUtilsService: PlatformUtilsService, apiService: ApiService, platformUtilsService: PlatformUtilsService, apiService: ApiService,
cryptoFunctionService: CryptoFunctionService, passwordGenerationService: PasswordGenerationService, cryptoFunctionService: CryptoFunctionService, passwordGenerationService: PasswordGenerationService,
syncService: SyncService, environmentService: EnvironmentService) { syncService: SyncService, environmentService: EnvironmentService, logService: LogService) {
super(authService, router, i18nService, route, storageService, stateService, platformUtilsService, super(authService, router, i18nService, route, stateService, platformUtilsService,
apiService, cryptoFunctionService, environmentService, passwordGenerationService); apiService, cryptoFunctionService, environmentService, passwordGenerationService, logService);
const url = this.environmentService.getWebVaultUrl(); const url = this.environmentService.getWebVaultUrl();

View File

@ -28,6 +28,7 @@ import { TwoFactorComponent as BaseTwoFactorComponent } from 'jslib-angular/comp
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { LogService } from 'jslib-common/abstractions/log.service';
const BroadcasterSubscriptionId = 'TwoFactorComponent'; const BroadcasterSubscriptionId = 'TwoFactorComponent';
@ -43,10 +44,10 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
platformUtilsService: PlatformUtilsService, private syncService: SyncService, platformUtilsService: PlatformUtilsService, private syncService: SyncService,
environmentService: EnvironmentService, private ngZone: NgZone, environmentService: EnvironmentService, private ngZone: NgZone,
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef, private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
private popupUtilsService: PopupUtilsService, stateService: StateService, private popupUtilsService: PopupUtilsService, stateService: StateService, route: ActivatedRoute,
storageService: StorageService, route: ActivatedRoute, private messagingService: MessagingService) { private messagingService: MessagingService, logService: LogService) {
super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService, super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService,
stateService, storageService, route); stateService, route, logService);
super.onSuccessfulLogin = () => { super.onSuccessfulLogin = () => {
return syncService.fullSync(true); return syncService.fullSync(true);
}; };

View File

@ -1,6 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
@ -11,6 +10,8 @@ import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { SyncService } from 'jslib-common/abstractions/sync.service'; import { SyncService } from 'jslib-common/abstractions/sync.service';
import { UpdateTempPasswordComponent as BaseUpdateTempPasswordComponent } from 'jslib-angular/components/update-temp-password.component'; import { UpdateTempPasswordComponent as BaseUpdateTempPasswordComponent } from 'jslib-angular/components/update-temp-password.component';
import { StateService } from 'jslib-common/abstractions/state.service';
import { LogService } from 'jslib-common/abstractions/log.service';
interface MasterPasswordScore { interface MasterPasswordScore {
Color: string; Color: string;
@ -55,11 +56,11 @@ export class UpdateTempPasswordComponent extends BaseUpdateTempPasswordComponent
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
passwordGenerationService: PasswordGenerationService, policyService: PolicyService, passwordGenerationService: PasswordGenerationService, policyService: PolicyService,
cryptoService: CryptoService, activeAccount: ActiveAccountService, cryptoService: CryptoService, stateService: StateService,
messagingService: MessagingService, apiService: ApiService, messagingService: MessagingService, apiService: ApiService,
syncService: SyncService) { syncService: SyncService, logService: LogService) {
super(i18nService, platformUtilsService, passwordGenerationService, policyService, super(i18nService, platformUtilsService, passwordGenerationService, policyService,
cryptoService, messagingService, apiService, activeAccount, cryptoService, messagingService, apiService, stateService,
syncService); syncService, logService);
} }
} }

View File

@ -31,8 +31,6 @@ import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.se
import { StateService } from 'jslib-common/abstractions/state.service'; import { StateService } from 'jslib-common/abstractions/state.service';
import { StorageService } from 'jslib-common/abstractions/storage.service'; import { StorageService } from 'jslib-common/abstractions/storage.service';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { routerTransition } from './app-routing.animations'; import { routerTransition } from './app-routing.animations';
@Component({ @Component({
@ -81,7 +79,7 @@ export class AppComponent implements OnInit {
(window as any).bitwardenPopupMainMessageListener = async (msg: any, sender: any, sendResponse: any) => { (window as any).bitwardenPopupMainMessageListener = async (msg: any, sender: any, sendResponse: any) => {
if (msg.command === 'doneLoggingOut') { if (msg.command === 'doneLoggingOut') {
this.ngZone.run(async () => { this.ngZone.run(async () => {
this.authService.logOut(() => { this.authService.logOut(async () => {
if (msg.expired) { if (msg.expired) {
this.showToast({ this.showToast({
type: 'warning', type: 'warning',
@ -90,7 +88,7 @@ export class AppComponent implements OnInit {
}); });
} }
this.router.navigate(['home']); this.router.navigate(['home']);
this.stateService.purge(); await this.stateService.clean();
}); });
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
}); });
@ -99,7 +97,7 @@ export class AppComponent implements OnInit {
this.router.navigate(['home']); this.router.navigate(['home']);
}); });
} else if (msg.command === 'locked') { } else if (msg.command === 'locked') {
this.stateService.purge(); this.stateService.clean();
this.ngZone.run(() => { this.ngZone.run(() => {
this.router.navigate(['lock']); this.router.navigate(['lock']);
}); });
@ -133,15 +131,13 @@ export class AppComponent implements OnInit {
const url = event.urlAfterRedirects || event.url || ''; const url = event.urlAfterRedirects || event.url || '';
if (url.startsWith('/tabs/') && (window as any).previousPopupUrl != null && if (url.startsWith('/tabs/') && (window as any).previousPopupUrl != null &&
(window as any).previousPopupUrl.startsWith('/tabs/')) { (window as any).previousPopupUrl.startsWith('/tabs/')) {
this.stateService.remove('GroupingsComponent'); this.stateService.setBrowserGroupingComponentState(null);
this.stateService.remove('GroupingsComponentScope'); this.stateService.setBrowserCipherComponentState(null);
this.stateService.remove('CiphersComponent'); this.stateService.setBrowserSendComponentState(null);
this.stateService.remove('SendGroupingsComponent'); this.stateService.setBrowserSendTypeComponentState(null);
this.stateService.remove('SendGroupingsComponentScope');
this.stateService.remove('SendTypeComponent');
} }
if (url.startsWith('/tabs/')) { if (url.startsWith('/tabs/')) {
this.stateService.remove('addEditCipherInfo'); this.stateService.setAddEditCipherInfo(null);
} }
(window as any).previousPopupUrl = url; (window as any).previousPopupUrl = url;
@ -173,7 +169,7 @@ export class AppComponent implements OnInit {
} }
this.lastActivity = now; this.lastActivity = now;
this.storageService.save(StorageKey.LastActive, now); await this.stateService.setLastActive(now);
} }
private showToast(msg: any) { private showToast(msg: any) {

View File

@ -13,12 +13,12 @@ import { EventType } from 'jslib-common/enums/eventType';
import { CipherView } from 'jslib-common/models/view/cipherView'; import { CipherView } from 'jslib-common/models/view/cipherView';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { EventService } from 'jslib-common/abstractions/event.service'; import { EventService } from 'jslib-common/abstractions/event.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { TotpService } from 'jslib-common/abstractions/totp.service'; import { TotpService } from 'jslib-common/abstractions/totp.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@Component({ @Component({
selector: 'app-action-buttons', selector: 'app-action-buttons',
@ -35,11 +35,11 @@ export class ActionButtonsComponent {
constructor(private toasterService: ToasterService, private i18nService: I18nService, constructor(private toasterService: ToasterService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private eventService: EventService, private platformUtilsService: PlatformUtilsService, private eventService: EventService,
private totpService: TotpService, private activeAccount: ActiveAccountService, private totpService: TotpService, private stateService: StateService,
private passwordRepromptService: PasswordRepromptService) { } private passwordRepromptService: PasswordRepromptService) { }
async ngOnInit() { async ngOnInit() {
this.userHasPremiumAccess = this.activeAccount.canAccessPremium; this.userHasPremiumAccess = await this.stateService.getCanAccessPremium();
} }
launchCipher() { launchCipher() {

View File

@ -27,7 +27,7 @@ export class PasswordGeneratorComponent extends BasePasswordGeneratorComponent {
async ngOnInit() { async ngOnInit() {
await super.ngOnInit(); await super.ngOnInit();
const addEditCipherInfo = await this.stateService.get<any>('addEditCipherInfo'); const addEditCipherInfo = await this.stateService.getAddEditCipherInfo();
if (addEditCipherInfo != null) { if (addEditCipherInfo != null) {
this.cipherState = addEditCipherInfo.cipher; this.cipherState = addEditCipherInfo.cipher;
} }

View File

@ -10,7 +10,6 @@ import {
Router, Router,
} from '@angular/router'; } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service';
@ -22,6 +21,8 @@ import { TokenService } from 'jslib-common/abstractions/token.service';
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/send/add-edit.component'; import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/send/add-edit.component';
import { StateService } from 'jslib-common/abstractions/state.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-send-add-edit', selector: 'app-send-add-edit',
@ -38,12 +39,12 @@ export class SendAddEditComponent extends BaseAddEditComponent {
isUnsupportedMac = false; isUnsupportedMac = false;
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
activeAccount: ActiveAccountService, messagingService: MessagingService, policyService: PolicyService, stateService: StateService, messagingService: MessagingService, policyService: PolicyService,
environmentService: EnvironmentService, datePipe: DatePipe, sendService: SendService, environmentService: EnvironmentService, datePipe: DatePipe, sendService: SendService,
private route: ActivatedRoute, private router: Router, private location: Location, private route: ActivatedRoute, private router: Router, private location: Location,
private popupUtilsService: PopupUtilsService) { private popupUtilsService: PopupUtilsService, logService: LogService) {
super(i18nService, platformUtilsService, environmentService, datePipe, super(i18nService, platformUtilsService, environmentService, datePipe,
sendService, messagingService, policyService, activeAccount); sendService, messagingService, policyService, logService, stateService);
} }
get showFileSelector(): boolean { get showFileSelector(): boolean {

View File

@ -26,6 +26,8 @@ import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { SendType } from 'jslib-common/enums/sendType'; import { SendType } from 'jslib-common/enums/sendType';
import { LogService } from 'jslib-common/abstractions/log.service';
import { BrowserSendComponentState } from 'jslib-common/models/domain/browserSendComponentState';
const ComponentId = 'SendComponent'; const ComponentId = 'SendComponent';
const ScopeStateId = ComponentId + 'Scope'; const ScopeStateId = ComponentId + 'Scope';
@ -40,8 +42,7 @@ export class SendGroupingsComponent extends BaseSendComponent {
// Send Type Calculations // Send Type Calculations
typeCounts = new Map<SendType, number>(); typeCounts = new Map<SendType, number>();
// State Handling // State Handling
state: any; state: BrowserSendComponentState;
scopeState: any;
private loadedTimeout: number; private loadedTimeout: number;
constructor(sendService: SendService, i18nService: I18nService, constructor(sendService: SendService, i18nService: I18nService,
@ -49,9 +50,10 @@ export class SendGroupingsComponent extends BaseSendComponent {
policyService: PolicyService, searchService: SearchService, policyService: PolicyService, searchService: SearchService,
private popupUtils: PopupUtilsService, private stateService: StateService, private popupUtils: PopupUtilsService, private stateService: StateService,
private router: Router, private syncService: SyncService, private router: Router, private syncService: SyncService,
private changeDetectorRef: ChangeDetectorRef, private broadcasterService: BroadcasterService) { private changeDetectorRef: ChangeDetectorRef, private broadcasterService: BroadcasterService,
logService: LogService) {
super(sendService, i18nService, platformUtilsService, environmentService, ngZone, searchService, super(sendService, i18nService, platformUtilsService, environmentService, ngZone, searchService,
policyService); policyService, logService);
super.onSuccessfulLoad = async () => { super.onSuccessfulLoad = async () => {
this.calculateTypeCounts(); this.calculateTypeCounts();
this.selectAll(); this.selectAll();
@ -62,12 +64,11 @@ export class SendGroupingsComponent extends BaseSendComponent {
// Determine Header details // Determine Header details
this.showLeftHeader = !(this.popupUtils.inSidebar(window) && this.platformUtilsService.isFirefox()); this.showLeftHeader = !(this.popupUtils.inSidebar(window) && this.platformUtilsService.isFirefox());
// Clear state of Send Type Component // Clear state of Send Type Component
this.stateService.remove('SendTypeComponent'); this.stateService.setBrowserSendComponentState(null);
// Let super class finish // Let super class finish
await super.ngOnInit(); await super.ngOnInit();
// Handle State Restore if necessary // Handle State Restore if necessary
const restoredScopeState = await this.restoreState(); const restoredScopeState = await this.restoreState();
this.state = (await this.stateService.get<any>(ComponentId)) || {};
if (this.state.searchText != null) { if (this.state.searchText != null) {
this.searchText = this.state.searchText; this.searchText = this.state.searchText;
} }
@ -158,27 +159,25 @@ export class SendGroupingsComponent extends BaseSendComponent {
this.state = { this.state = {
scrollY: this.popupUtils.getContentScrollY(window), scrollY: this.popupUtils.getContentScrollY(window),
searchText: this.searchText, searchText: this.searchText,
};
await this.stateService.save(ComponentId, this.state);
this.scopeState = {
sends: this.sends, sends: this.sends,
typeCounts: this.typeCounts, typeCounts: this.typeCounts,
}; };
await this.stateService.save(ScopeStateId, this.scopeState); await this.stateService.setBrowserSendComponentState(this.state);
} }
private async restoreState(): Promise<boolean> { private async restoreState(): Promise<boolean> {
this.scopeState = await this.stateService.get<any>(ScopeStateId); this.state = await this.stateService.getBrowserSendComponentState();
if (this.scopeState == null) { if (this.state == null) {
return false; return false;
} }
if (this.state.sends != null) {
if (this.scopeState.sends != null) { this.sends = this.state.sends;
this.sends = this.scopeState.sends;
} }
if (this.scopeState.typeCounts != null) { if (this.state.typeCounts != null) {
this.typeCounts = this.scopeState.typeCounts; this.typeCounts = this.state.typeCounts;
}
if (this.state.searchText != null) {
this.searchText = this.state.searchText;
} }
return true; return true;

View File

@ -28,6 +28,8 @@ import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { SendType } from 'jslib-common/enums/sendType'; import { SendType } from 'jslib-common/enums/sendType';
import { LogService } from 'jslib-common/abstractions/log.service';
import { BrowserComponentState } from 'jslib-common/models/domain/browserComponentState';
const ComponentId = 'SendTypeComponent'; const ComponentId = 'SendTypeComponent';
@ -38,7 +40,7 @@ const ComponentId = 'SendTypeComponent';
export class SendTypeComponent extends BaseSendComponent { export class SendTypeComponent extends BaseSendComponent {
groupingTitle: string; groupingTitle: string;
// State Handling // State Handling
state: any; state: BrowserComponentState;
private refreshTimeout: number; private refreshTimeout: number;
private applySavedState = true; private applySavedState = true;
@ -47,9 +49,9 @@ export class SendTypeComponent extends BaseSendComponent {
policyService: PolicyService, searchService: SearchService, policyService: PolicyService, searchService: SearchService,
private popupUtils: PopupUtilsService, private stateService: StateService, private popupUtils: PopupUtilsService, private stateService: StateService,
private route: ActivatedRoute, private location: Location, private changeDetectorRef: ChangeDetectorRef, private route: ActivatedRoute, private location: Location, private changeDetectorRef: ChangeDetectorRef,
private broadcasterService: BroadcasterService, private router: Router) { private broadcasterService: BroadcasterService, private router: Router, logService: LogService) {
super(sendService, i18nService, platformUtilsService, environmentService, ngZone, searchService, super(sendService, i18nService, platformUtilsService, environmentService, ngZone, searchService,
policyService); policyService, logService);
super.onSuccessfulLoad = async () => { super.onSuccessfulLoad = async () => {
this.selectType(this.type); this.selectType(this.type);
}; };
@ -62,7 +64,7 @@ export class SendTypeComponent extends BaseSendComponent {
await super.ngOnInit(); await super.ngOnInit();
const queryParamsSub = this.route.queryParams.subscribe(async params => { const queryParamsSub = this.route.queryParams.subscribe(async params => {
if (this.applySavedState) { if (this.applySavedState) {
this.state = (await this.stateService.get<any>(ComponentId)) || {}; this.state = (await this.stateService.getBrowserSendTypeComponentState());
if (this.state.searchText != null) { if (this.state.searchText != null) {
this.searchText = this.state.searchText; this.searchText = this.state.searchText;
} }
@ -87,7 +89,7 @@ export class SendTypeComponent extends BaseSendComponent {
if (this.applySavedState && this.state != null) { if (this.applySavedState && this.state != null) {
window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY), 0); window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY), 0);
} }
this.stateService.remove(ComponentId); this.stateService.setBrowserSendComponentState(null);
// Unsubscribe // Unsubscribe
if (queryParamsSub != null) { if (queryParamsSub != null) {
@ -154,6 +156,6 @@ export class SendTypeComponent extends BaseSendComponent {
scrollY: this.popupUtils.getContentScrollY(window), scrollY: this.popupUtils.getContentScrollY(window),
searchText: this.searchText, searchText: this.searchText,
}; };
await this.stateService.save(ComponentId, this.state); await this.stateService.setBrowserSendTypeComponentState(this.state);
} }
} }

View File

@ -19,8 +19,6 @@ import { ValidationService } from 'jslib-angular/services/validation.service';
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { AccountsManagementService } from 'jslib-common/abstractions/accountsManagement.service';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { AppIdService } from 'jslib-common/abstractions/appId.service'; import { AppIdService } from 'jslib-common/abstractions/appId.service';
import { AuditService } from 'jslib-common/abstractions/audit.service'; import { AuditService } from 'jslib-common/abstractions/audit.service';
@ -65,7 +63,6 @@ import { StateService } from 'jslib-common/services/state.service';
import { PopupSearchService } from './popup-search.service'; import { PopupSearchService } from './popup-search.service';
import { PopupUtilsService } from './popup-utils.service'; import { PopupUtilsService } from './popup-utils.service';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { ThemeType } from 'jslib-common/enums/themeType'; import { ThemeType } from 'jslib-common/enums/themeType';
function getBgService<T>(service: string) { function getBgService<T>(service: string) {
@ -77,14 +74,13 @@ function getBgService<T>(service: string) {
const isPrivateMode = BrowserApi.getBackgroundPage() == null; const isPrivateMode = BrowserApi.getBackgroundPage() == null;
const stateService = new StateService();
const messagingService = new BrowserMessagingService(); const messagingService = new BrowserMessagingService();
const searchService = isPrivateMode ? null : new PopupSearchService(getBgService<SearchService>('searchService')(), const searchService = isPrivateMode ? null : new PopupSearchService(getBgService<SearchService>('searchService')(),
getBgService<CipherService>('cipherService')(), getBgService<ConsoleLogService>('consoleLogService')(), getBgService<CipherService>('cipherService')(), getBgService<ConsoleLogService>('consoleLogService')(),
getBgService<I18nService>('i18nService')()); getBgService<I18nService>('i18nService')());
export function initFactory(platformUtilsService: PlatformUtilsService, i18nService: I18nService, storageService: StorageService, export function initFactory(platformUtilsService: PlatformUtilsService, i18nService: I18nService, storageService: StorageService,
popupUtilsService: PopupUtilsService): Function { popupUtilsService: PopupUtilsService, stateService: StateService): Function {
return async () => { return async () => {
if (!popupUtilsService.inPopup(window)) { if (!popupUtilsService.inPopup(window)) {
window.document.body.classList.add('body-full'); window.document.body.classList.add('body-full');
@ -95,17 +91,18 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
} }
if (!isPrivateMode) { if (!isPrivateMode) {
await stateService.save(StorageKey.DisableFavicon, // TODO: Fix these guys
await storageService.get<boolean>(StorageKey.DisableFavicon)); // await stateService.save(StorageKey.DisableFavicon,
// await storageService.get<boolean>(StorageKey.DisableFavicon));
await stateService.save(StorageKey.DisableBadgeCounter, // await stateService.save(StorageKey.DisableBadgeCounter,
await storageService.get<boolean>(StorageKey.DisableBadgeCounter)); // await storageService.get<boolean>(StorageKey.DisableBadgeCounter));
const htmlEl = window.document.documentElement; const htmlEl = window.document.documentElement;
const theme = await platformUtilsService.getEffectiveTheme(); const theme = await platformUtilsService.getEffectiveTheme();
htmlEl.classList.add('theme_' + theme); htmlEl.classList.add('theme_' + theme);
platformUtilsService.onDefaultSystemThemeChange(async sysTheme => { platformUtilsService.onDefaultSystemThemeChange(async sysTheme => {
const bwTheme = await storageService.get<ThemeType>(StorageKey.Theme); const bwTheme = await stateService.getTheme();
if (bwTheme == null || bwTheme === ThemeType.System) { if (bwTheme == null || bwTheme === ThemeType.System) {
htmlEl.classList.remove('theme_' + ThemeType.Light, 'theme_' + ThemeType.Dark); htmlEl.classList.remove('theme_' + ThemeType.Light, 'theme_' + ThemeType.Dark);
htmlEl.classList.add('theme_' + sysTheme); htmlEl.classList.add('theme_' + sysTheme);
@ -133,7 +130,7 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
ModalService, ModalService,
{ provide: MessagingService, useValue: messagingService }, { provide: MessagingService, useValue: messagingService },
{ provide: AuthServiceAbstraction, useFactory: getBgService<AuthService>('authService'), deps: [] }, { provide: AuthServiceAbstraction, useFactory: getBgService<AuthService>('authService'), deps: [] },
{ provide: StateServiceAbstraction, useValue: stateService }, { provide: StateServiceAbstraction, useFactory: getBgService<StateService>('stateService') },
{ provide: SearchServiceAbstraction, useValue: searchService }, { provide: SearchServiceAbstraction, useValue: searchService },
{ provide: AuditService, useFactory: getBgService<AuditService>('auditService'), deps: [] }, { provide: AuditService, useFactory: getBgService<AuditService>('auditService'), deps: [] },
{ provide: FileUploadService, useFactory: getBgService<FileUploadService>('fileUploadService'), deps: [] }, { provide: FileUploadService, useFactory: getBgService<FileUploadService>('fileUploadService'), deps: [] },
@ -194,8 +191,6 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
}, },
{ provide: PasswordRepromptServiceAbstraction, useClass: PasswordRepromptService }, { provide: PasswordRepromptServiceAbstraction, useClass: PasswordRepromptService },
{ provide: PasswordRepromptServiceAbstraction, useClass: PasswordRepromptService }, { provide: PasswordRepromptServiceAbstraction, useClass: PasswordRepromptService },
{ provide: ActiveAccountService, useFactory: getBgService<ActiveAccountService>('activeAccount'), deps: [] },
{ provide: AccountsManagementService, useFactory: getBgService<AccountsManagementService>('accountsManagementService'), deps: [] },
{ provide: OrganizationService, useFactory: getBgService<OrganizationService>('organizationService'), deps: [] }, { provide: OrganizationService, useFactory: getBgService<OrganizationService>('organizationService'), deps: [] },
{ provide: ProviderService, useFactory: getBgService<ProviderService>('providerService'), deps: [] }, { provide: ProviderService, useFactory: getBgService<ProviderService>('providerService'), deps: [] },
], ],

View File

@ -7,9 +7,6 @@ import {
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
@ -18,6 +15,7 @@ import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { Utils } from 'jslib-common/misc/utils'; import { Utils } from 'jslib-common/misc/utils';
import { StateService } from 'jslib-common/abstractions/state.service';
interface ExcludedDomain { interface ExcludedDomain {
uri: string; uri: string;
@ -35,14 +33,14 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
currentUris: string[]; currentUris: string[];
loadCurrentUrisTimeout: number; loadCurrentUrisTimeout: number;
constructor(private activeAccount: ActiveAccountService, constructor(private stateService: StateService,
private i18nService: I18nService, private router: Router, private i18nService: I18nService, private router: Router,
private broadcasterService: BroadcasterService, private ngZone: NgZone, private broadcasterService: BroadcasterService, private ngZone: NgZone,
private platformUtilsService: PlatformUtilsService) { private platformUtilsService: PlatformUtilsService) {
} }
async ngOnInit() { async ngOnInit() {
const savedDomains = await this.activeAccount.getInformation<any>(StorageKey.NeverDomains); const savedDomains = await this.stateService.getNeverDomains();
if (savedDomains) { if (savedDomains) {
for (const uri of Object.keys(savedDomains)) { for (const uri of Object.keys(savedDomains)) {
this.excludedDomains.push({ uri: uri, showCurrentUris: false }); this.excludedDomains.push({ uri: uri, showCurrentUris: false });
@ -93,7 +91,7 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
savedDomains[validDomain] = null; savedDomains[validDomain] = null;
} }
} }
await this.activeAccount.saveInformation(StorageKey.NeverDomains, savedDomains); await this.stateService.setNeverDomains(savedDomains);
this.router.navigate(['/tabs/settings']); this.router.navigate(['/tabs/settings']);
} }

View File

@ -1,5 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { FormBuilder } from '@angular/forms';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EventService } from 'jslib-common/abstractions/event.service'; import { EventService } from 'jslib-common/abstractions/event.service';
@ -9,6 +10,8 @@ import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.se
import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { ExportComponent as BaseExportComponent } from 'jslib-angular/components/export.component'; import { ExportComponent as BaseExportComponent } from 'jslib-angular/components/export.component';
import { LogService } from 'jslib-common/abstractions/log.service';
import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service';
@Component({ @Component({
selector: 'app-export', selector: 'app-export',
@ -17,8 +20,10 @@ import { ExportComponent as BaseExportComponent } from 'jslib-angular/components
export class ExportComponent extends BaseExportComponent { export class ExportComponent extends BaseExportComponent {
constructor(cryptoService: CryptoService, i18nService: I18nService, constructor(cryptoService: CryptoService, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, exportService: ExportService, platformUtilsService: PlatformUtilsService, exportService: ExportService,
eventService: EventService, policyService: PolicyService, private router: Router) { eventService: EventService, policyService: PolicyService, private router: Router,
super(cryptoService, i18nService, platformUtilsService, exportService, eventService, policyService, window); logService: LogService, userVerificationService: UserVerificationService, formBuilder: FormBuilder) {
super(cryptoService, i18nService, platformUtilsService, exportService, eventService,
policyService, window, logService, userVerificationService, formBuilder);
} }
protected saved() { protected saved() {

View File

@ -11,6 +11,7 @@ import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.se
import { import {
FolderAddEditComponent as BaseFolderAddEditComponent, FolderAddEditComponent as BaseFolderAddEditComponent,
} from 'jslib-angular/components/folder-add-edit.component'; } from 'jslib-angular/components/folder-add-edit.component';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-folder-add-edit', selector: 'app-folder-add-edit',
@ -19,8 +20,8 @@ import {
export class FolderAddEditComponent extends BaseFolderAddEditComponent { export class FolderAddEditComponent extends BaseFolderAddEditComponent {
constructor(folderService: FolderService, i18nService: I18nService, constructor(folderService: FolderService, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, private router: Router, platformUtilsService: PlatformUtilsService, private router: Router,
private route: ActivatedRoute) { private route: ActivatedRoute, logService: LogService) {
super(folderService, i18nService, platformUtilsService); super(folderService, i18nService, platformUtilsService, logService);
} }
async ngOnInit() { async ngOnInit() {

View File

@ -3,14 +3,13 @@ import {
OnInit, OnInit,
} from '@angular/core'; } from '@angular/core';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { ThemeType } from 'jslib-common/enums/themeType'; import { ThemeType } from 'jslib-common/enums/themeType';
import { UriMatchType } from 'jslib-common/enums/uriMatchType'; import { UriMatchType } from 'jslib-common/enums/uriMatchType';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { TotpService } from 'jslib-common/abstractions/totp.service'; import { TotpService } from 'jslib-common/abstractions/totp.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@Component({ @Component({
selector: 'app-options', selector: 'app-options',
@ -39,7 +38,7 @@ export class OptionsComponent implements OnInit {
showAutofill: boolean = true; showAutofill: boolean = true;
showDisplay: boolean = true; showDisplay: boolean = true;
constructor(private messagingService: MessagingService, private activeAccount: ActiveAccountService, constructor(private messagingService: MessagingService, private stateService: StateService,
private totpService: TotpService, i18nService: I18nService) { private totpService: TotpService, i18nService: I18nService) {
this.themeOptions = [ this.themeOptions = [
{ name: i18nService.t('default'), value: null }, { name: i18nService.t('default'), value: null },
@ -72,93 +71,85 @@ export class OptionsComponent implements OnInit {
} }
async ngOnInit() { async ngOnInit() {
this.enableAutoFillOnPageLoad = await this.activeAccount.getInformation<boolean>( this.enableAutoFillOnPageLoad = await this.stateService.getEnableAutoFillOnPageLoad();
StorageKey.EnableAutoFillOnPageLoad);
this.autoFillOnPageLoadDefault = await this.activeAccount.getInformation<boolean>( this.autoFillOnPageLoadDefault = await this.stateService.getAutoFillOnPageLoadDefault() ?? true;
StorageKey.AutoFillOnPageLoadDefault) ?? true;
this.disableAddLoginNotification = await this.activeAccount.getInformation<boolean>( this.disableAddLoginNotification = await this.stateService.getDisableAddLoginNotification();
StorageKey.DisableAddLoginNotification);
this.disableChangedPasswordNotification = await this.activeAccount.getInformation<boolean>( this.disableChangedPasswordNotification = await this.stateService.getDisableChangedPasswordNotification();
StorageKey.DisableChangedPasswordNotification);
this.disableContextMenuItem = await this.activeAccount.getInformation<boolean>( this.disableContextMenuItem = await this.stateService.getDisableContextMenuItem();
StorageKey.DisableContextMenuItem);
this.dontShowCards = await this.activeAccount.getInformation<boolean>(StorageKey.DontShowCardsCurrentTab); this.dontShowCards = await this.stateService.getDontShowCardsCurrentTab();
this.dontShowIdentities = await this.activeAccount.getInformation<boolean>(StorageKey.DontShowIdentitiesCurrentTab); this.dontShowIdentities = await this.stateService.getDontShowIdentitiesCurrentTab();
this.disableAutoTotpCopy = !(await this.totpService.isAutoCopyEnabled()); this.disableAutoTotpCopy = !(await this.totpService.isAutoCopyEnabled());
this.disableFavicon = await this.activeAccount.getInformation<boolean>(StorageKey.DisableFavicon); this.disableFavicon = await this.stateService.getDisableFavicon();
this.disableBadgeCounter = await this.activeAccount.getInformation<boolean>(StorageKey.DisableBadgeCounter); this.disableBadgeCounter = await this.stateService.getDisableBadgeCounter();
this.theme = await this.activeAccount.getInformation<string>(StorageKey.Theme); this.theme = await this.stateService.getTheme();
const defaultUriMatch = await this.activeAccount.getInformation<UriMatchType>(StorageKey.DefaultUriMatch); const defaultUriMatch = await this.stateService.getDefaultUriMatch();
this.defaultUriMatch = defaultUriMatch == null ? UriMatchType.Domain : defaultUriMatch; this.defaultUriMatch = defaultUriMatch == null ? UriMatchType.Domain : defaultUriMatch;
this.clearClipboard = await this.activeAccount.getInformation<number>(StorageKey.ClearClipboard); this.clearClipboard = await this.stateService.getClearClipboard();
} }
async updateAddLoginNotification() { async updateAddLoginNotification() {
await this.activeAccount.saveInformation(StorageKey.DisableAddLoginNotification, await this.stateService.setDisableAddLoginNotification(this.disableAddLoginNotification);
this.disableAddLoginNotification);
} }
async updateChangedPasswordNotification() { async updateChangedPasswordNotification() {
await this.activeAccount.saveInformation(StorageKey.DisableChangedPasswordNotification, await this.stateService.setDisableChangedPasswordNotification(this.disableChangedPasswordNotification);
this.disableChangedPasswordNotification);
} }
async updateDisableContextMenuItem() { async updateDisableContextMenuItem() {
await this.activeAccount.saveInformation(StorageKey.DisableContextMenuItem, await this.stateService.setDisableContextMenuItem(this.disableContextMenuItem);
this.disableContextMenuItem);
this.messagingService.send('bgUpdateContextMenu'); this.messagingService.send('bgUpdateContextMenu');
} }
async updateAutoTotpCopy() { async updateAutoTotpCopy() {
await this.activeAccount.saveInformation(StorageKey.DisableAutoTotpCopy, this.disableAutoTotpCopy); await this.stateService.setDisableAutoTotpCopy(this.disableAutoTotpCopy);
} }
async updateAutoFillOnPageLoad() { async updateAutoFillOnPageLoad() {
await this.activeAccount.saveInformation(StorageKey.EnableAutoFillOnPageLoad, this.enableAutoFillOnPageLoad); await this.stateService.setEnableAutoFillOnPageLoad(this.enableAutoFillOnPageLoad);
} }
async updateAutoFillOnPageLoadDefault() { async updateAutoFillOnPageLoadDefault() {
await this.activeAccount.saveInformation(StorageKey.AutoFillOnPageLoadDefault, this.autoFillOnPageLoadDefault); await this.stateService.setAutoFillOnPageLoadDefault(this.autoFillOnPageLoadDefault);
} }
async updateDisableFavicon() { async updateDisableFavicon() {
await this.activeAccount.saveInformation(StorageKey.DisableFavicon, this.disableFavicon); await this.stateService.setDisableFavicon(this.disableFavicon);
} }
async updateDisableBadgeCounter() { async updateDisableBadgeCounter() {
await this.activeAccount.saveInformation(StorageKey.DisableBadgeCounter, this.disableBadgeCounter); await this.stateService.setDisableBadgeCounter(this.disableBadgeCounter);
this.messagingService.send('bgUpdateContextMenu'); this.messagingService.send('bgUpdateContextMenu');
} }
async updateShowCards() { async updateShowCards() {
await this.activeAccount.saveInformation(StorageKey.DontShowCardsCurrentTab, this.dontShowCards); await this.stateService.setDontShowCardsCurrentTab(this.dontShowCards);
} }
async updateShowIdentities() { async updateShowIdentities() {
await this.activeAccount.saveInformation(StorageKey.DontShowIdentitiesCurrentTab, this.dontShowIdentities); await this.stateService.setDontShowIdentitiesCurrentTab(this.dontShowIdentities);
} }
async saveTheme() { async saveTheme() {
await this.activeAccount.saveInformation(StorageKey.Theme, this.theme); await this.stateService.setTheme(this.theme);
window.setTimeout(() => window.location.reload(), 200); window.setTimeout(() => window.location.reload(), 200);
} }
async saveDefaultUriMatch() { async saveDefaultUriMatch() {
await this.activeAccount.saveInformation(StorageKey.DefaultUriMatch, this.defaultUriMatch); await this.stateService.setDefaultUriMatch(this.defaultUriMatch);
} }
async saveClearClipboard() { async saveClearClipboard() {
await this.activeAccount.saveInformation(StorageKey.ClearClipboard, this.clearClipboard); await this.stateService.setClearClipboard(this.clearClipboard);
} }
} }

View File

@ -1,12 +1,13 @@
import { CurrencyPipe } from '@angular/common'; import { CurrencyPipe } from '@angular/common';
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PremiumComponent as BasePremiumComponent } from 'jslib-angular/components/premium.component'; import { PremiumComponent as BasePremiumComponent } from 'jslib-angular/components/premium.component';
import { StateService } from 'jslib-common/abstractions/state.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-premium', selector: 'app-premium',
@ -16,9 +17,9 @@ export class PremiumComponent extends BasePremiumComponent {
priceString: string; priceString: string;
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService, constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
apiService: ApiService, activeAccount: ActiveAccountService, apiService: ApiService, logService: LogService, stateService: StateService,
private currencyPipe: CurrencyPipe) { private currencyPipe: CurrencyPipe) {
super(i18nService, platformUtilsService, apiService, activeAccount); super(i18nService, platformUtilsService, apiService, logService, stateService);
// Support old price string. Can be removed in future once all translations are properly updated. // Support old price string. Can be removed in future once all translations are properly updated.
const thePrice = this.currencyPipe.transform(this.price, '$'); const thePrice = this.currencyPipe.transform(this.price, '$');

View File

@ -12,9 +12,7 @@ import Swal from 'sweetalert2/src/sweetalert2.js';
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { DeviceType } from 'jslib-common/enums/deviceType'; import { DeviceType } from 'jslib-common/enums/deviceType';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
@ -26,6 +24,7 @@ import { PopupUtilsService } from '../services/popup-utils.service';
import { ModalService } from 'jslib-angular/services/modal.service'; import { ModalService } from 'jslib-angular/services/modal.service';
import { SetPinComponent } from '../components/set-pin.component'; import { SetPinComponent } from '../components/set-pin.component';
import { StateService } from 'jslib-common/abstractions/state.service';
const RateUrls = { const RateUrls = {
[DeviceType.ChromeExtension]: [DeviceType.ChromeExtension]:
@ -62,7 +61,7 @@ export class SettingsComponent implements OnInit {
constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService,
private vaultTimeoutService: VaultTimeoutService, public messagingService: MessagingService, private vaultTimeoutService: VaultTimeoutService, public messagingService: MessagingService,
private router: Router, private environmentService: EnvironmentService, private router: Router, private environmentService: EnvironmentService,
private cryptoService: CryptoService, private activeAccount: ActiveAccountService, private cryptoService: CryptoService, private stateService: StateService,
private popupUtilsService: PopupUtilsService, private modalService: ModalService, private popupUtilsService: PopupUtilsService, private modalService: ModalService,
private toasterService: ToasterService) { private toasterService: ToasterService) {
} }
@ -106,7 +105,7 @@ export class SettingsComponent implements OnInit {
this.saveVaultTimeout(value); this.saveVaultTimeout(value);
}); });
const action = await this.activeAccount.getInformation<string>(StorageKey.VaultTimeoutAction); const action = await this.stateService.getVaultTimeoutAction();
this.vaultTimeoutAction = action == null ? 'lock' : action; this.vaultTimeoutAction = action == null ? 'lock' : action;
const pinSet = await this.vaultTimeoutService.isPinLockSet(); const pinSet = await this.vaultTimeoutService.isPinLockSet();
@ -114,8 +113,7 @@ export class SettingsComponent implements OnInit {
this.supportsBiometric = await this.platformUtilsService.supportsBiometric(); this.supportsBiometric = await this.platformUtilsService.supportsBiometric();
this.biometric = await this.vaultTimeoutService.isBiometricLockSet(); this.biometric = await this.vaultTimeoutService.isBiometricLockSet();
this.disableAutoBiometricsPrompt = await this.activeAccount.getInformation<boolean>( this.disableAutoBiometricsPrompt = await this.stateService.getDisableAutoBiometricsPrompt() ?? true;
StorageKey.DisableAutoBiometricsPrompt) ?? true;
} }
async saveVaultTimeout(newValue: number) { async saveVaultTimeout(newValue: number) {
@ -223,14 +221,14 @@ export class SettingsComponent implements OnInit {
allowOutsideClick: false, allowOutsideClick: false,
}); });
await this.activeAccount.saveInformation(StorageKey.BiometricAwaitingAcceptance, true); await this.stateService.setBiometricAwaitingAcceptance(true);
await this.cryptoService.toggleKey(); await this.cryptoService.toggleKey();
await Promise.race([ await Promise.race([
submitted.then(result => { submitted.then(async result => {
if (result.dismiss === Swal.DismissReason.cancel) { if (result.dismiss === Swal.DismissReason.cancel) {
this.biometric = false; this.biometric = false;
this.activeAccount.removeInformation(StorageKey.BiometricAwaitingAcceptance); await this.stateService.setBiometricAwaitingAcceptance(null);
} }
}), }),
this.platformUtilsService.authenticateBiometric().then(result => { this.platformUtilsService.authenticateBiometric().then(result => {
@ -246,13 +244,13 @@ export class SettingsComponent implements OnInit {
}), }),
]); ]);
} else { } else {
await this.activeAccount.removeInformation(StorageKey.BiometricUnlock); await this.stateService.setBiometricUnlock(null);
this.vaultTimeoutService.biometricLocked = false; await this.stateService.setBiometricLocked(false);
} }
} }
async updateAutoBiometricsPrompt() { async updateAutoBiometricsPrompt() {
await this.activeAccount.saveInformation(StorageKey.DisableAutoBiometricsPrompt, this.disableAutoBiometricsPrompt); await this.stateService.setDisableAutoBiometricsPrompt(this.disableAutoBiometricsPrompt);
} }
async lock() { async lock() {
@ -332,7 +330,7 @@ export class SettingsComponent implements OnInit {
} }
async fingerprint() { async fingerprint() {
const fingerprint = await this.cryptoService.getFingerprint(this.activeAccount.userId); const fingerprint = await this.cryptoService.getFingerprint(await this.stateService.getUserId());
const p = document.createElement('p'); const p = document.createElement('p');
p.innerText = this.i18nService.t('yourAccountsFingerprint') + ':'; p.innerText = this.i18nService.t('yourAccountsFingerprint') + ':';
const p2 = document.createElement('p'); const p2 = document.createElement('p');

View File

@ -7,7 +7,6 @@ import {
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { AuditService } from 'jslib-common/abstractions/audit.service'; import { AuditService } from 'jslib-common/abstractions/audit.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service';
@ -27,7 +26,8 @@ import { LoginUriView } from 'jslib-common/models/view/loginUriView';
import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/add-edit.component'; import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/add-edit.component';
import { CipherType } from 'jslib-common/enums/cipherType'; import { CipherType } from 'jslib-common/enums/cipherType';
import { StorageKey } from 'jslib-common/enums/storageKey'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-vault-add-edit', selector: 'app-vault-add-edit',
@ -41,15 +41,15 @@ export class AddEditComponent extends BaseAddEditComponent {
constructor(cipherService: CipherService, folderService: FolderService, constructor(cipherService: CipherService, folderService: FolderService,
i18nService: I18nService, platformUtilsService: PlatformUtilsService, i18nService: I18nService, platformUtilsService: PlatformUtilsService,
auditService: AuditService, stateService: StateService, auditService: AuditService, stateService: StateService, collectionService: CollectionService,
activeAccount: ActiveAccountService, collectionService: CollectionService,
messagingService: MessagingService, private route: ActivatedRoute, messagingService: MessagingService, private route: ActivatedRoute,
private router: Router, private location: Location, private router: Router, private location: Location,
eventService: EventService, policyService: PolicyService, eventService: EventService, policyService: PolicyService,
private popupUtilsService: PopupUtilsService, organizationService: OrganizationService) { private popupUtilsService: PopupUtilsService, organizationService: OrganizationService,
passwordRepromptService: PasswordRepromptService, logService: LogService) {
super(cipherService, folderService, i18nService, platformUtilsService, super(cipherService, folderService, i18nService, platformUtilsService,
auditService, stateService, collectionService, messagingService, auditService, stateService, collectionService, messagingService,
eventService, policyService, activeAccount, organizationService); eventService, policyService, logService, passwordRepromptService, organizationService);
} }
async ngOnInit() { async ngOnInit() {
@ -117,7 +117,7 @@ export class AddEditComponent extends BaseAddEditComponent {
async load() { async load() {
await super.load(); await super.load();
this.showAutoFillOnPageLoadOptions = this.cipher.type === CipherType.Login && this.showAutoFillOnPageLoadOptions = this.cipher.type === CipherType.Login &&
await this.activeAccount.getInformation<boolean>(StorageKey.EnableAutoFillOnPageLoad); await this.stateService.getEnableAutoFillOnPageLoad();
} }
async submit(): Promise<boolean> { async submit(): Promise<boolean> {
@ -161,7 +161,7 @@ export class AddEditComponent extends BaseAddEditComponent {
async generatePassword(): Promise<boolean> { async generatePassword(): Promise<boolean> {
const confirmed = await super.generatePassword(); const confirmed = await super.generatePassword();
if (confirmed) { if (confirmed) {
this.stateService.save('addEditCipherInfo', { this.stateService.setAddEditCipherInfo({
cipher: this.cipher, cipher: this.cipher,
collectionIds: this.collections == null ? [] : collectionIds: this.collections == null ? [] :
this.collections.filter(c => (c as any).checked).map(c => c.id), this.collections.filter(c => (c as any).checked).map(c => c.id),

View File

@ -2,7 +2,6 @@ import { Location } from '@angular/common';
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service';
@ -10,6 +9,8 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { AttachmentsComponent as BaseAttachmentsComponent } from 'jslib-angular/components/attachments.component'; import { AttachmentsComponent as BaseAttachmentsComponent } from 'jslib-angular/components/attachments.component';
import { StateService } from 'jslib-common/abstractions/state.service';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-vault-attachments', selector: 'app-vault-attachments',
@ -21,9 +22,9 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
constructor(cipherService: CipherService, i18nService: I18nService, constructor(cipherService: CipherService, i18nService: I18nService,
cryptoService: CryptoService, platformUtilsService: PlatformUtilsService, cryptoService: CryptoService, platformUtilsService: PlatformUtilsService,
apiService: ApiService, private location: Location, apiService: ApiService, private location: Location,
private route: ActivatedRoute, activeAccount: ActiveAccountService) { private route: ActivatedRoute, stateService: StateService, logService: LogService) {
super(cipherService, i18nService, cryptoService, platformUtilsService, super(cipherService, i18nService, cryptoService, platformUtilsService,
apiService, window, activeAccount); apiService, window, logService, stateService);
} }
async ngOnInit() { async ngOnInit() {

View File

@ -34,6 +34,7 @@ import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { CiphersComponent as BaseCiphersComponent } from 'jslib-angular/components/ciphers.component'; import { CiphersComponent as BaseCiphersComponent } from 'jslib-angular/components/ciphers.component';
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { BrowserComponentState } from 'jslib-common/models/domain/browserComponentState';
const ComponentId = 'CiphersComponent'; const ComponentId = 'CiphersComponent';
@ -43,7 +44,7 @@ const ComponentId = 'CiphersComponent';
}) })
export class CiphersComponent extends BaseCiphersComponent implements OnInit, OnDestroy { export class CiphersComponent extends BaseCiphersComponent implements OnInit, OnDestroy {
groupingTitle: string; groupingTitle: string;
state: any; state: BrowserComponentState;
folderId: string = null; folderId: string = null;
collectionId: string = null; collectionId: string = null;
type: CipherType = null; type: CipherType = null;
@ -72,7 +73,7 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
this.searchTypeSearch = !this.platformUtilsService.isSafari(); this.searchTypeSearch = !this.platformUtilsService.isSafari();
const queryParamsSub = this.route.queryParams.subscribe(async params => { const queryParamsSub = this.route.queryParams.subscribe(async params => {
if (this.applySavedState) { if (this.applySavedState) {
this.state = (await this.stateService.get<any>(ComponentId)) || {}; this.state = await this.stateService.getBrowserCipherComponentState();
if (this.state.searchText) { if (this.state.searchText) {
this.searchText = this.state.searchText; this.searchText = this.state.searchText;
} }
@ -135,7 +136,7 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY, window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY,
this.scrollingContainer), 0); this.scrollingContainer), 0);
} }
this.stateService.remove(ComponentId); this.stateService.setBrowserCipherComponentState(null);
if (queryParamsSub != null) { if (queryParamsSub != null) {
queryParamsSub.unsubscribe(); queryParamsSub.unsubscribe();
} }
@ -231,6 +232,6 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
scrollY: this.popupUtils.getContentScrollY(window, this.scrollingContainer), scrollY: this.popupUtils.getContentScrollY(window, this.scrollingContainer),
searchText: this.searchText, searchText: this.searchText,
}; };
await this.stateService.save(ComponentId, this.state); await this.stateService.setBrowserCipherComponentState(this.state);
} }
} }

View File

@ -8,6 +8,7 @@ import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { CollectionsComponent as BaseCollectionsComponent } from 'jslib-angular/components/collections.component'; import { CollectionsComponent as BaseCollectionsComponent } from 'jslib-angular/components/collections.component';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-vault-collections', selector: 'app-vault-collections',
@ -16,8 +17,8 @@ import { CollectionsComponent as BaseCollectionsComponent } from 'jslib-angular/
export class CollectionsComponent extends BaseCollectionsComponent { export class CollectionsComponent extends BaseCollectionsComponent {
constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService, constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService, cipherService: CipherService, i18nService: I18nService, cipherService: CipherService,
private route: ActivatedRoute, private location: Location) { private route: ActivatedRoute, private location: Location, logService: LogService) {
super(collectionService, platformUtilsService, i18nService, cipherService); super(collectionService, platformUtilsService, i18nService, cipherService, logService);
} }
async ngOnInit() { async ngOnInit() {

View File

@ -16,11 +16,9 @@ import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType'; import { CipherRepromptType } from 'jslib-common/enums/cipherRepromptType';
import { CipherType } from 'jslib-common/enums/cipherType'; import { CipherType } from 'jslib-common/enums/cipherType';
import { StorageKey } from 'jslib-common/enums/storageKey';
import { CipherView } from 'jslib-common/models/view/cipherView'; import { CipherView } from 'jslib-common/models/view/cipherView';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service'; import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service';
@ -33,6 +31,7 @@ import { AutofillService } from '../../services/abstractions/autofill.service';
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { Utils } from 'jslib-common/misc/utils'; import { Utils } from 'jslib-common/misc/utils';
import { StateService } from 'jslib-common/abstractions/state.service';
const BroadcasterSubscriptionId = 'CurrentTabComponent'; const BroadcasterSubscriptionId = 'CurrentTabComponent';
@ -62,7 +61,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
private toasterService: ToasterService, private i18nService: I18nService, private router: Router, private toasterService: ToasterService, private i18nService: I18nService, private router: Router,
private ngZone: NgZone, private broadcasterService: BroadcasterService, private ngZone: NgZone, private broadcasterService: BroadcasterService,
private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService, private changeDetectorRef: ChangeDetectorRef, private syncService: SyncService,
private searchService: SearchService, private activeAccount: ActiveAccountService, private searchService: SearchService, private stateService: StateService,
private passwordRepromptService: PasswordRepromptService) { private passwordRepromptService: PasswordRepromptService) {
} }
@ -208,9 +207,8 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
}); });
const otherTypes: CipherType[] = []; const otherTypes: CipherType[] = [];
const dontShowCards = await this.activeAccount.getInformation<boolean>(StorageKey.DontShowCardsCurrentTab); const dontShowCards = await this.stateService.getDontShowCardsCurrentTab();
const dontShowIdentities = await this.activeAccount.getInformation<boolean>( const dontShowIdentities = await this.stateService.getDontShowIdentitiesCurrentTab();
StorageKey.DontShowIdentitiesCurrentTab);
if (!dontShowCards) { if (!dontShowCards) {
otherTypes.push(CipherType.Card); otherTypes.push(CipherType.Card);
} }

View File

@ -19,7 +19,6 @@ import { CipherView } from 'jslib-common/models/view/cipherView';
import { CollectionView } from 'jslib-common/models/view/collectionView'; import { CollectionView } from 'jslib-common/models/view/collectionView';
import { FolderView } from 'jslib-common/models/view/folderView'; import { FolderView } from 'jslib-common/models/view/folderView';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service';
import { FolderService } from 'jslib-common/abstractions/folder.service'; import { FolderService } from 'jslib-common/abstractions/folder.service';
@ -78,18 +77,17 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
private cipherService: CipherService, private router: Router, private cipherService: CipherService, private router: Router,
private ngZone: NgZone, private broadcasterService: BroadcasterService, private ngZone: NgZone, private broadcasterService: BroadcasterService,
private changeDetectorRef: ChangeDetectorRef, private route: ActivatedRoute, private changeDetectorRef: ChangeDetectorRef, private route: ActivatedRoute,
private stateService: StateService, private popupUtils: PopupUtilsService, stateService: StateService, private popupUtils: PopupUtilsService,
private syncService: SyncService, private platformUtilsService: PlatformUtilsService, private syncService: SyncService, private platformUtilsService: PlatformUtilsService,
private searchService: SearchService, private location: Location, private searchService: SearchService, private location: Location) {
activeAccount: ActiveAccountService) { super(collectionService, folderService, stateService);
super(collectionService, folderService, activeAccount);
this.noFolderListSize = 100; this.noFolderListSize = 100;
} }
async ngOnInit() { async ngOnInit() {
this.searchTypeSearch = !this.platformUtilsService.isSafari(); this.searchTypeSearch = !this.platformUtilsService.isSafari();
this.showLeftHeader = !(this.popupUtils.inSidebar(window) && this.platformUtilsService.isFirefox()); this.showLeftHeader = !(this.popupUtils.inSidebar(window) && this.platformUtilsService.isFirefox());
this.stateService.remove('CiphersComponent'); this.stateService.setBrowserCipherComponentState(null);
this.broadcasterService.subscribe(ComponentId, (message: any) => { this.broadcasterService.subscribe(ComponentId, (message: any) => {
this.ngZone.run(async () => { this.ngZone.run(async () => {
@ -109,7 +107,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
const restoredScopeState = await this.restoreState(); const restoredScopeState = await this.restoreState();
const queryParamsSub = this.route.queryParams.subscribe(async params => { const queryParamsSub = this.route.queryParams.subscribe(async params => {
this.state = (await this.stateService.get<any>(ComponentId)) || {}; this.state = (await this.stateService.getBrowserGroupingComponentState()) || {};
if (this.state.searchText) { if (this.state.searchText) {
this.searchText = this.state.searchText; this.searchText = this.state.searchText;
} else if (params.searchText) { } else if (params.searchText) {
@ -297,7 +295,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
closeOnEsc(e: KeyboardEvent) { closeOnEsc(e: KeyboardEvent) {
// If input not empty, use browser default behavior of clearing input instead // If input not empty, use browser default behavior of clearing input instead
if (e.key === 'Escape' && (this.searchText == null || this.searchText === '')) { if (e.key === 'Escape' && (this.searchText == null || this.searchText === '')) {
BrowserApi.closePopup(window); BrowserApi.closePopup(window);
} }
} }
@ -306,10 +304,6 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
this.state = { this.state = {
scrollY: this.popupUtils.getContentScrollY(window), scrollY: this.popupUtils.getContentScrollY(window),
searchText: this.searchText, searchText: this.searchText,
};
await this.stateService.save(ComponentId, this.state);
this.scopeState = {
favoriteCiphers: this.favoriteCiphers, favoriteCiphers: this.favoriteCiphers,
noFolderCiphers: this.noFolderCiphers, noFolderCiphers: this.noFolderCiphers,
ciphers: this.ciphers, ciphers: this.ciphers,
@ -320,11 +314,11 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
collections: this.collections, collections: this.collections,
deletedCount: this.deletedCount, deletedCount: this.deletedCount,
}; };
await this.stateService.save(ScopeStateId, this.scopeState); await this.stateService.setBrowserGroupingComponentState(this.scopeState);
} }
private async restoreState(): Promise<boolean> { private async restoreState(): Promise<boolean> {
this.scopeState = await this.stateService.get<any>(ScopeStateId); this.scopeState = await this.stateService.getBrowserGroupingComponentState();
if (this.scopeState == null) { if (this.scopeState == null) {
return false; return false;
} }

View File

@ -4,7 +4,6 @@ import {
Router, Router,
} from '@angular/router'; } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service'; import { CollectionService } from 'jslib-common/abstractions/collection.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
@ -12,6 +11,7 @@ import { OrganizationService } from 'jslib-common/abstractions/organization.serv
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { ShareComponent as BaseShareComponent } from 'jslib-angular/components/share.component'; import { ShareComponent as BaseShareComponent } from 'jslib-angular/components/share.component';
import { LogService } from 'jslib-common/abstractions/log.service';
@Component({ @Component({
selector: 'app-vault-share', selector: 'app-vault-share',
@ -19,11 +19,11 @@ import { ShareComponent as BaseShareComponent } from 'jslib-angular/components/s
}) })
export class ShareComponent extends BaseShareComponent { export class ShareComponent extends BaseShareComponent {
constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService, constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService, activeAccount: ActiveAccountService, i18nService: I18nService, logService: LogService,
cipherService: CipherService, private route: ActivatedRoute, cipherService: CipherService, private route: ActivatedRoute,
private router: Router, organizationService: OrganizationService) { private router: Router, organizationService: OrganizationService) {
super(collectionService, platformUtilsService, i18nService, cipherService, super(collectionService, platformUtilsService, i18nService, cipherService,
activeAccount, organizationService); logService, organizationService);
} }
async ngOnInit() { async ngOnInit() {

View File

@ -9,7 +9,6 @@ import {
Router, Router,
} from '@angular/router'; } from '@angular/router';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { ApiService } from 'jslib-common/abstractions/api.service'; import { ApiService } from 'jslib-common/abstractions/api.service';
import { AuditService } from 'jslib-common/abstractions/audit.service'; import { AuditService } from 'jslib-common/abstractions/audit.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
@ -33,6 +32,8 @@ import { ViewComponent as BaseViewComponent } from 'jslib-angular/components/vie
import { BrowserApi } from '../../browser/browserApi'; import { BrowserApi } from '../../browser/browserApi';
import { AutofillService } from '../../services/abstractions/autofill.service'; import { AutofillService } from '../../services/abstractions/autofill.service';
import { PopupUtilsService } from '../services/popup-utils.service'; import { PopupUtilsService } from '../services/popup-utils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { LogService } from 'jslib-common/abstractions/log.service';
const BroadcasterSubscriptionId = 'ChildViewComponent'; const BroadcasterSubscriptionId = 'ChildViewComponent';
@ -54,14 +55,15 @@ export class ViewComponent extends BaseViewComponent {
auditService: AuditService, private route: ActivatedRoute, auditService: AuditService, private route: ActivatedRoute,
private router: Router, private location: Location, private router: Router, private location: Location,
broadcasterService: BroadcasterService, ngZone: NgZone, broadcasterService: BroadcasterService, ngZone: NgZone,
changeDetectorRef: ChangeDetectorRef, activeAccount: ActiveAccountService, changeDetectorRef: ChangeDetectorRef, stateService: StateService,
eventService: EventService, private autofillService: AutofillService, eventService: EventService, private autofillService: AutofillService,
private messagingService: MessagingService, private popupUtilsService: PopupUtilsService, private messagingService: MessagingService, private popupUtilsService: PopupUtilsService,
apiService: ApiService, passwordRepromptService: PasswordRepromptService) { apiService: ApiService, passwordRepromptService: PasswordRepromptService,
logService: LogService) {
super(cipherService, totpService, tokenService, i18nService, super(cipherService, totpService, tokenService, i18nService,
cryptoService, platformUtilsService, auditService, window, cryptoService, platformUtilsService, auditService, window,
broadcasterService, ngZone, changeDetectorRef, eventService, broadcasterService, ngZone, changeDetectorRef, eventService,
apiService, passwordRepromptService, activeAccount); apiService, passwordRepromptService, logService, stateService);
} }
ngOnInit() { ngOnInit() {

View File

@ -1,4 +1,3 @@
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service'; import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { EventService } from 'jslib-common/abstractions/event.service'; import { EventService } from 'jslib-common/abstractions/event.service';
import { TotpService } from 'jslib-common/abstractions/totp.service'; import { TotpService } from 'jslib-common/abstractions/totp.service';
@ -17,6 +16,7 @@ import AutofillPageDetails from '../models/autofillPageDetails';
import AutofillScript from '../models/autofillScript'; import AutofillScript from '../models/autofillScript';
import { BrowserApi } from '../browser/browserApi'; import { BrowserApi } from '../browser/browserApi';
import { StateService } from 'jslib-common/abstractions/state.service';
const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag', const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag',
'placeholder', 'label-left', 'label-top', 'data-recurly']; 'placeholder', 'label-left', 'label-top', 'data-recurly'];
@ -130,7 +130,7 @@ var IsoProvinces: { [id: string]: string; } = {
export default class AutofillService implements AutofillServiceInterface { export default class AutofillService implements AutofillServiceInterface {
constructor(private cipherService: CipherService, private activeAccount: ActiveAccountService, constructor(private cipherService: CipherService, private stateService: StateService,
private totpService: TotpService, private eventService: EventService) { } private totpService: TotpService, private eventService: EventService) { }
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
@ -172,7 +172,7 @@ export default class AutofillService implements AutofillServiceInterface {
throw new Error('Nothing to auto-fill.'); throw new Error('Nothing to auto-fill.');
} }
const canAccessPremium = this.activeAccount.canAccessPremium; const canAccessPremium = await this.stateService.getCanAccessPremium();
let didAutofill = false; let didAutofill = false;
options.pageDetails.forEach((pd: any) => { options.pageDetails.forEach((pd: any) => {
// make sure we're still on correct tab // make sure we're still on correct tab

View File

@ -1,4 +1,4 @@
import { KeySuffixOptions } from 'jslib-common/models/domain/settingStorageOptions'; import { KeySuffixOptions } from 'jslib-common/enums/keySuffixOptions';
import { CryptoService } from 'jslib-common/services/crypto.service'; import { CryptoService } from 'jslib-common/services/crypto.service';

View File

@ -4,10 +4,9 @@ import { SafariApp } from '../browser/safariApp';
import { DeviceType } from 'jslib-common/enums/deviceType'; import { DeviceType } from 'jslib-common/enums/deviceType';
import { ThemeType } from 'jslib-common/enums/themeType'; import { ThemeType } from 'jslib-common/enums/themeType';
import { ActiveAccountService } from 'jslib-common/abstractions/activeAccount.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service'; import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StorageKey } from 'jslib-common/enums/storageKey'; import { StateService } from 'jslib-common/abstractions/state.service';
const DialogPromiseExpiration = 600000; // 10 minutes const DialogPromiseExpiration = 600000; // 10 minutes
@ -19,7 +18,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
private deviceCache: DeviceType = null; private deviceCache: DeviceType = null;
private prefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)'); private prefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)');
constructor(private messagingService: MessagingService, private activeAccount: ActiveAccountService, constructor(private messagingService: MessagingService, private stateService: StateService,
private clipboardWriteCallback: (clipboardValue: string, clearMs: number) => void, private clipboardWriteCallback: (clipboardValue: string, clearMs: number) => void,
private biometricCallback: () => Promise<boolean>) { } private biometricCallback: () => Promise<boolean>) { }
@ -119,7 +118,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
} }
supportsWebAuthn(win: Window): boolean { supportsWebAuthn(win: Window): boolean {
return (typeof(PublicKeyCredential) !== 'undefined'); return (typeof (PublicKeyCredential) !== 'undefined');
} }
supportsDuo(): boolean { supportsDuo(): boolean {
@ -331,7 +330,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
} }
async getEffectiveTheme() { async getEffectiveTheme() {
const theme = await this.activeAccount.getInformation<ThemeType>(StorageKey.Theme); const theme = await this.stateService.getTheme() as ThemeType;
if (theme == null || theme === ThemeType.System) { if (theme == null || theme === ThemeType.System) {
return this.getDefaultSystemTheme(); return this.getDefaultSystemTheme();
} else { } else {

View File

@ -26,11 +26,7 @@ export default class BrowserStorageService implements StorageService {
async save(key: string, obj: any): Promise<any> { async save(key: string, obj: any): Promise<any> {
if (obj == null) { if (obj == null) {
// Fix safari not liking null in set // Fix safari not liking null in set
return new Promise<void>(resolve => { return this.remove(key);
this.chromeStorageApi.remove(key, () => {
resolve();
});
});
} }
if (obj instanceof Set) { if (obj instanceof Set) {