1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

utils service. added browser detection method to utils

This commit is contained in:
Kyle Spearrin 2016-09-21 01:17:46 -04:00
parent 9a19acef22
commit 5b1172b8d0
5 changed files with 45 additions and 4 deletions

View File

@ -1,3 +1,4 @@
var utilsService = new UtilsService();
var cryptoService = new CryptoService();
var tokenService = new TokenService();
var apiService = new ApiService(tokenService);

View File

@ -30,7 +30,7 @@
"models/api/responseModels.js",
"models/dataModels.js",
"models/domainModels.js",
"services/cryptoService.js",
"services/utilsService.js",
"services/cryptoService.js",
"services/tokenService.js",
"services/apiService.js",

View File

@ -30,4 +30,7 @@
})
.factory('passwordGenerationService', function () {
return chrome.extension.getBackgroundPage().passwordGenerationService;
})
.factory('utilsService', function () {
return chrome.extension.getBackgroundPage().utilsService;
});

View File

@ -1,7 +1,7 @@
angular
.module('bit.settings')
.controller('settingsController', function ($scope, loginService, $state, syncService, SweetAlert) {
.controller('settingsController', function ($scope, loginService, $state, syncService, SweetAlert, utilsService) {
$scope.sync = function () {
syncService.fullSync(function () {
alert('Sync done!');
@ -65,7 +65,22 @@
}
$scope.rate = function () {
// TODO: detect which extension store to send them to
chrome.tabs.create({ url: 'https://google.com' });
switch (utilsService.getBrowser()) {
case 'chrome':
chrome.tabs.create({ url: 'https://chrome.com' });
break;
case 'firefox':
chrome.tabs.create({ url: 'https://firefox.com' });
break;
case 'edge':
chrome.tabs.create({ url: 'https://microsoft.com' });
break;
case 'opera':
chrome.tabs.create({ url: 'https://opera.com' });
break;
default:
return;
}
};
});

View File

@ -0,0 +1,22 @@
function UtilsService() {
initUtilsService();
};
function initUtilsService() {
UtilsService.prototype.getBrowser = function () {
if (navigator.userAgent.indexOf("Firefox") !== -1 || navigator.userAgent.indexOf("Gecko/") !== -1) {
return 'firefox';
}
if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
return 'opera';
}
if (navigator.userAgent.indexOf(" Edge/") !== -1) {
return 'edge';
}
if (window.chrome) {
return 'chrome';
}
return null;
};
};