From 013c29a57b8208186b99dc880250fd2029915349 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 25 May 2025 15:18:50 +0200 Subject: ... --- overlays/worktime/pyproject.toml | 2 ++ overlays/worktime/uv.lock | 23 +++++++++++++++++++++++ overlays/worktime/worktime/__main__.py | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+) (limited to 'overlays/worktime') diff --git a/overlays/worktime/pyproject.toml b/overlays/worktime/pyproject.toml index 4b3605bd..42da51f5 100644 --- a/overlays/worktime/pyproject.toml +++ b/overlays/worktime/pyproject.toml @@ -12,11 +12,13 @@ dependencies = [ "jsonpickle>=4.0.5,<5", "frozendict>=2.4.6", "atomicwriter>=0.2.5", + "desktop-notify>=1.3.3", ] [project.scripts] worktime = "worktime.__main__:main" worktime-ui = "worktime.__main__:ui" +worktime-stop = "worktime.__main__:stop" [build-system] requires = ["hatchling"] diff --git a/overlays/worktime/uv.lock b/overlays/worktime/uv.lock index d8a14937..39de4ccf 100644 --- a/overlays/worktime/uv.lock +++ b/overlays/worktime/uv.lock @@ -82,6 +82,27 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/0e/f6/65ecc6878a89bb1c23a086ea335ad4bf21a588990c3f535a227b9eea9108/charset_normalizer-3.4.1-py3-none-any.whl", hash = "sha256:d98b1668f06378c6dbefec3b92299716b931cd4e6061f3c875a71ced1780ab85", size = 49767, upload-time = "2024-12-24T18:12:32.852Z" }, ] +[[package]] +name = "dbus-next" +version = "0.2.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ce/45/6a40fbe886d60a8c26f480e7d12535502b5ba123814b3b9a0b002ebca198/dbus_next-0.2.3.tar.gz", hash = "sha256:f4eae26909332ada528c0a3549dda8d4f088f9b365153952a408e28023a626a5", size = 71112, upload-time = "2021-07-25T22:11:28.398Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d2/fc/c0a3f4c4eaa5a22fbef91713474666e13d0ea2a69c84532579490a9f2cc8/dbus_next-0.2.3-py3-none-any.whl", hash = "sha256:58948f9aff9db08316734c0be2a120f6dc502124d9642f55e90ac82ffb16a18b", size = 57885, upload-time = "2021-07-25T22:11:25.466Z" }, +] + +[[package]] +name = "desktop-notify" +version = "1.3.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "dbus-next" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/7a/d8/7ae5779257f5f1aa0a2d50c02d70b29522bd414692f3d3bd18ef119fe82d/desktop-notify-1.3.3.tar.gz", hash = "sha256:62934ad1f72f292f9a3af5ffe45af32814af18c396c00369385540c72bf08077", size = 7828, upload-time = "2021-01-03T16:46:36.483Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0a/cd/a7e3bd0262f3e8a9272fd24d0193e24dad7cb4e4edd27da48e74b5523e59/desktop_notify-1.3.3-py3-none-any.whl", hash = "sha256:8ad7ecc3a9a603dd5fa3cdc11cc6265cfbc7f6df9d8ed240f4663f43ef0de37a", size = 9937, upload-time = "2021-01-03T16:46:35.157Z" }, +] + [[package]] name = "frozendict" version = "2.4.6" @@ -198,6 +219,7 @@ version = "1.0.0" source = { editable = "." } dependencies = [ { name = "atomicwriter" }, + { name = "desktop-notify" }, { name = "frozendict" }, { name = "jsonpickle" }, { name = "python-dateutil" }, @@ -211,6 +233,7 @@ dependencies = [ [package.metadata] requires-dist = [ { name = "atomicwriter", specifier = ">=0.2.5" }, + { name = "desktop-notify", specifier = ">=1.3.3" }, { name = "frozendict", specifier = ">=2.4.6" }, { name = "jsonpickle", specifier = ">=4.0.5,<5" }, { name = "python-dateutil", specifier = ">=2.9.0.post0,<3" }, diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 79e1cbb7..fbd8fb0a 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -49,6 +49,7 @@ from contextlib import closing import os from time import clock_gettime_ns, CLOCK_MONOTONIC from atomicwriter import AtomicWriter +import desktop_notify.aio as notify class BearerAuth(requests.auth.AuthBase): def __init__(self, token): @@ -1018,6 +1019,7 @@ async def ui_main(): return elif running_entry and fuzzel_out == 0: api.stop_clock(running_entry['id']) + await notify.Server('worktime').Notify("Stopped running timesheet").set_timeout(65000).show() else: if running_entry: fuzzel_out -= 1 @@ -1029,10 +1031,27 @@ async def ui_main(): tags = option['tags'], billable = option['billable'], ) + await notify.Server('worktime').Notify("Timesheet started…").set_timeout(65000).show() def ui(): asyncio.run(ui_main()) +async def stop_main(): + config = Worktime.config() + api = KimaiAPI( + base_url=config.get("KIMAI", {}).get("BaseUrl", None), + api_token=config.get("KIMAI", {}).get("ApiToken", None), + clients=config.get("KIMAI", {}).get("Clients", None) + ) + if running_entry := api.get_running_entry(): + api.stop_clock(running_entry['id']) + await notify.Server('worktime').Notify("Stopped running timesheet").set_timeout(65000).show() + else: + await notify.Server('worktime').Notify("No timesheet currently running").set_timeout(65000).show() + +def stop(): + asyncio.run(stop_main()) + if __name__ == "__main__": sys.exit(main()) -- cgit v1.2.3