I am creating a chrome app with a USB device. In my main app.js, I want to always check when a device is added / removed and change the 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 redirection does not work in async function.
Edit:
I found a similar question. How to call $ urlRouterProvider.otherwise () after loading a JSON file? , and the first answer describes that this is not possible. But how can I solve this problem. I need to check that usb remove / add globally and change views based on this.
source
share