mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
abstract storage service
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
import { StorageService } from '../../../services/abstractions/storage.service';
|
||||
import { UtilsService } from '../../../services/abstractions/utils.service';
|
||||
|
||||
function getBackgroundService<T>(service: string) {
|
||||
@@ -8,6 +9,7 @@ function getBackgroundService<T>(service: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export const storageService = getBackgroundService<StorageService>('storageService');
|
||||
export const tokenService = getBackgroundService<any>('tokenService');
|
||||
export const cryptoService = getBackgroundService<any>('cryptoService');
|
||||
export const userService = getBackgroundService<any>('userService');
|
||||
|
||||
@@ -10,6 +10,7 @@ export default angular
|
||||
.service('validationService', ValidationService)
|
||||
.service('authService', AuthService)
|
||||
|
||||
.factory('storageService', backgroundServices.storageService)
|
||||
.factory('tokenService', backgroundServices.tokenService)
|
||||
.factory('cryptoService', backgroundServices.cryptoService)
|
||||
.factory('userService', backgroundServices.userService)
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { UtilsService } from '../../../services/abstractions/utils.service';
|
||||
import { StorageService } from '../../../services/abstractions/storage.service';
|
||||
|
||||
class StateService {
|
||||
private state: any = {};
|
||||
|
||||
constructor(private utilsService: UtilsService, private constantsService: any) {
|
||||
constructor(private storageService: StorageService, private constantsService: any) {
|
||||
}
|
||||
|
||||
async init() {
|
||||
const faviconsDisabled = await this.utilsService
|
||||
.getObjFromStorage<boolean>(this.constantsService.disableFaviconKey);
|
||||
|
||||
this.saveState('faviconEnabled', !faviconsDisabled);
|
||||
const iconsDisabled = await this.storageService.get<boolean>(this.constantsService.disableFaviconKey);
|
||||
this.saveState('faviconEnabled', !iconsDisabled);
|
||||
}
|
||||
|
||||
saveState(key: string, data: any) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as angular from 'angular';
|
||||
import { StorageService } from '../../../services/abstractions/storage.service';
|
||||
import { UtilsService } from '../../../services/abstractions/utils.service';
|
||||
import StateService from '../services/state.service';
|
||||
import * as template from './options.component.html';
|
||||
@@ -14,7 +15,7 @@ export class OptionsController {
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any, private constantsService: any,
|
||||
private utilsService: UtilsService, private totpService: any, private stateService: StateService,
|
||||
private $timeout: ng.ITimeoutService) {
|
||||
private storageService: StorageService, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
@@ -25,22 +26,22 @@ export class OptionsController {
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.enableAutoFillOnPageLoad = await this.utilsService.getObjFromStorage<boolean>(
|
||||
this.enableAutoFillOnPageLoad = await this.storageService.get<boolean>(
|
||||
this.constantsService.enableAutoFillOnPageLoadKey);
|
||||
|
||||
const disableGa = await this.utilsService.getObjFromStorage<boolean>(
|
||||
const disableGa = await this.storageService.get<boolean>(
|
||||
this.constantsService.disableGaKey);
|
||||
this.disableGa = disableGa || (this.utilsService.isFirefox() && disableGa === undefined);
|
||||
|
||||
this.disableAddLoginNotification = await this.utilsService.getObjFromStorage<boolean>(
|
||||
this.disableAddLoginNotification = await this.storageService.get<boolean>(
|
||||
this.constantsService.disableAddLoginNotificationKey);
|
||||
|
||||
this.disableContextMenuItem = await this.utilsService.getObjFromStorage<boolean>(
|
||||
this.disableContextMenuItem = await this.storageService.get<boolean>(
|
||||
this.constantsService.disableContextMenuItemKey);
|
||||
|
||||
this.disableAutoTotpCopy = !await this.totpService.isAutoCopyEnabled();
|
||||
|
||||
this.disableFavicon = await this.utilsService.getObjFromStorage<boolean>(
|
||||
this.disableFavicon = await this.storageService.get<boolean>(
|
||||
this.constantsService.disableFaviconKey);
|
||||
}
|
||||
|
||||
@@ -50,18 +51,18 @@ export class OptionsController {
|
||||
}
|
||||
|
||||
updateGa() {
|
||||
this.utilsService.saveObjToStorage(this.constantsService.disableGaKey, this.disableGa);
|
||||
this.storageService.save(this.constantsService.disableGaKey, this.disableGa);
|
||||
this.callAnalytics('Analytics', !this.disableGa);
|
||||
}
|
||||
|
||||
updateAddLoginNotification() {
|
||||
this.utilsService.saveObjToStorage(this.constantsService.disableAddLoginNotificationKey,
|
||||
this.storageService.save(this.constantsService.disableAddLoginNotificationKey,
|
||||
this.disableAddLoginNotification);
|
||||
this.callAnalytics('Add Login Notification', !this.disableAddLoginNotification);
|
||||
}
|
||||
|
||||
updateDisableContextMenuItem() {
|
||||
this.utilsService.saveObjToStorage(this.constantsService.disableContextMenuItemKey,
|
||||
this.storageService.save(this.constantsService.disableContextMenuItemKey,
|
||||
this.disableContextMenuItem).then(() => {
|
||||
chrome.runtime.sendMessage({
|
||||
command: 'bgUpdateContextMenu',
|
||||
@@ -71,18 +72,18 @@ export class OptionsController {
|
||||
}
|
||||
|
||||
updateAutoTotpCopy() {
|
||||
this.utilsService.saveObjToStorage(this.constantsService.disableAutoTotpCopyKey, this.disableAutoTotpCopy);
|
||||
this.storageService.save(this.constantsService.disableAutoTotpCopyKey, this.disableAutoTotpCopy);
|
||||
this.callAnalytics('Auto Copy TOTP', !this.disableAutoTotpCopy);
|
||||
}
|
||||
|
||||
updateAutoFillOnPageLoad() {
|
||||
this.utilsService.saveObjToStorage(this.constantsService.enableAutoFillOnPageLoadKey,
|
||||
this.storageService.save(this.constantsService.enableAutoFillOnPageLoadKey,
|
||||
this.enableAutoFillOnPageLoad);
|
||||
this.callAnalytics('Auto-fill Page Load', this.enableAutoFillOnPageLoad);
|
||||
}
|
||||
|
||||
updateDisableFavicon() {
|
||||
this.utilsService.saveObjToStorage(this.constantsService.disableFaviconKey, this.disableFavicon);
|
||||
this.storageService.save(this.constantsService.disableFaviconKey, this.disableFavicon);
|
||||
this.stateService.saveState('faviconEnabled', !this.disableFavicon);
|
||||
this.callAnalytics('Favicon', !this.disableFavicon);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as angular from 'angular';
|
||||
import { BrowserType } from '../../../enums/browserType.enum';
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
import { StorageService } from '../../../services/abstractions/storage.service';
|
||||
import { UtilsService } from '../../../services/abstractions/utils.service';
|
||||
import ConstantsService from '../../../services/constants.service';
|
||||
|
||||
@@ -28,7 +29,8 @@ export class SettingsController {
|
||||
|
||||
constructor(private $state: any, private SweetAlert: any, private utilsService: UtilsService,
|
||||
private $analytics: any, private i18nService: any, private constantsService: ConstantsService,
|
||||
private cryptoService: CryptoService, private lockService: any, private $timeout: ng.ITimeoutService) {
|
||||
private cryptoService: CryptoService, private lockService: any, private storageService: StorageService,
|
||||
private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
@@ -36,7 +38,7 @@ export class SettingsController {
|
||||
}, 500);
|
||||
|
||||
this.showOnLocked = !utilsService.isFirefox() && !utilsService.isEdge();
|
||||
this.utilsService.getObjFromStorage(constantsService.lockOptionKey).then((lockOption: number) => {
|
||||
this.storageService.get(constantsService.lockOptionKey).then((lockOption: number) => {
|
||||
if (lockOption != null) {
|
||||
let option = lockOption.toString();
|
||||
if (option === '-2' && !this.showOnLocked) {
|
||||
@@ -51,7 +53,7 @@ export class SettingsController {
|
||||
|
||||
changeLockOption() {
|
||||
const option = this.lockOption && this.lockOption !== '' ? parseInt(this.lockOption, 10) : null;
|
||||
this.utilsService.saveObjToStorage(this.constantsService.lockOptionKey, option).then(() => {
|
||||
this.storageService.save(this.constantsService.lockOptionKey, option).then(() => {
|
||||
return this.cryptoService.getKeyHash();
|
||||
}).then((keyHash) => {
|
||||
if (keyHash) {
|
||||
|
||||
Reference in New Issue
Block a user