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

Add initial flatpak-spawn support #570

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,14 +1505,37 @@ def spawn_child(self, widget=None, respawn=False, debugserver=False, init_comman

dbg('Forking shell: "%s" with args: %s' % (shell, args))
args.insert(0, shell)
result, self.pid = self.vte.spawn_sync(Vte.PtyFlags.DEFAULT,
self.cwd,
args,
envv,
GLib.SpawnFlags.FILE_AND_ARGV_ZERO,
None,
None,
None)

if util.is_flatpak():
dbg('Flatpak detected')
args = util.get_flatpak_args(args, envv, self.cwd)
dbg('Forking shell: "%s" with args: %s via flatpak-spawn' % (shell, args))

self.pid = self.vte.spawn_async(
Vte.PtyFlags.NO_CTTY,
self.cwd,
args,
envv,
0,
None,
None,
-1,
None,
None,
None,
)
else:
result, self.pid = self.vte.spawn_sync(
Vte.PtyFlags.DEFAULT,
self.cwd,
args,
envv,
GLib.SpawnFlags.FILE_AND_ARGV_ZERO,
None,
None,
None
)

self.command = shell

self.titlebar.update()
Expand Down
24 changes: 24 additions & 0 deletions terminatorlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
# list of methods to show debugging for. empty list means show all methods
DEBUGMETHODS = []

def is_flatpak():
return os.path.exists("/.flatpak-info")

def dbg(log = ""):
"""Print a message if debugging is enabled"""
if DEBUG:
Expand Down Expand Up @@ -144,6 +147,13 @@ def path_lookup(command):

def shell_lookup():
"""Find an appropriate shell for the user"""
if is_flatpak():
getent = subprocess.check_output([
'flatpak-spawn', '--host', 'getent', 'passwd',
pwd.getpwuid(os.getuid())[0]
]).decode(encoding='UTF-8').rstrip('\n')
shell = getent.split(':')[6]
return shell
try:
usershell = pwd.getpwuid(os.getuid())[6]
except KeyError:
Expand Down Expand Up @@ -394,3 +404,17 @@ def update_config_to_cell_height(filename):
except Exception as ex:
err('Unable to open ‘%s’ for reading and/or writting.\n(%s)'
% (filename, ex))

def get_flatpak_args(args, envv, cwd):
"""Contruct args to be executed via flatpak-spawn"""
flatpak_args = None
env_args = ['--env={}'.format(env) for env in envv]
flatpak_spawn = [
"flatpak-spawn", "--host", "--watch-bus", "--forward-fd=1",
"--forward-fd=2", "--directory={}".format(cwd)
]
flatpak_args = flatpak_spawn + env_args + args
JayDoubleu marked this conversation as resolved.
Show resolved Hide resolved

dbg('returned flatpak args: %s' % flatpak_args)

return flatpak_args