44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
"""Progress on the dock icon, via `com.canonical.Unity.LauncherEntry`.
|
|
|
|
A signal, not a service: anything listening (Plasma's task manager, Dash to
|
|
Dock, Latte) picks it up, and nothing breaks where nobody listens. The result is
|
|
a progress bar filling under the icon as the interval runs and a badge with the
|
|
pomodoro count for the day — the timer stays readable with the window closed.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from PyQt6.QtCore import QVariant
|
|
from PyQt6.QtDBus import QDBusConnection, QDBusMessage
|
|
|
|
_PATH = "/org/kadence/Desktop"
|
|
_IFACE = "com.canonical.Unity.LauncherEntry"
|
|
_APP_URI = "application://kadence.desktop"
|
|
|
|
|
|
class LauncherEntry:
|
|
def __init__(self) -> None:
|
|
self._bus = QDBusConnection.sessionBus()
|
|
|
|
def update(self, *, progress: float | None = None, count: int | None = None, urgent: bool = False) -> None:
|
|
"""Push a new state. `progress` is 0..1; `count` is the badge number."""
|
|
properties: dict[str, QVariant] = {}
|
|
if progress is None:
|
|
properties["progress-visible"] = QVariant(False)
|
|
else:
|
|
properties["progress"] = QVariant(max(0.0, min(1.0, progress)))
|
|
properties["progress-visible"] = QVariant(True)
|
|
if count is None:
|
|
properties["count-visible"] = QVariant(False)
|
|
else:
|
|
properties["count"] = QVariant(int(count))
|
|
properties["count-visible"] = QVariant(True)
|
|
properties["urgent"] = QVariant(bool(urgent))
|
|
|
|
message = QDBusMessage.createSignal(_PATH, _IFACE, "Update")
|
|
message.setArguments([_APP_URI, properties])
|
|
self._bus.send(message)
|
|
|
|
def clear(self) -> None:
|
|
self.update(progress=None, count=None, urgent=False)
|