2024-03-02 17:34:17 +00:00
|
|
|
#! /usr/local/bin/python3
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
def invoke_shell(proc):
|
|
|
|
try:
|
|
|
|
result = subprocess.run(
|
|
|
|
proc,
|
|
|
|
shell=True,
|
|
|
|
check=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
text=True,
|
|
|
|
)
|
|
|
|
return result.stdout.strip()
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
return e.stderr.strip()
|
|
|
|
|
|
|
|
|
|
|
|
def timer_active() -> bool:
|
|
|
|
status = invoke_shell("timew get dom.active")
|
|
|
|
if status == "1":
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def generate_tooltip():
|
|
|
|
tooltip = invoke_shell("timew summary :week")
|
|
|
|
return tooltip
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
output = {}
|
|
|
|
try:
|
|
|
|
if timer_active():
|
2024-03-09 19:29:41 +00:00
|
|
|
output["text"] = ""
|
2024-03-02 17:34:17 +00:00
|
|
|
output["class"] = "active"
|
|
|
|
else:
|
2024-03-09 19:29:41 +00:00
|
|
|
output["text"] = ""
|
2024-03-02 17:34:17 +00:00
|
|
|
output["class"] = "inactive"
|
|
|
|
except Exception as e:
|
|
|
|
output["text"] = "Error"
|
|
|
|
|
|
|
|
print(json.dumps(output))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
print(timer_active())
|