mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-18 10:55:48 +01:00
updates to icon component and state init
This commit is contained in:
parent
09c340bbe5
commit
cebf913999
@ -5,32 +5,28 @@ angular
|
||||
bindings: {
|
||||
cipher: '<'
|
||||
},
|
||||
template: '<div class="icon" ng-if="$ctrl.enabled">' +
|
||||
'<img ng-src="{{$ctrl.image}}" fallback-src="{{$ctrl.fallbackImage}}" ng-if="$ctrl.image" alt="" />' +
|
||||
'<i class="fa fa-fw fa-lg {{$ctrl.icon}}" ng-if="!$ctrl.image"></i>' +
|
||||
'</div>',
|
||||
templateUrl: 'app/components/views/icon.html',
|
||||
controller: function (stateService, constantsService) {
|
||||
var ctrl = this;
|
||||
ctrl.enabled = stateService.getState('faviconEnabled');
|
||||
ctrl.imageEnabled = stateService.getState('faviconEnabled');
|
||||
|
||||
ctrl.$onChanges = function () {
|
||||
if (ctrl.enabled) {
|
||||
switch (ctrl.cipher.type) {
|
||||
case constantsService.cipherType.login:
|
||||
setLoginIcon(ctrl.cipher);
|
||||
break;
|
||||
case constantsService.cipherType.secureNote:
|
||||
ctrl.icon = 'fa-sticky-note-o';
|
||||
break;
|
||||
case constantsService.cipherType.card:
|
||||
ctrl.icon = 'fa-credit-card';
|
||||
break;
|
||||
case constantsService.cipherType.identity:
|
||||
ctrl.icon = 'fa-id-card-o';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (ctrl.cipher.type) {
|
||||
case constantsService.cipherType.login:
|
||||
ctrl.icon = 'fa-globe';
|
||||
setLoginIcon(ctrl.cipher);
|
||||
break;
|
||||
case constantsService.cipherType.secureNote:
|
||||
ctrl.icon = 'fa-sticky-note-o';
|
||||
break;
|
||||
case constantsService.cipherType.card:
|
||||
ctrl.icon = 'fa-credit-card';
|
||||
break;
|
||||
case constantsService.cipherType.identity:
|
||||
ctrl.icon = 'fa-id-card-o';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@ -47,18 +43,16 @@ angular
|
||||
ctrl.icon = 'fa-apple';
|
||||
ctrl.image = null;
|
||||
}
|
||||
else if (hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 &&
|
||||
else if (ctrl.imageEnabled && hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 &&
|
||||
hostnameUri.indexOf('https://') !== 0) {
|
||||
hostnameUri = "http://" + hostnameUri;
|
||||
isWebsite = true;
|
||||
ctrl.icon = 'fa-globe';
|
||||
}
|
||||
else {
|
||||
else if (ctrl.imageEnabled) {
|
||||
isWebsite = hostnameUri.indexOf('http') === 0 && hostnameUri.indexOf('.') > 0;
|
||||
ctrl.icon = 'fa-globe';
|
||||
}
|
||||
|
||||
if (isWebsite) {
|
||||
if (ctrl.imageEnabled && isWebsite) {
|
||||
try {
|
||||
var url = new URL(hostnameUri);
|
||||
ctrl.image = 'https://icons.bitwarden.com/' + url.hostname + '/icon.png';
|
||||
@ -68,7 +62,6 @@ angular
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctrl.icon = 'fa-globe';
|
||||
ctrl.image = null;
|
||||
}
|
||||
}
|
||||
|
4
src/popup/app/components/views/icon.html
Normal file
4
src/popup/app/components/views/icon.html
Normal file
@ -0,0 +1,4 @@
|
||||
<div class="icon">
|
||||
<img ng-src="{{$ctrl.image}}" fallback-src="{{$ctrl.fallbackImage}}" ng-if="$ctrl.imageEnabled && $ctrl.image" alt="" />
|
||||
<i class="fa fa-fw fa-lg {{$ctrl.icon}}" ng-if="!$ctrl.imageEnabled || !$ctrl.image"></i>
|
||||
</div>
|
@ -2,7 +2,8 @@
|
||||
.module('bit')
|
||||
|
||||
.config(function ($stateProvider, $urlRouterProvider, $compileProvider, $sceDelegateProvider, toastrConfig) {
|
||||
$compileProvider.imgSrcSanitizationWhitelist(/^\s*((https?|ftp|file|blob):|data:image\/|(moz|chrome|ms-browser)-extension)/);
|
||||
$compileProvider.imgSrcSanitizationWhitelist(
|
||||
/^\s*((https?|ftp|file|blob):|data:image\/|(moz|chrome|ms-browser)-extension)/);
|
||||
|
||||
angular.extend(toastrConfig, {
|
||||
closeButton: true,
|
||||
@ -258,9 +259,7 @@
|
||||
});
|
||||
})
|
||||
.run(function ($rootScope, userService, $state, constantsService, stateService) {
|
||||
chrome.storage.local.get(constantsService.disableFaviconKey, function(obj) {
|
||||
stateService.saveState('faviconEnabled', !obj[constantsService.disableFaviconKey]);
|
||||
});
|
||||
stateService.init();
|
||||
|
||||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
||||
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
|
||||
|
@ -1,10 +1,16 @@
|
||||
angular
|
||||
.module('bit.services')
|
||||
|
||||
.factory('stateService', function () {
|
||||
.factory('stateService', function (utilsService, constantsService) {
|
||||
var _service = {},
|
||||
_state = {};
|
||||
|
||||
_service.init = function () {
|
||||
utilsService.getObjFromStorage(constantsService.disableFaviconKey).then(function (disabledFavicons) {
|
||||
_service.saveState('faviconEnabled', !disabledFavicons);
|
||||
});
|
||||
};
|
||||
|
||||
_service.saveState = function (key, data) {
|
||||
_state[key] = data;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user