i'm building a chrome app with USB device. In my main app.js i want always check when device added/removed and change url.
angular.module('rfApp', [
'ngRoute',
'ngMaterial',
'rfApp.view1',
'rfApp.view2',
'rfApp.device_not_found'
]).config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
function checkForDevices() {
RFFWHID.getDevices(function(current_devices) {
if(current_devices.length > 0) {
$routeProvider.otherwise({redirectTo: '/view1'});
} else {
$routeProvider.otherwise({redirectTo: '/device_not_found'});
}
});
}
chrome.hid.onDeviceAdded.addListener(function(){
checkForDevices();
});
chrome.hid.onDeviceRemoved.addListener(function(){
checkForDevices();
});
checkForDevices();
}]);
But redirect not working in async function.
Edit:
I found similar question How to call $urlRouterProvider.otherwise() after loading JSON file?, and first answer describes that it is impossible. But how i can solve this problem. I need to check for usb remove/add globally and change views based on that.