mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
Turn screen updating off if page becomes inactive.
This commit is contained in:
parent
8e5755137e
commit
8c72d79f92
6 changed files with 27 additions and 50 deletions
|
@ -1,4 +1,4 @@
|
|||
module.exports = angular.module('stf.page-visibility', [
|
||||
|
||||
])
|
||||
.directive('pageVisibility', require('./page-visibility-directive'))
|
||||
.factory('PageVisibilityService', require('./page-visibility-service'))
|
||||
|
|
|
@ -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');
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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');
|
||||
*/
|
||||
|
||||
});
|
||||
});
|
|
@ -1,6 +1,7 @@
|
|||
module.exports = angular.module('stf/screen', [
|
||||
require('stf/screen/scaling').name
|
||||
, require('stf/util/vendor').name
|
||||
, require('stf/page-visibility').name
|
||||
])
|
||||
.directive('deviceScreen', require('./screen-directive'))
|
||||
.controller('DeviceScreenCtrl', require('./screen-controller'))
|
||||
|
|
|
@ -4,6 +4,7 @@ module.exports = function DeviceScreenDirective(
|
|||
$document
|
||||
, ScalingService
|
||||
, VendorUtil
|
||||
, PageVisibilityService
|
||||
) {
|
||||
return {
|
||||
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) {
|
||||
rotation = r || 0
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue