mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2024-10-01 03:35:38 -04:00
pantalaimon: Make the dbus UI optional.
This commit is contained in:
parent
dfa5501a6c
commit
ad65fbf1a7
@ -28,7 +28,7 @@ from pantalaimon.config import PanConfig, PanConfigError, parse_log_level
|
||||
from pantalaimon.daemon import ProxyDaemon
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.thread_messages import DaemonResponse
|
||||
from pantalaimon.ui import GlibT
|
||||
from pantalaimon.ui import UI_ENABLED
|
||||
|
||||
|
||||
def create_dirs(data_dir, conf_dir):
|
||||
@ -50,8 +50,8 @@ async def init(data_dir, server_conf, send_queue, recv_queue):
|
||||
server_conf.homeserver,
|
||||
server_conf,
|
||||
data_dir,
|
||||
send_queue=send_queue,
|
||||
recv_queue=recv_queue,
|
||||
send_queue=send_queue.async_q if send_queue else None,
|
||||
recv_queue=recv_queue.async_q if recv_queue else None,
|
||||
proxy=server_conf.proxy.geturl() if server_conf.proxy else None,
|
||||
ssl=None if server_conf.ssl is True else False,
|
||||
)
|
||||
@ -154,17 +154,36 @@ def main(context, log_level, config):
|
||||
logger.level = pan_conf.log_level
|
||||
StderrHandler().push_application()
|
||||
|
||||
servers = []
|
||||
proxies = []
|
||||
|
||||
if UI_ENABLED:
|
||||
from pantalaimon.ui import GlibT
|
||||
|
||||
pan_queue = janus.Queue(loop=loop)
|
||||
ui_queue = janus.Queue(loop=loop)
|
||||
|
||||
servers = []
|
||||
proxies = []
|
||||
glib_thread = GlibT(
|
||||
pan_queue.sync_q, ui_queue.sync_q, data_dir, pan_conf.servers.values(), pan_conf
|
||||
)
|
||||
|
||||
glib_fut = loop.run_in_executor(None, glib_thread.run)
|
||||
message_router_task = loop.create_task(
|
||||
message_router(ui_queue.async_q, pan_queue.async_q, proxies)
|
||||
)
|
||||
|
||||
else:
|
||||
glib_thread = None
|
||||
glib_fut = None
|
||||
pan_queue = None
|
||||
ui_queue = None
|
||||
message_router_task = None
|
||||
|
||||
try:
|
||||
|
||||
for server_conf in pan_conf.servers.values():
|
||||
proxy, runner, site = loop.run_until_complete(
|
||||
init(data_dir, server_conf, pan_queue.async_q, ui_queue.async_q)
|
||||
init(data_dir, server_conf, pan_queue, ui_queue)
|
||||
)
|
||||
servers.append((proxy, runner, site))
|
||||
proxies.append(proxy)
|
||||
@ -172,20 +191,10 @@ def main(context, log_level, config):
|
||||
except keyring.errors.KeyringError as e:
|
||||
context.fail(f"Error initializing keyring: {e}")
|
||||
|
||||
glib_thread = GlibT(
|
||||
pan_queue.sync_q, ui_queue.sync_q, data_dir, pan_conf.servers.values(), pan_conf
|
||||
)
|
||||
|
||||
glib_fut = loop.run_in_executor(None, glib_thread.run)
|
||||
|
||||
async def wait_for_glib(glib_thread, fut):
|
||||
glib_thread.stop()
|
||||
await fut
|
||||
|
||||
message_router_task = loop.create_task(
|
||||
message_router(ui_queue.async_q, pan_queue.async_q, proxies)
|
||||
)
|
||||
|
||||
home = os.path.expanduser("~")
|
||||
os.chdir(home)
|
||||
|
||||
@ -208,9 +217,13 @@ def main(context, log_level, config):
|
||||
for _, runner, _ in servers:
|
||||
loop.run_until_complete(runner.cleanup())
|
||||
|
||||
if glib_fut:
|
||||
loop.run_until_complete(wait_for_glib(glib_thread, glib_fut))
|
||||
|
||||
if message_router_task:
|
||||
message_router_task.cancel()
|
||||
loop.run_until_complete(asyncio.wait({message_router_task}))
|
||||
|
||||
loop.close()
|
||||
|
||||
|
||||
|
@ -12,19 +12,22 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from collections import defaultdict
|
||||
from queue import Empty
|
||||
from importlib import util
|
||||
|
||||
import attr
|
||||
import dbus
|
||||
import notify2
|
||||
from gi.repository import GLib
|
||||
from pydbus import SessionBus
|
||||
from pydbus.generic import signal
|
||||
if util.find_spec("pybdubs") and util.find_spec("gi.repository") and False:
|
||||
from collections import defaultdict
|
||||
from queue import Empty
|
||||
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import PanStore
|
||||
from pantalaimon.thread_messages import (
|
||||
import attr
|
||||
import dbus
|
||||
import notify2
|
||||
from gi.repository import GLib
|
||||
from pydbus import SessionBus
|
||||
from pydbus.generic import signal
|
||||
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import PanStore
|
||||
from pantalaimon.thread_messages import (
|
||||
AcceptSasMessage,
|
||||
CancelSasMessage,
|
||||
CancelSendingMessage,
|
||||
@ -44,10 +47,12 @@ from pantalaimon.thread_messages import (
|
||||
UnverifiedDevicesSignal,
|
||||
UpdateDevicesMessage,
|
||||
UpdateUsersMessage,
|
||||
)
|
||||
)
|
||||
|
||||
UI_ENABLED = True
|
||||
|
||||
|
||||
class IdCounter:
|
||||
class IdCounter:
|
||||
def __init__(self):
|
||||
self._message_id = 0
|
||||
|
||||
@ -59,7 +64,7 @@ class IdCounter:
|
||||
return ret
|
||||
|
||||
|
||||
class Control:
|
||||
class Control:
|
||||
"""
|
||||
<node>
|
||||
<interface name='org.pantalaimon1.control'>
|
||||
@ -151,7 +156,7 @@ class Control:
|
||||
return message.message_id
|
||||
|
||||
|
||||
class Devices:
|
||||
class Devices:
|
||||
"""
|
||||
<node>
|
||||
<interface name='org.pantalaimon1.devices'>
|
||||
@ -359,8 +364,8 @@ class Devices:
|
||||
device_list[device["user_id"]][device["device_id"]] = device
|
||||
|
||||
|
||||
@attr.s
|
||||
class GlibT:
|
||||
@attr.s
|
||||
class GlibT:
|
||||
receive_queue = attr.ib()
|
||||
send_queue = attr.ib()
|
||||
data_dir = attr.ib()
|
||||
@ -574,3 +579,6 @@ class GlibT:
|
||||
if self.loop:
|
||||
self.loop.quit()
|
||||
self.loop = None
|
||||
|
||||
else:
|
||||
UI_ENABLED = False
|
||||
|
10
setup.py
10
setup.py
@ -25,18 +25,20 @@ setup(
|
||||
"keyring",
|
||||
"logbook",
|
||||
"peewee",
|
||||
"dbus-python",
|
||||
"PyGObject",
|
||||
"pydbus",
|
||||
"janus",
|
||||
"prompt_toolkit",
|
||||
"notify2",
|
||||
"typing;python_version<'3.5'",
|
||||
"matrix-nio[e2e] >= 0.4"
|
||||
],
|
||||
extras_require={
|
||||
"e2e_search": [
|
||||
"tantivy",
|
||||
],
|
||||
"ui": [
|
||||
"dbus-python",
|
||||
"PyGObject",
|
||||
"pydbus",
|
||||
"notify2",
|
||||
]
|
||||
},
|
||||
entry_points={
|
||||
|
Loading…
Reference in New Issue
Block a user