diff --git a/openrecall/screenshot.py b/openrecall/screenshot.py index 02bbadf..1d092b9 100644 --- a/openrecall/screenshot.py +++ b/openrecall/screenshot.py @@ -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() diff --git a/openrecall/utils.py b/openrecall/utils.py index bc8af80..75f646d 100644 --- a/openrecall/utils.py +++ b/openrecall/utils.py @@ -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") + \ No newline at end of file diff --git a/setup.py b/setup.py index a730118..d3e88c7 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ install_requires.extend(extras_require.get("python-doctr", [])) setup( name="OpenRecall", - version="0.7", + version="0.8", packages=find_packages(), install_requires=install_requires, long_description=long_description,