2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-05-13 03:00:34 +00:00
|
|
|
import Ember from 'ember';
|
2018-03-06 22:14:20 +00:00
|
|
|
import Mixin from '@ember/object/mixin';
|
2018-03-08 19:15:43 +00:00
|
|
|
import { assert } from '@ember/debug';
|
2019-10-15 18:32:58 +00:00
|
|
|
import { on } from '@ember/object/evented';
|
2018-03-06 22:14:20 +00:00
|
|
|
|
2020-06-09 21:03:28 +00:00
|
|
|
// eslint-disable-next-line ember/no-new-mixins
|
2018-03-06 22:14:20 +00:00
|
|
|
export default Mixin.create({
|
2018-03-08 19:15:43 +00:00
|
|
|
visibilityHandler() {
|
|
|
|
assert('visibilityHandler needs to be overridden in the Route', false);
|
|
|
|
},
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
setupDocumentVisibility: on('activate', function () {
|
2018-05-13 03:00:34 +00:00
|
|
|
if (!Ember.testing) {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.set('_visibilityHandler', this.visibilityHandler.bind(this));
|
|
|
|
document.addEventListener('visibilitychange', this._visibilityHandler);
|
2018-05-13 03:00:34 +00:00
|
|
|
}
|
2019-10-15 18:32:58 +00:00
|
|
|
}),
|
2018-03-06 22:14:20 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
removeDocumentVisibility: on('deactivate', function () {
|
2018-05-13 03:00:34 +00:00
|
|
|
if (!Ember.testing) {
|
2019-03-26 07:46:44 +00:00
|
|
|
document.removeEventListener('visibilitychange', this._visibilityHandler);
|
2018-05-13 03:00:34 +00:00
|
|
|
}
|
2019-10-15 18:32:58 +00:00
|
|
|
}),
|
2018-03-06 22:14:20 +00:00
|
|
|
});
|