1
- /* globals Meteor, Tracker, RocketChat */
1
+ /* globals Meteor, Tracker, RocketChat, UserPresence */
2
2
'use strict' ;
3
3
4
4
const { ipcRenderer, shell } = require ( 'electron' ) ;
@@ -15,6 +15,20 @@ events.forEach(function (e) {
15
15
} ) ;
16
16
} ) ;
17
17
18
+ const userPresenceControl = ( ) => {
19
+ const INTERVAL = 10000 ; // 10s
20
+ setInterval ( ( ) => {
21
+ try {
22
+ const idleTime = ipcRenderer . sendSync ( 'getSystemIdleTime' ) ;
23
+ if ( idleTime < INTERVAL ) {
24
+ UserPresence . setOnline ( ) ;
25
+ }
26
+ } catch ( e ) {
27
+ console . error ( `Error getting system idle time: ${ e } ` ) ;
28
+ }
29
+ } , INTERVAL ) ;
30
+ } ;
31
+
18
32
window . addEventListener ( 'load' , function ( ) {
19
33
Meteor . startup ( function ( ) {
20
34
Tracker . autorun ( function ( ) {
@@ -24,8 +38,8 @@ window.addEventListener('load', function () {
24
38
}
25
39
} ) ;
26
40
} ) ;
41
+ userPresenceControl ( ) ;
27
42
} ) ;
28
-
29
43
window . onload = function ( ) {
30
44
const $ = require ( './vendor/jquery-3.1.1' ) ;
31
45
function checkExternalUrl ( e ) {
@@ -34,7 +48,6 @@ window.onload = function () {
34
48
if ( RegExp ( `^${ location . protocol } \/\/${ location . host } ` ) . test ( href ) ) {
35
49
return ;
36
50
}
37
-
38
51
// Check href matching relative URL
39
52
if ( ! / ^ ( [ a - z ] + : ) ? \/ \/ / . test ( href ) ) {
40
53
return ;
@@ -65,19 +78,3 @@ document.addEventListener('drop', e => e.preventDefault());
65
78
66
79
const spellChecker = new SpellCheck ( ) ;
67
80
spellChecker . enable ( ) ;
68
-
69
- /**
70
- * Keep user online if they are still using their computer
71
- */
72
- const AWAY_TIME = 300000 ; // 5 mins
73
- const INTERVAL = 10000 ; // 10 seconds
74
- setInterval ( function ( ) {
75
- try {
76
- const idleTime = ipcRenderer . sendSync ( 'getSystemIdleTime' ) ;
77
- if ( idleTime < AWAY_TIME ) {
78
- Meteor . call ( 'UserPresence:online' ) ;
79
- }
80
- } catch ( e ) {
81
- console . error ( `Error getting system idle time: ${ e } ` ) ;
82
- }
83
- } , INTERVAL ) ;
0 commit comments