Files
tdesktop/Telegram/ThirdParty/xdg-desktop-portal/tests/templates/notification.py
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
init
2026-02-16 15:50:16 +03:00

83 lines
1.9 KiB
Python

# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is formatted with Python Black
# mypy: disable-error-code="misc"
from tests.templates import init_logger
import dbus.service
from dbusmock import MOCK_IFACE
BUS_NAME = "org.freedesktop.impl.portal.Test"
MAIN_OBJ = "/org/freedesktop/portal/desktop"
SYSTEM_BUS = False
MAIN_IFACE = "org.freedesktop.impl.portal.Notification"
VERSION = 2
logger = init_logger(__name__)
def load(mock, parameters={}):
logger.debug(f"Loading parameters: {parameters}")
mock.AddProperties(
MAIN_IFACE,
dbus.Dictionary(
{
"version": dbus.UInt32(parameters.get("version", VERSION)),
"SupportedOptions": dbus.Dictionary(
parameters.get("SupportedOptions", {}), signature="sv"
),
},
),
)
mock.notifications = {}
@dbus.service.method(
MAIN_IFACE,
in_signature="ssa{sv}",
out_signature="",
)
def AddNotification(self, app_id, id, notification):
logger.debug(f"AddNotification({app_id}, {id}, {notification})")
self.notifications.setdefault(app_id, {})[id] = notification
@dbus.service.method(
MAIN_IFACE,
in_signature="ss",
out_signature="",
)
def RemoveNotification(self, app_id, id):
logger.debug(f"AddNotification({app_id}, {id})")
del self.notifications[app_id][id]
@dbus.service.method(
MOCK_IFACE,
in_signature="sssav",
out_signature="",
)
def EmitActionInvoked(self, app_id, id, action, parameter):
logger.debug(f"EmitActionInvoked({app_id}, {id}, {action}, {parameter})")
# n = self.notifications[app_id][id]
# FIXME check action is in n
self.EmitSignal(
MAIN_IFACE,
"ActionInvoked",
"sssav",
[
app_id,
id,
action,
dbus.Array(parameter, signature="v"),
],
)