Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/forceful_timer/app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def is_app_running(app_id: str) -> bool:
app_ids = [x.split()[0] for x in get_running_apps_raw()]
return app_id in app_ids
elif os_type() == "windows":
raise NotImplementedError
output = subprocess.check_output(["tasklist"]).decode()
return app_id in [line.split()[1] for line in output.split("\n")[3:-1]]
elif os_type() == "darwin":
output = subprocess.check_output(["ps", "-A"]).decode()
return app_id in [line.split()[0] for line in output.split("\n")[1:-1]]
return False


Expand All @@ -24,7 +28,13 @@ def get_running_apps_raw() -> list:
decoded_output = subprocess.check_output(["wmctrl", "-l"])
output = decoded_output.decode().split("\n")[:-1]
elif os_type() == "windows":
raise NotImplementedError
output = subprocess.check_output(["tasklist"]).decode()
output = output.split("\n")[3:-1]
output = [line.split()[0:2] for line in output]
elif os_type() == "darwin":
output = subprocess.check_output(["ps", "-A"]).decode()
output = output.split("\n")[1:-1]
output = [line.split()[0:2] for line in output]
return output


Expand All @@ -48,8 +58,8 @@ def get_running_apps() -> list:
"""
if os_type() == "linux":
apps = [extract_app_data_values(x) for x in get_running_apps_raw()]
elif os_type() == "windows":
raise NotImplementedError
elif os_type() == "windows" or os_type() == "darwin":
apps = [tuple(x) for x in get_running_apps_raw()]
return apps


Expand Down
11 changes: 10 additions & 1 deletion src/forceful_timer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,23 @@ def shutdown():
subprocess.call(["shutdown", "now"])
elif os_type() == "windows":
subprocess.call(["shutdown", "/s", "/t", "0"])
elif os_type() == "darwin":
subprocess.call(["sudo", "shutdown", "-h", "now"])


def cancel_shutdown(apps):
print("Shutdown cancled.\n")

for app in apps:
if app_utils.is_app_running(app[0]):
subprocess.call(["wmctrl", "-i", "-c", app[0]])
if os_type() == "linux":
subprocess.call(["wmctrl", "-i", "-c", app[0]])
elif os_type() == "windows":
subprocess.call(["taskkill", "/F", "/IM", app[1]])
elif os_type() == "darwin":
subprocess.call(
["osascript", "-e", f"tell application {app[1]} to quit"]
)
print("Terminating: {}".format(app))
else:
print("Skipping app, because it's not running anymore: {}".format(app))
Expand Down
2 changes: 2 additions & 0 deletions src/forceful_timer/ui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def clear_terminal():
subprocess.run("clear", shell=True)
elif os_type() == "windows":
subprocess.run("cls", shell=True)
elif os_type() == "darwin":
subprocess.run("clear", shell=True)


def get_title() -> list:
Expand Down
2 changes: 1 addition & 1 deletion src/forceful_timer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def check_os():
if os_type_str not in ["linux", "windows"]:
if os_type_str not in ["linux", "windows", "darwin"]:
raise OSError("Your operating system is not supported!", os_type_str)


Expand Down