1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +02:00

Turn screen updating off if page becomes inactive.

This commit is contained in:
Simo Kinnunen 2014-05-13 18:57:22 +09:00
parent 8e5755137e
commit 8c72d79f92
6 changed files with 27 additions and 50 deletions

View file

@ -1,4 +1,4 @@
module.exports = angular.module('stf.page-visibility', [ module.exports = angular.module('stf.page-visibility', [
]) ])
.directive('pageVisibility', require('./page-visibility-directive')) .factory('PageVisibilityService', require('./page-visibility-service'))

View file

@ -1,26 +0,0 @@
module.exports = function pageVisibilityDirective($document, $rootScope) {
return {
restrict: 'A',
link: function (scope) {
function pageVisibilityChanged() {
if (document.hidden) {
$rootScope.$broadcast('pageHidden')
} else {
$rootScope.$broadcast('pageVisible')
// Application is visible to the user
// Adjust polling rates and display update for active display mode
}
}
document.addEventListener(
'visibilitychange'
, pageVisibilityChanged
, false
)
scope.$on('$destroy', function () {
angular.element(document).unbind('visibilitychange');
})
}
}
}

View file

@ -0,0 +1,15 @@
module.exports = function PageVisibilityServiceFactory($rootScope) {
var service = {}
function visibilityChangeListener() {
$rootScope.$broadcast('visibilitychange', document.hidden)
}
document.addEventListener(
'visibilitychange'
, visibilityChangeListener
, false
)
return service
}

View file

@ -1,23 +0,0 @@
describe('pageVisibility', function () {
beforeEach(module('stf.page-visibility'));
var scope, compile;
beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
compile = $compile;
}));
it('should ...', function () {
/*
To test your directive, you need to create some html that would use your
directive, send that through compile() then compare the results.
var element = compile('<div page-visibility name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world');
*/
});
});

View file

@ -1,6 +1,7 @@
module.exports = angular.module('stf/screen', [ module.exports = angular.module('stf/screen', [
require('stf/screen/scaling').name require('stf/screen/scaling').name
, require('stf/util/vendor').name , require('stf/util/vendor').name
, require('stf/page-visibility').name
]) ])
.directive('deviceScreen', require('./screen-directive')) .directive('deviceScreen', require('./screen-directive'))
.controller('DeviceScreenCtrl', require('./screen-controller')) .controller('DeviceScreenCtrl', require('./screen-controller'))

View file

@ -4,6 +4,7 @@ module.exports = function DeviceScreenDirective(
$document $document
, ScalingService , ScalingService
, VendorUtil , VendorUtil
, PageVisibilityService
) { ) {
return { return {
restrict: 'E', restrict: 'E',
@ -241,6 +242,15 @@ module.exports = function DeviceScreenDirective(
} }
}) })
scope.$on('visibilitychange', function(e, hidden) {
if (hidden) {
off()
}
else {
on()
}
})
scope.$watch('device.display.orientation', function(r) { scope.$watch('device.display.orientation', function(r) {
rotation = r || 0 rotation = r || 0
}) })