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

Terminator flatpak-spawn integration (HostCommand) #347

Open
JayDoubleu opened this issue Dec 31, 2020 · 7 comments
Open

Terminator flatpak-spawn integration (HostCommand) #347

JayDoubleu opened this issue Dec 31, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@JayDoubleu
Copy link
Contributor

JayDoubleu commented Dec 31, 2020

Flatpak is using the "flatpak-spawn" command to escape from the sandbox and run commands on the host.

Tilix has implemented the below so it automatically spawns shell on the host instead of the container
https://github.com/gnunn1/tilix/blob/787e5335ecef9cada035170eeaedb301f567127d/source/gx/tilix/terminal/terminal.d#L2825..L2833
https://gitlab.gnome.org/GNOME/gnome-builder/-/blob/master/src/libide/threading/ide-flatpak-subprocess.c#L549

Would it be possible to look at the implementation in terminator ?
Here is an example of python running flatpak's "HostCommand"

https://stackoverflow.com/questions/39494813/pass-file-descriptor-via-a-dbus-function-call-from-python-aka-call-flatpaks-ho

Currently I can launch terminator from flatpak but I have to run flatpak-spawn --host zsh from within terminator and this is not persistent across tabs.

Alternatively, if there would be a way to pass default run command to terminator as an argument for example:
--default-shell="flatpak-spawn --host $SHELL" which would apply to all tabs overwriting the config.

@mattrose
Copy link
Member

Where did you get a flatpak build of Terminator from? It's been on my todo list for a while but I've never used flatpak, and I haven't had time to do the research to build up a flatpak build yet. Did Redhat build one up? If we can get access to the flatpak build we can suggest a patch for flatpak that will do the right thing for the flatpak package.

The best thing I can think I can think of is to add a profile, or change the default profile to have flatpak-spawn --host $SHELL to be the default command that runs on terminal launch.

JayDoubleu pushed a commit to flatpak-rpm-builds/terminator that referenced this issue Dec 31, 2020
Seems to be working ok, terminator will need some modifications to spawn shell on a host by default(gnome-terminator/terminator#347)
@JayDoubleu
Copy link
Contributor Author

No, redhat didn't yet build one.
I've had a go at it and it looks promising so far. Have a look here: https://github.com/flatpak-rpm-builds/com.tenshu.terminator

I know that the toolbox tool on fedora also uses flatpak-spawn so it could be potentially used for development without having to build/rebuild the flatpak.

@JayDoubleu
Copy link
Contributor Author

JayDoubleu commented Jan 4, 2021

@mattrose this is now on https://src.fedoraproject.org/flatpaks/terminator/tree/master
Fedora builds flatpaks as OCI containers from RPM so essentially this is mostly ready for implementation and it will pull your latest RPM if it becomes available in fedora repos (with flatpak-spawn fixes).
From there there is a short route to get it into fedora flatpak registry if folks at fedora decide to include it there.

Ps. I've changed the app id to match your dbus name net.tenshu.Terminator2

I'm happy to be your guinea pig for testing if needed. Give me a shout if you would like some help setting up development environment.

@mattrose
Copy link
Member

mattrose commented Jan 4, 2021

I'll play with this a bit, I think the only thing we need is a way to detect that we're in a flatpak environment, and set the command appropriately. Is there a standard way of detecting that you're running in a flatpak sandbox?

@JayDoubleu
Copy link
Contributor Author

JayDoubleu commented Jan 5, 2021

Apparently the common approach is to check if /.flatpak-info exists.
I'm not sure if simply firing the spawn command will produce stable terminal experience tho.

Looks like Tilix does it with custom bin mentioned here:
https://github.com/gnunn1/tilix/blob/787e5335ecef9cada035170eeaedb301f567127d/source/gx/tilix/terminal/terminal.d#L3061..L3064

https://github.com/gnunn1/tilix/blob/master/experimental/flatpak/tilix-flatpak-toolbox.c

@mattrose
Copy link
Member

mattrose commented Jan 5, 2021

yeah, so I tried it, and if you alter the default profile in the Preferences UI so that it runs flatpak-spawn --host /bin/bash it starts and runs in the host OS just fine. I'm not sure how to plumb this in to the flatpak manifest so it configures terminator to do this by default, but I think that might be the best way to achieve what you're looking for.

@JayDoubleu
Copy link
Contributor Author

The issue is that flatpak-spawn produces unstable shell experience.
Looks like tilix discovered that quite some time ago and developed something slightly better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants