mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-12 00:47:29 +00:00
fix(linux): Fix restarting ibus when running with sudo
When installing in the shared area the user has to run
`km-package-install` with sudo so that he has sufficient permissions.
In that case we have to do extra work to restart ibus for the
logged-in user instead of root.
Fixes #5309. Partial cherry-pick of #5371.
(cherry picked from commit 0a2dd29e53)
This commit is contained in:
parent
59e0cd3992
commit
cf03a2b2e0
1 changed files with 16 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import gi
|
||||
import logging
|
||||
import subprocess
|
||||
|
|
@ -66,15 +67,21 @@ def restart_ibus_subp():
|
|||
|
||||
|
||||
def restart_ibus(bus=None):
|
||||
try:
|
||||
if not bus:
|
||||
bus = get_ibus_bus()
|
||||
logging.info("restarting IBus")
|
||||
bus.exit(True)
|
||||
bus.destroy()
|
||||
except Exception as e:
|
||||
logging.warning("Failed to restart IBus")
|
||||
logging.warning(e)
|
||||
realuser = os.environ.get('SUDO_USER')
|
||||
if realuser:
|
||||
# we have been called with `sudo`. Restart ibus for the real user.
|
||||
logging.info('restarting IBus by subprocess for user %s', realuser)
|
||||
subprocess.run(['sudo', '-u', realuser, 'ibus', 'restart'])
|
||||
else:
|
||||
try:
|
||||
if not bus:
|
||||
bus = get_ibus_bus()
|
||||
logging.info("restarting IBus")
|
||||
bus.exit(True)
|
||||
bus.destroy()
|
||||
except Exception as e:
|
||||
logging.warning("Failed to restart IBus")
|
||||
logging.warning(e)
|
||||
|
||||
|
||||
def bus_has_engine(bus, name):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue