Wallet/src/js/services/applicationService.js

107 lines
3 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.services')
2017-05-09 16:42:41 -03:00
.factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, fingerprintService, openURLService, configService, $state) {
2015-03-06 12:00:10 -03:00
var root = {};
2017-05-09 18:33:31 -03:00
root.isPinModalOpen = false;
2016-08-23 12:01:09 -03:00
var isChromeApp = platformInfo.isChromeApp;
var isNW = platformInfo.isNW;
2015-06-11 12:53:38 -03:00
root.restart = function() {
var hashIndex = window.location.href.indexOf('#/');
if (platformInfo.isCordova) {
2015-06-11 12:53:38 -03:00
window.location = window.location.href.substr(0, hashIndex);
2015-03-06 12:00:10 -03:00
$timeout(function() {
$rootScope.$digest();
}, 1);
} else {
// Go home reloading the application
2015-04-17 13:01:02 -03:00
if (isChromeApp) {
2015-10-28 11:28:12 -03:00
chrome.runtime.reload();
} else if (isNW) {
2016-09-23 12:42:33 -03:00
$ionicHistory.removeBackView();
2016-08-19 13:07:18 -03:00
$state.go('tabs.home');
2015-10-28 11:28:12 -03:00
$timeout(function() {
var win = require('nw.gui').Window.get();
win.reload(3);
//or
win.reloadDev();
}, 100);
2015-04-17 13:01:02 -03:00
} else {
window.location = window.location.href.substr(0, hashIndex);
}
2015-03-06 12:00:10 -03:00
}
};
2017-05-09 16:42:41 -03:00
root.fingerprintModal = function() {
2017-05-09 18:33:31 -03:00
var scope = $rootScope.$new(true);
$ionicModal.fromTemplateUrl('views/modals/fingerprintCheck.html', {
scope: scope,
animation: 'none',
backdropClickToClose: false,
hardwareBackButtonClose: false
}).then(function(modal) {
scope.fingerprintCheckModal = modal;
scope.openModal();
2017-05-09 16:42:41 -03:00
});
2017-05-09 18:33:31 -03:00
scope.openModal = function() {
scope.fingerprintCheckModal.show();
checkFingerprint();
};
scope.hideModal = function() {
scope.fingerprintCheckModal.hide();
};
function checkFingerprint() {
fingerprintService.check('unlockingApp', function(err) {
if (err) {
checkFingerprint();
return;
}
scope.hideModal();
});
}
2017-05-09 16:42:41 -03:00
};
2017-05-09 12:36:32 -03:00
root.pinModal = function(action) {
2017-05-09 11:48:12 -03:00
2017-05-09 18:33:31 -03:00
if (root.isPinModalOpen) return;
2017-05-09 11:48:12 -03:00
var scope = $rootScope.$new(true);
2017-05-09 12:36:32 -03:00
scope.action = action;
$ionicModal.fromTemplateUrl('views/modals/pin.html', {
2017-05-09 11:48:12 -03:00
scope: scope,
2017-05-09 16:42:41 -03:00
animation: 'none',
2017-05-09 11:48:12 -03:00
backdropClickToClose: false,
hardwareBackButtonClose: false
}).then(function(modal) {
2017-05-09 12:36:32 -03:00
scope.pinModal = modal;
2017-05-09 18:33:31 -03:00
root.isPinModalOpen = true;
2017-05-09 12:36:32 -03:00
scope.openModal();
2017-05-09 11:48:12 -03:00
});
scope.openModal = function() {
2017-05-09 12:36:32 -03:00
scope.pinModal.show();
2017-05-09 11:48:12 -03:00
};
2017-05-09 12:36:32 -03:00
scope.hideModal = function() {
2017-05-09 16:42:41 -03:00
scope.$emit('pinModalClosed');
2017-05-09 18:33:31 -03:00
root.isPinModalOpen = false;
2017-05-09 12:36:32 -03:00
scope.pinModal.hide();
2017-05-09 11:48:12 -03:00
};
2017-05-09 16:42:41 -03:00
};
root.appLockModal = function(action) {
configService.whenAvailable(function(config) {
var lockMethod = config.lock && config.lock.method;
if (!lockMethod || lockMethod == 'none') return;
if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) root.fingerprintModal();
if (lockMethod == 'pin') root.pinModal(action);
2017-05-09 11:48:12 -03:00
});
}
2015-03-06 12:00:10 -03:00
return root;
});