mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
promise conversions
This commit is contained in:
@@ -1,35 +1,27 @@
|
||||
function AppIdService() {
|
||||
function AppIdService(utilsService) {
|
||||
this.utilsService = utilsService;
|
||||
|
||||
initAppIdService();
|
||||
}
|
||||
|
||||
function initAppIdService() {
|
||||
AppIdService.prototype.getAppId = function (callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
makeAndGetAppId('appId', callback);
|
||||
AppIdService.prototype.getAppId = function () {
|
||||
return makeAndGetAppId('appId', this);
|
||||
};
|
||||
|
||||
AppIdService.prototype.getAnonymousAppId = function (callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
makeAndGetAppId('anonymousAppId', callback);
|
||||
AppIdService.prototype.getAnonymousAppId = function () {
|
||||
return makeAndGetAppId('anonymousAppId', this);
|
||||
};
|
||||
|
||||
function makeAndGetAppId(key, callback) {
|
||||
chrome.storage.local.get(key, function (obj) {
|
||||
if (obj && obj[key]) {
|
||||
callback(obj[key]);
|
||||
return;
|
||||
function makeAndGetAppId(key, self) {
|
||||
return self.utilsService.getObjFromStorage(key).then(function (obj) {
|
||||
if (obj) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
var setObj = {};
|
||||
setObj[key] = newGuid();
|
||||
chrome.storage.local.set(setObj, function () {
|
||||
callback(setObj[key]);
|
||||
var guid = newGuid();
|
||||
return self.utilsService.saveObjToStorage(key, guid).then(function () {
|
||||
return guid;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
function TokenService(utilsService) {
|
||||
this.utilsService = utilsService;
|
||||
|
||||
initTokenService();
|
||||
}
|
||||
|
||||
@@ -97,20 +98,9 @@ function initTokenService() {
|
||||
});
|
||||
};
|
||||
|
||||
TokenService.prototype.getTwoFactorToken = function (email, callback) {
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
throw 'callback function required';
|
||||
}
|
||||
|
||||
var prop = 'twoFactorToken_' + email;
|
||||
|
||||
chrome.storage.local.get(prop, function (obj) {
|
||||
if (obj && obj[prop]) {
|
||||
callback(obj[prop]);
|
||||
return;
|
||||
}
|
||||
|
||||
return callback(null);
|
||||
TokenService.prototype.getTwoFactorToken = function (email) {
|
||||
return this.utilsService.getObjFromStorage('twoFactorToken_' + email).then(function (token) {
|
||||
return token;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user