Skip to content

Commit

Permalink
If User inactive for 10 minutes, the app closes (IMGIITRoorkee#121)
Browse files Browse the repository at this point in the history
* If User inactive for 10 minutes, the app closes

* Added same feature for Unix bases system also

* Added same feature for Unix bases system also

* moved msvcrt statement for windows and updated timeout limit

---------

Co-authored-by: Angel Sharma <[email protected]>
  • Loading branch information
Sanat-Jha and fillingtothemomo authored Jan 3, 2025
1 parent f9ab147 commit bb75c6a
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
from manager import PasswordManager
import pyperclip
import sys
import select
import time


def get_input_with_timeout(prompt, timeout=60):
print(prompt, end='', flush=True)
# For Windows
if sys.platform == 'win32':
import msvcrt
start_time = time.time()
input_str = ''
while True:
if msvcrt.kbhit():
char = msvcrt.getwche()
if char == '\r':
print()
return input_str.strip()
input_str += char
if time.time() - start_time > timeout:
print("\nUser inactive for too long. Closing the application.")
return None
time.sleep(0.1)
# For Unix-like systems
else:
rlist, _, _ = select.select([sys.stdin], [], [], timeout)
if rlist:
return sys.stdin.readline().strip()
print("\nUser inactive for too long. Closing the application.")
return None



Expand Down Expand Up @@ -32,7 +62,12 @@ def main():

done = False
while not done:
choice = input("Enter choice: ").strip().lower()
choice = get_input_with_timeout("Enter choice: ")
if choice is None: # Timeout occurred
done = True
continue

choice = choice.strip().lower()
if choice == '1':
path = input("Enter key file path: ").strip()
pm.create_key(path)
Expand Down

0 comments on commit bb75c6a

Please sign in to comment.