from __future__ import annotations

import importlib
import os


def desktop_notify(title: str, message: str = "", timeout: int = 6, app_name: str = "NexaOffice") -> bool:
    """Best-effort desktop notification.

    The app intentionally keeps native notification support optional.
    This keeps the EXE build smaller and more transparent for antivirus tools:
    if the optional backend is not installed or is blocked, the main app still
    runs normally and falls back to in-app status/messages.
    """
    if os.environ.get("NEXAOFFICE_DISABLE_NATIVE_NOTIFY") == "1":
        return False
    try:
        module = importlib.import_module("plyer.notification")
        notify = getattr(module, "notify")
        notify(
            title=str(title or "NexaOffice")[:128],
            message=str(message or "")[:240],
            app_name=app_name,
            timeout=max(1, int(timeout or 6)),
        )
        return True
    except Exception:
        return False
