mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-06 00:48:08 +02:00
move icon component into jslib
This commit is contained in:
parent
24f86e9a73
commit
9d29dd5853
2
jslib
2
jslib
@ -1 +1 @@
|
||||
Subproject commit 013bf20a35c74383389337ac2c5ae9ac19a0bba7
|
||||
Subproject commit d429cd2199e8a0880dfc0edbaea5fcad874eb424
|
@ -20,7 +20,7 @@ import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType';
|
||||
|
||||
import { ApiService } from 'jslib/abstractions/api.service';
|
||||
import { AuthService } from 'jslib/abstractions/auth.service';
|
||||
import { EnvironmentService } from 'jslib/services/environment.service';
|
||||
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||
|
@ -42,7 +42,7 @@ import { AttachmentsComponent } from './vault/attachments.component';
|
||||
import { CiphersComponent } from './vault/ciphers.component';
|
||||
import { FolderAddEditComponent } from './vault/folder-add-edit.component';
|
||||
import { GroupingsComponent } from './vault/groupings.component';
|
||||
import { IconComponent } from './vault/icon.component';
|
||||
import { IconComponent } from 'jslib/angular/components/icon.component';
|
||||
import { PasswordGeneratorHistoryComponent } from './vault/password-generator-history.component';
|
||||
import { PasswordGeneratorComponent } from './vault/password-generator.component';
|
||||
import { VaultComponent } from './vault/vault.component';
|
||||
|
@ -1,4 +0,0 @@
|
||||
<div class="icon">
|
||||
<img [src]="image" appFallbackSrc="{{fallbackImage}}" *ngIf="imageEnabled && image" alt="" />
|
||||
<i class="fa fa-fw fa-lg {{icon}}" *ngIf="!imageEnabled || !image"></i>
|
||||
</div>
|
@ -1,91 +0,0 @@
|
||||
import * as template from './icon.component.html';
|
||||
|
||||
import {
|
||||
Component,
|
||||
Input,
|
||||
OnChanges,
|
||||
} from '@angular/core';
|
||||
|
||||
import { CipherType } from 'jslib/enums/cipherType';
|
||||
|
||||
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { StateService } from 'jslib/abstractions/state.service';
|
||||
|
||||
import { ConstantsService } from 'jslib/services/constants.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-vault-icon',
|
||||
template: template,
|
||||
})
|
||||
export class IconComponent implements OnChanges {
|
||||
@Input() cipher: any;
|
||||
icon: string;
|
||||
image: string;
|
||||
fallbackImage: string;
|
||||
imageEnabled: boolean;
|
||||
|
||||
private iconsUrl: string;
|
||||
|
||||
constructor(private environmentService: EnvironmentService, private stateService: StateService) {
|
||||
this.iconsUrl = environmentService.iconsUrl;
|
||||
if (!this.iconsUrl) {
|
||||
if (environmentService.baseUrl) {
|
||||
this.iconsUrl = environmentService.baseUrl + '/icons';
|
||||
} else {
|
||||
this.iconsUrl = 'https://icons.bitwarden.com';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async ngOnChanges() {
|
||||
this.imageEnabled = !(await this.stateService.get<boolean>(ConstantsService.disableFaviconKey));
|
||||
|
||||
switch (this.cipher.type) {
|
||||
case CipherType.Login:
|
||||
this.icon = 'fa-globe';
|
||||
this.setLoginIcon();
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
this.icon = 'fa-sticky-note-o';
|
||||
break;
|
||||
case CipherType.Card:
|
||||
this.icon = 'fa-credit-card';
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
this.icon = 'fa-id-card-o';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private setLoginIcon() {
|
||||
if (this.cipher.login.uri) {
|
||||
let hostnameUri = this.cipher.login.uri;
|
||||
let isWebsite = false;
|
||||
|
||||
if (hostnameUri.indexOf('androidapp://') === 0) {
|
||||
this.icon = 'fa-android';
|
||||
this.image = null;
|
||||
} else if (hostnameUri.indexOf('iosapp://') === 0) {
|
||||
this.icon = 'fa-apple';
|
||||
this.image = null;
|
||||
} else if (this.imageEnabled && hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('.') > -1) {
|
||||
hostnameUri = 'http://' + hostnameUri;
|
||||
isWebsite = true;
|
||||
} else if (this.imageEnabled) {
|
||||
isWebsite = hostnameUri.indexOf('http') === 0 && hostnameUri.indexOf('.') > -1;
|
||||
}
|
||||
|
||||
if (this.imageEnabled && isWebsite) {
|
||||
try {
|
||||
const url = new URL(hostnameUri);
|
||||
this.image = this.iconsUrl + '/' + url.hostname + '/icon.png';
|
||||
this.fallbackImage = 'images/fa-globe.png';
|
||||
} catch (e) { }
|
||||
}
|
||||
} else {
|
||||
this.image = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user