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.database import insert_entry
|
||||||
from openrecall.nlp import get_embedding
|
from openrecall.nlp import get_embedding
|
||||||
from openrecall.ocr import extract_text_from_image
|
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):
|
def mean_structured_similarity_index(img1, img2, L=255):
|
||||||
@ -55,9 +55,16 @@ def take_screenshots(monitor=1):
|
|||||||
|
|
||||||
|
|
||||||
def record_screenshots_thread():
|
def record_screenshots_thread():
|
||||||
|
# TODO: fix the error from huggingface tokenizers
|
||||||
|
import os
|
||||||
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
||||||
|
|
||||||
last_screenshots = take_screenshots()
|
last_screenshots = take_screenshots()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
if not is_user_active():
|
||||||
|
time.sleep(3)
|
||||||
|
continue
|
||||||
|
|
||||||
screenshots = take_screenshots()
|
screenshots = take_screenshots()
|
||||||
|
|
||||||
|
@ -106,3 +106,44 @@ def get_active_window_title():
|
|||||||
return get_active_window_title_linux()
|
return get_active_window_title_linux()
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("This platform is not supported")
|
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")
|
||||||
|
|
2
setup.py
2
setup.py
@ -44,7 +44,7 @@ install_requires.extend(extras_require.get("python-doctr", []))
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="OpenRecall",
|
name="OpenRecall",
|
||||||
version="0.7",
|
version="0.8",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
Loading…
Reference in New Issue
Block a user