Files
doneit-web/src/app/services/inativity.service.ts
T
Peter Maquiran 31f74933b7 remove alert
2023-02-22 09:31:14 +01:00

38 lines
1.0 KiB
TypeScript

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,
) {
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
function userIsNotActive() {
// your function for too long inactivity goes here
SessionStore.setInativity(false)
try {
window['inactivity/function']()
} catch (error) {}
}
function resetTimer() {
clearTimeout(time);
time = setTimeout(userIsNotActive, 60000 * 15); // time is in milliseconds
}
}
}