user active check implemented for MacOS
This commit is contained in:
parent
fa2aad8251
commit
ab947aec6e
@ -9,7 +9,7 @@ from openrecall.config import screenshots_path, args
|
||||
from openrecall.database import insert_entry
|
||||
from openrecall.nlp import get_embedding
|
||||
from openrecall.ocr import extract_text_from_image
|
||||
from openrecall.utils import get_active_app_name, get_active_window_title
|
||||
from openrecall.utils import get_active_app_name, get_active_window_title, is_user_active
|
||||
|
||||
|
||||
def mean_structured_similarity_index(img1, img2, L=255):
|
||||
@ -55,9 +55,16 @@ def take_screenshots(monitor=1):
|
||||
|
||||
|
||||
def record_screenshots_thread():
|
||||
# TODO: fix the error from huggingface tokenizers
|
||||
import os
|
||||
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
||||
|
||||
last_screenshots = take_screenshots()
|
||||
|
||||
while True:
|
||||
if not is_user_active():
|
||||
time.sleep(3)
|
||||
continue
|
||||
|
||||
screenshots = take_screenshots()
|
||||
|
||||
|
@ -106,3 +106,44 @@ def get_active_window_title():
|
||||
return get_active_window_title_linux()
|
||||
else:
|
||||
raise NotImplementedError("This platform is not supported")
|
||||
|
||||
def is_user_active_osx():
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
# Run the 'ioreg' command to get idle time information
|
||||
output = subprocess.check_output(["ioreg", "-c", "IOHIDSystem"]).decode()
|
||||
|
||||
# Find the line containing "HIDIdleTime"
|
||||
for line in output.split('\n'):
|
||||
if "HIDIdleTime" in line:
|
||||
# Extract the idle time value
|
||||
idle_time = int(line.split('=')[-1].strip())
|
||||
|
||||
# Convert idle time from nanoseconds to seconds
|
||||
idle_seconds = idle_time / 1000000000
|
||||
|
||||
# If idle time is less than 5 seconds, consider the user not idle
|
||||
return idle_seconds < 5
|
||||
|
||||
# If "HIDIdleTime" is not found, assume the user is not idle
|
||||
return True
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
# If there's an error running the command, assume the user is not idle
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
# If there's any other error, assume the user is not idle
|
||||
return True
|
||||
|
||||
def is_user_active():
|
||||
if sys.platform == "win32":
|
||||
return True
|
||||
elif sys.platform == "darwin":
|
||||
return is_user_active_osx()
|
||||
elif sys.platform.startswith("linux"):
|
||||
return True
|
||||
else:
|
||||
raise NotImplementedError("This platform is not supported")
|
||||
|
Loading…
Reference in New Issue
Block a user