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