forked from shaba/openuds
Testing windows 8 idle
This commit is contained in:
parent
c2bd664545
commit
9094547f22
@ -54,6 +54,8 @@ trayIcon = None
|
|||||||
|
|
||||||
doLogoff = False
|
doLogoff = False
|
||||||
|
|
||||||
|
TIMER_TIMEOUT = 5 # In seconds
|
||||||
|
|
||||||
|
|
||||||
def sigTerm(sigNo, stackFrame):
|
def sigTerm(sigNo, stackFrame):
|
||||||
if trayIcon:
|
if trayIcon:
|
||||||
@ -209,20 +211,34 @@ class UDSSystemTray(QtGui.QSystemTrayIcon):
|
|||||||
|
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
|
|
||||||
self.timer.start(5000) # Launch idle checking every 5 seconds
|
self.resetTimervars()
|
||||||
self.graceTimerShots = 6 # Start counting for idle after 30 seconds after login, got on windows some "instant" logout because of idle timer not being reset??
|
self.timer.start(TIMER_TIMEOUT * 1000) # Launch idle checking every 5 seconds
|
||||||
|
|
||||||
self.ipc.start()
|
self.ipc.start()
|
||||||
# If this is running, it's because he have logged in
|
# If this is running, it's because he have logged in
|
||||||
self.ipc.sendLogin(operations.getCurrentUser())
|
self.ipc.sendLogin(operations.getCurrentUser())
|
||||||
|
|
||||||
|
def resetTimervars(self):
|
||||||
|
self.lastTimerTime = datetime.datetime.now()
|
||||||
|
self.graceTimerShots = 6 # Start counting for idle after 30 seconds after login, got on windows some "instant" logout because of idle timer not being reset??
|
||||||
|
|
||||||
def checkTimers(self):
|
def checkTimers(self):
|
||||||
|
# Check clock readjustment
|
||||||
|
# This is executed
|
||||||
|
elapsed_seconds = (datetime.datetime.now() - self.lastTimerTime).total_seconds()
|
||||||
|
if elapsed_seconds > TIMER_TIMEOUT * 4 or elapsed_seconds < 0:
|
||||||
|
# Clock has changed a lot, reset session variables, idle timer, etc..
|
||||||
|
self.resetTimervars()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.lastTimerTime = datetime.datetime.now()
|
||||||
|
|
||||||
self.checkIdle()
|
self.checkIdle()
|
||||||
self.checkMaxSession()
|
self.checkMaxSession()
|
||||||
|
|
||||||
def checkMaxSession(self):
|
def checkMaxSession(self):
|
||||||
if self.maxSessionTime is None or self.maxSessionTime == 0:
|
if self.maxSessionTime is None or self.maxSessionTime == 0:
|
||||||
logger.debug('Returning because maxSessionTime is cero')
|
logger.debug('Returning because maxSessionTime is zero')
|
||||||
return
|
return
|
||||||
|
|
||||||
remainingTime = self.maxSessionTime - (datetime.datetime.now() - self.sessionStart).total_seconds()
|
remainingTime = self.maxSessionTime - (datetime.datetime.now() - self.sessionStart).total_seconds()
|
||||||
@ -235,7 +251,7 @@ class UDSSystemTray(QtGui.QSystemTrayIcon):
|
|||||||
|
|
||||||
if remainingTime <= 0:
|
if remainingTime <= 0:
|
||||||
logger.debug('Remaining time is less than cero, exiting')
|
logger.debug('Remaining time is less than cero, exiting')
|
||||||
self.quit()
|
self.quit(extra=" (max session time {} {})".format(self.maxSessionTime, self.sessionStart))
|
||||||
|
|
||||||
def checkIdle(self):
|
def checkIdle(self):
|
||||||
if self.maxIdleTime is None: # No idle check
|
if self.maxIdleTime is None: # No idle check
|
||||||
|
@ -213,10 +213,10 @@ def getIdleDuration():
|
|||||||
lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)
|
lastInputInfo.cbSize = ctypes.sizeof(lastInputInfo)
|
||||||
if ctypes.windll.user32.GetLastInputInfo(ctypes.byref(lastInputInfo)) == 0:
|
if ctypes.windll.user32.GetLastInputInfo(ctypes.byref(lastInputInfo)) == 0:
|
||||||
return 0
|
return 0
|
||||||
if lastInputInfo.dwTime > 1000000000: # Value toooo high, nonsense...
|
# if lastInputInfo.dwTime > 1000000000: # Value toooo high, nonsense...
|
||||||
return 0
|
# return 0
|
||||||
millis = ctypes.windll.kernel32.GetTickCount() - lastInputInfo.dwTime # @UndefinedVariable
|
millis = ctypes.windll.kernel32.GetTickCount() - lastInputInfo.dwTime # @UndefinedVariable
|
||||||
if millis < 0:
|
if millis < 0 or millis > 1000000000:
|
||||||
return 0
|
return 0
|
||||||
return millis / 1000.0
|
return millis / 1000.0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user