| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
# |
| 3 |
# This file is formatted with Python Black |
| 4 |
# mypy: disable-error-code="misc" |
| 5 |
|
| 6 |
from tests.templates.xdp_utils import init_logger |
| 7 |
|
| 8 |
import dbus.service |
| 9 |
import dbus |
| 10 |
from gi.repository import GLib |
| 11 |
from dataclasses import dataclass |
| 12 |
|
| 13 |
|
| 14 |
BUS_NAME = "org.freedesktop.impl.portal.Test" |
| 15 |
MAIN_OBJ = "/org/freedesktop/portal/desktop" |
| 16 |
SYSTEM_BUS = False |
| 17 |
MAIN_IFACE = "org.freedesktop.impl.portal.Background" |
| 18 |
VERSION = 1 |
| 19 |
|
| 20 |
|
| 21 |
logger = init_logger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
@dataclass |
| 25 |
class BackgroundParameters: |
| 26 |
delay: int |
| 27 |
|
| 28 |
|
| 29 |
def load(mock, parameters={}): |
| 30 |
logger.debug(f"Loading parameters: {parameters}") |
| 31 |
|
| 32 |
assert not hasattr(mock, "background_params") |
| 33 |
mock.background_params = BackgroundParameters( |
| 34 |
delay=parameters.get("delay", 200), |
| 35 |
) |
| 36 |
|
| 37 |
|
| 38 |
@dbus.service.method( |
| 39 |
MAIN_IFACE, |
| 40 |
in_signature="", |
| 41 |
out_signature="a{sv}", |
| 42 |
async_callbacks=("cb_success", "cb_error"), |
| 43 |
) |
| 44 |
def GetAppState(self, cb_success, cb_error): |
| 45 |
logger.debug("GetAppState()") |
| 46 |
params = self.background_params |
| 47 |
|
| 48 |
# FIXME: implement? |
| 49 |
def reply(): |
| 50 |
cb_success({}) |
| 51 |
|
| 52 |
logger.debug(f"scheduling delay of {params.delay}") |
| 53 |
GLib.timeout_add(params.delay, reply) |
| 54 |
|
| 55 |
|
| 56 |
@dbus.service.method( |
| 57 |
MAIN_IFACE, |
| 58 |
in_signature="oss", |
| 59 |
out_signature="ua{sv}", |
| 60 |
async_callbacks=("cb_success", "cb_error"), |
| 61 |
) |
| 62 |
def NotifyBackground(self, handle, app_id, name, cb_success, cb_error): |
| 63 |
logger.debug(f"NotifyBackground({handle}, {app_id}, {name})") |
| 64 |
params = self.background_params |
| 65 |
|
| 66 |
logger.debug(f"scheduling delay of {params.delay}") |
| 67 |
GLib.timeout_add(params.delay, cb_success) |
| 68 |
|
| 69 |
|
| 70 |
@dbus.service.method( |
| 71 |
MAIN_IFACE, |
| 72 |
in_signature="sbasu", |
| 73 |
out_signature="b", |
| 74 |
) |
| 75 |
def EnableAutostart(self, app_id, enable, commandline, flags): |
| 76 |
raise dbus.exceptions.DBusException("EnableAutostart is deprecated") |