1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-17 15:37:57 +01:00

apply settings with state service.

This commit is contained in:
Kyle Spearrin 2018-02-12 15:06:39 -05:00
parent 3bb03d13d7
commit 3ee71a2b5b
6 changed files with 50 additions and 12 deletions

View File

@ -9,7 +9,8 @@
<div class="box-content box-content-padded"> <div class="box-content box-content-padded">
<div class="form-group"> <div class="form-group">
<label for="lockOption">{{'lockOptions' | i18n}}</label> <label for="lockOption">{{'lockOptions' | i18n}}</label>
<select id="lockOption" name="LockOption" [(ngModel)]="lockOption" (change)="save()"> <select id="lockOption" name="LockOption" [(ngModel)]="lockOption"
(change)="saveLockOption()">
<option *ngFor="let o of lockOptions" [ngValue]="o.value">{{o.name}}</option> <option *ngFor="let o of lockOptions" [ngValue]="o.value">{{o.name}}</option>
</select> </select>
<small class="help-block">{{'lockOptionsDesc' | i18n}}</small> <small class="help-block">{{'lockOptionsDesc' | i18n}}</small>
@ -25,7 +26,7 @@
<div class="checkbox"> <div class="checkbox">
<label for="disableGa"> <label for="disableGa">
<input id="disableGa" type="checkbox" name="DisableAnalytics" <input id="disableGa" type="checkbox" name="DisableAnalytics"
[(ngModel)]="disableGa" (change)="save()"> [(ngModel)]="disableGa" (change)="saveGa()">
{{'disableGa' | i18n}} {{'disableGa' | i18n}}
</label> </label>
</div> </div>
@ -33,9 +34,9 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<label for="disableFavicon"> <label for="disableFavicons">
<input id="disableFavicon" type="checkbox" name="DisableFavicon" <input id="disableFavicons" type="checkbox" name="DisableFavicons"
[(ngModel)]="disableFavicons" (change)="save()"> [(ngModel)]="disableFavicons" (change)="saveFavicons()">
{{'disableFavicon' | i18n}} {{'disableFavicon' | i18n}}
</label> </label>
</div> </div>

View File

@ -10,7 +10,9 @@ import { Angulartics2 } from 'angulartics2';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { LockService } from 'jslib/abstractions/lock.service'; import { LockService } from 'jslib/abstractions/lock.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StateService } from 'jslib/abstractions/state.service';
import { StorageService } from 'jslib/abstractions/storage.service'; import { StorageService } from 'jslib/abstractions/storage.service';
import { ConstantsService } from 'jslib/services/constants.service'; import { ConstantsService } from 'jslib/services/constants.service';
@ -27,7 +29,8 @@ export class SettingsComponent implements OnInit {
constructor(private analytics: Angulartics2, private toasterService: ToasterService, constructor(private analytics: Angulartics2, private toasterService: ToasterService,
private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService,
private storageService: StorageService, private lockService: LockService) { private storageService: StorageService, private lockService: LockService,
private stateService: StateService, private messagingService: MessagingService) {
this.lockOptions = [ this.lockOptions = [
// { name: i18nService.t('immediately'), value: 0 }, // { name: i18nService.t('immediately'), value: 0 },
{ name: i18nService.t('oneMinute'), value: 1 }, { name: i18nService.t('oneMinute'), value: 1 },
@ -50,9 +53,29 @@ export class SettingsComponent implements OnInit {
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey); this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
} }
async save() { async saveLockOption() {
await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null); await this.lockService.setLockOption(this.lockOption != null ? this.lockOption : null);
}
async saveGa() {
if (this.disableGa) {
this.callAnalytics('Analytics', !this.disableGa);
}
await this.storageService.save(ConstantsService.disableGaKey, this.disableGa); await this.storageService.save(ConstantsService.disableGaKey, this.disableGa);
if (!this.disableGa) {
this.callAnalytics('Analytics', !this.disableGa);
}
}
async saveFavicons() {
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicons); await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicons);
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicons);
this.messagingService.send('refreshCiphers');
this.callAnalytics('Favicons', !this.disableGa);
}
private callAnalytics(name: string, enabled: boolean) {
const status = enabled ? 'Enabled' : 'Disabled';
this.analytics.eventTrack.next({ action: `${status} ${name}` });
} }
} }

View File

@ -33,6 +33,7 @@ import {
LockService, LockService,
PasswordGenerationService, PasswordGenerationService,
SettingsService, SettingsService,
StateService,
SyncService, SyncService,
TokenService, TokenService,
TotpService, TotpService,
@ -55,6 +56,7 @@ import {
PasswordGenerationService as PasswordGenerationServiceAbstraction, PasswordGenerationService as PasswordGenerationServiceAbstraction,
PlatformUtilsService as PlatformUtilsServiceAbstraction, PlatformUtilsService as PlatformUtilsServiceAbstraction,
SettingsService as SettingsServiceAbstraction, SettingsService as SettingsServiceAbstraction,
StateService as StateServiceAbstraction,
StorageService as StorageServiceAbstraction, StorageService as StorageServiceAbstraction,
SyncService as SyncServiceAbstraction, SyncService as SyncServiceAbstraction,
TokenService as TokenServiceAbstraction, TokenService as TokenServiceAbstraction,
@ -67,6 +69,7 @@ webFrame.registerURLSchemeAsPrivileged('file');
const i18nService = new I18nService(window.navigator.language, './locales'); const i18nService = new I18nService(window.navigator.language, './locales');
const utilsService = new UtilsService(); const utilsService = new UtilsService();
const stateService = new StateService();
const platformUtilsService = new DesktopPlatformUtilsService(i18nService); const platformUtilsService = new DesktopPlatformUtilsService(i18nService);
const broadcasterService = new BroadcasterService(); const broadcasterService = new BroadcasterService();
const messagingService = new DesktopRendererMessagingService(broadcasterService); const messagingService = new DesktopRendererMessagingService(broadcasterService);
@ -111,6 +114,8 @@ function initFactory(i18n: I18nService, platformUtils: DesktopPlatformUtilsServi
const htmlEl = window.document.documentElement; const htmlEl = window.document.documentElement;
htmlEl.classList.add('os_' + platformUtils.getDeviceString()); htmlEl.classList.add('os_' + platformUtils.getDeviceString());
htmlEl.classList.add('locale_' + i18n.translationLocale); htmlEl.classList.add('locale_' + i18n.translationLocale);
stateService.save(ConstantsService.disableFaviconKey,
await storageService.get<boolean>(ConstantsService.disableFaviconKey));
}; };
} }
@ -142,6 +147,7 @@ function initFactory(i18n: I18nService, platformUtils: DesktopPlatformUtilsServi
{ provide: SettingsServiceAbstraction, useValue: settingsService }, { provide: SettingsServiceAbstraction, useValue: settingsService },
{ provide: LockServiceAbstraction, useValue: lockService }, { provide: LockServiceAbstraction, useValue: lockService },
{ provide: StorageServiceAbstraction, useValue: storageService }, { provide: StorageServiceAbstraction, useValue: storageService },
{ provide: StateServiceAbstraction, useValue: stateService },
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: initFactory, useFactory: initFactory,

View File

@ -42,6 +42,8 @@ export class CiphersComponent {
} }
async refresh() { async refresh() {
this.loaded = false;
this.ciphers = [];
await this.load(this.filter); await this.load(this.filter);
} }

View File

@ -9,6 +9,9 @@ import {
import { CipherType } from 'jslib/enums/cipherType'; import { CipherType } from 'jslib/enums/cipherType';
import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { StateService } from 'jslib/abstractions/state.service';
import { ConstantsService } from 'jslib/services/constants.service';
@Component({ @Component({
selector: 'app-vault-icon', selector: 'app-vault-icon',
@ -23,9 +26,7 @@ export class IconComponent implements OnChanges {
private iconsUrl: string; private iconsUrl: string;
constructor(private environmentService: EnvironmentService) { constructor(private environmentService: EnvironmentService, private stateService: StateService) {
this.imageEnabled = true; // TODO
this.iconsUrl = environmentService.iconsUrl; this.iconsUrl = environmentService.iconsUrl;
if (!this.iconsUrl) { if (!this.iconsUrl) {
if (environmentService.baseUrl) { if (environmentService.baseUrl) {
@ -36,7 +37,9 @@ export class IconComponent implements OnChanges {
} }
} }
ngOnChanges() { async ngOnChanges() {
this.imageEnabled = !(await this.stateService.get<boolean>(ConstantsService.disableFaviconKey));
switch (this.cipher.type) { switch (this.cipher.type) {
case CipherType.Login: case CipherType.Login:
this.icon = 'fa-globe'; this.icon = 'fa-globe';

View File

@ -129,6 +129,9 @@ export class VaultComponent implements OnInit, OnDestroy {
await this.load(); await this.load();
} }
break; break;
case 'refreshCiphers':
this.ciphersComponent.refresh();
break;
default: default:
detectChanges = false; detectChanges = false;
break; break;