Files
doneit-web/src/app/services/inativity.service.ts
T

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-08-27 13:39:52 +01:00
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { SessionStore } from '../store/session.service';
@Injectable({
providedIn: 'root'
})
export class InativityService {
constructor(
private router: Router,
) {
2023-01-09 10:49:58 +01:00
var time;
window.onload = resetTimer;
window.onmousemove = resetTimer;
window.onmousedown = resetTimer; // catches touchscreen presses as well
window.ontouchstart = resetTimer; // catches touchscreen swipes as well
window.onclick = resetTimer; // catches touchpad clicks as well
window.onkeydown = resetTimer;
window.addEventListener('scroll', resetTimer, true); // improved; see comments
2021-08-27 13:39:52 +01:00
2023-01-09 10:49:58 +01:00
function userIsNotActive() {
// your function for too long inactivity goes here
SessionStore.setInativity(false)
try {
window['inactivity/function']()
} catch (error) {}
2023-01-02 14:36:57 +01:00
2023-01-09 10:49:58 +01:00
}
2021-08-27 13:39:52 +01:00
2023-01-09 10:49:58 +01:00
function resetTimer() {
clearTimeout(time);
2023-01-12 15:27:09 +01:00
time = setTimeout(userIsNotActive, 60000 * 15); // time is in milliseconds
2023-01-09 10:49:58 +01:00
}
2021-08-27 13:39:52 +01:00
}
}