mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 18:53:29 +00:00
move settings service to jslib
This commit is contained in:
@@ -21,12 +21,11 @@ import { ConstantsService } from 'jslib/services';
|
||||
import {
|
||||
ApiService,
|
||||
CryptoService,
|
||||
SettingsService,
|
||||
StorageService,
|
||||
UserService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
import SettingsService from './settings.service';
|
||||
|
||||
const Keys = {
|
||||
ciphersPrefix: 'ciphers_',
|
||||
localData: 'sitesLocalData',
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import {
|
||||
StorageService,
|
||||
UserService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
const Keys = {
|
||||
settingsPrefix: 'settings_',
|
||||
equivalentDomains: 'equivalentDomains',
|
||||
};
|
||||
|
||||
export default class SettingsService {
|
||||
private settingsCache: any;
|
||||
|
||||
constructor(private userService: UserService, private storageService: StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.settingsCache = null;
|
||||
}
|
||||
|
||||
getEquivalentDomains(): Promise<any> {
|
||||
return this.getSettingsKey(Keys.equivalentDomains);
|
||||
}
|
||||
|
||||
async setEquivalentDomains(equivalentDomains: string[][]) {
|
||||
await this.setSettingsKey(Keys.equivalentDomains, equivalentDomains);
|
||||
}
|
||||
|
||||
async clear(userId: string): Promise<void> {
|
||||
await this.storageService.remove(Keys.settingsPrefix + userId);
|
||||
this.settingsCache = null;
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
private async getSettings(): Promise<any> {
|
||||
if (this.settingsCache == null) {
|
||||
const userId = await this.userService.getUserId();
|
||||
this.settingsCache = this.storageService.get(Keys.settingsPrefix + userId);
|
||||
}
|
||||
return this.settingsCache;
|
||||
}
|
||||
|
||||
private async getSettingsKey(key: string): Promise<any> {
|
||||
const settings = await this.getSettings();
|
||||
if (settings != null && settings[key]) {
|
||||
return settings[key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async setSettingsKey(key: string, value: any): Promise<void> {
|
||||
const userId = await this.userService.getUserId();
|
||||
let settings = await this.getSettings();
|
||||
if (!settings) {
|
||||
settings = {};
|
||||
}
|
||||
|
||||
settings[key] = value;
|
||||
await this.storageService.save(Keys.settingsPrefix + userId, settings);
|
||||
this.settingsCache = settings;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import CipherService from './cipher.service';
|
||||
import CollectionService from './collection.service';
|
||||
import SettingsService from './settings.service';
|
||||
|
||||
import {
|
||||
ApiService,
|
||||
CryptoService,
|
||||
FolderService,
|
||||
MessagingService,
|
||||
SettingsService,
|
||||
StorageService,
|
||||
UserService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
Reference in New Issue
Block a user