Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linux): Start dbus if not running #10863

Merged
merged 11 commits into from
Mar 26, 2024
25 changes: 25 additions & 0 deletions linux/keyman-config/keyman_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gettext
import logging
import os
import subprocess

from keyman_config.sentry_handling import SentryErrorHandling
from keyman_config.version import (
Expand Down Expand Up @@ -77,3 +79,26 @@ def add_standard_arguments(parser):

# There's no staging site for downloads
KeymanDownloadsUrl = 'https://downloads.keyman.com'


if (not 'DBUS_SESSION_BUS_ADDRESS' in os.environ or
not 'DBUS_SESSION_BUS_PID' in os.environ):
try:
# Seems dbus isn't running for the current user. Try to start it
# and set these environment variables
logging.info('Starting dbus with dbus-launch')
stdout = subprocess.run(
('dbus-launch', '--exit-with-session'),
stdout=subprocess.PIPE, check=False).stdout
lines = stdout.decode('utf-8').splitlines()
for line in lines:
equal_sign = line.find('=')
if equal_sign <= 0:
logging.warning('Got unexpected line from dbus-launch: %s', line)
continue
name = line[:equal_sign]
value = line[equal_sign+1:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this empty if = is at the end of the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

logging.debug('Setting environment %s=%s', name, value)
os.environ[name] = value
except Exception as e:
logging.error('Starting dbus-launch failed with %s', e)