diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-13 19:41:20 +0100 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-11-15 13:23:28 +0100 |
commit | 693c4f4c5c096e067b7d5621f595e26f2b794824 (patch) | |
tree | 3bf778629ccf42159f7f98bb12168b4c2b8ecce1 /src/windows | |
parent | 7e8d5e71ce2a441faa85a178481f4ef30a7901d5 (diff) |
src: add user session detection implementation
Detect user login and logout for Linux and Windows.
Poll the session change in 5 second intervals in a thread. Use the
same event socket previously used by the old session detection
mechanism to notify a session change.
Report an active interactive session through the /refresh response
so a new ogserver instance can update the session status.
Diffstat (limited to 'src/windows')
-rw-r--r-- | src/windows/ogOperations.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/windows/ogOperations.py b/src/windows/ogOperations.py index bc7e954..ef4e308 100644 --- a/src/windows/ogOperations.py +++ b/src/windows/ogOperations.py @@ -8,11 +8,13 @@ import os import ctypes +import pythoncom import subprocess from subprocess import CalledProcessError import multiprocessing as mp from multiprocessing import Process, freeze_support from src.log import OgError +import wmi from PIL import Image, ImageDraw from pystray import Icon, Menu, MenuItem @@ -64,6 +66,7 @@ def create_systray(): class OgWindowsOperations: def __init__(self): + self.session = False freeze_support() mp.set_start_method('spawn') self.systray_p = Process(target=create_systray, daemon=True) @@ -125,4 +128,30 @@ class OgWindowsOperations: raise OgError('Function not implemented') def refresh(self, ogRest): - return {"status": "WIN"} + if self.session: + session_value = 'WINS' + else: + session_value = 'WIN' + return {"status": session_value} + + def check_interactive_session_change(self): + old_status = self.session + pythoncom.CoInitialize() + has_logged_user = False + try: + c = wmi.WMI() + sessions = c.Win32_LogonSession(LogonType=2) + + for session in sessions: + if has_logged_user: + break + for user in session.associators("Win32_LoggedOnUser"): + has_logged_user = True + break + finally: + pythoncom.CoUninitialize() + self.session = has_logged_user + + if self.session != old_status: + return self.session + return None |