[flatpak] "Run in Background" policy
This is Flatpak-specific. The current behavior for bare-metal is fine and shouldn't change.
The bug
When a Boxes user has a "Run in Background" VM and they close Boxes, the libvirtd daemon keeping the VM alive continues running in the Boxes' container, but the application itself does not. This way, once you open a new Boxes instance, you don't have access to that VM.
To fix this we need to keep Boxes (GApplication) alive for as long as VMs are running. We can run it in the background, so we can literally get rid of the window. Opening Boxes again would just wake up the existing instance and everything would just work as expected. That's just a 20 lines patch which I already have.
Flatpak Background Monitor/Portal
"(Development) Usage" here is the application name. "whatever reason" should be a sentence we can compose.
Since xdg-desktop-portal 1.4, there's a background monitor mechanism that will kill applications which are running in the background if they don't have permission to do so. See https://github.com/flatpak/xdg-desktop-portal/pull/319
For this reason, we need to call the Background Portal and ask for authorization to run in the background.
That being said, I think we need to discuss some policies here:
- The permissions for each application entry can be "yes", "no" or "ask". If they desire to revoke that, they need to go to Settings.
How do we notify the user that Boxes is running in the background? I thought of using a permanent notification. Clicking it would bring the window back, so users can shutdown VMs and exit gracefully. Thoughts? If we choose this approach, how does the user Force Boxes to Quit? (we don't have that in bare-metal either).
- In the bare-metal/classic version of Boxes, we suspend VMs when the window is closed. This is a bit slow and, therefore, closing Boxes and opening it before the VMs suspends gets the user into a race-condition. The new Boxes instance won't simply work.
Should we keep running VMs alive (running) when the user has authorized Boxes to run in background? (notice that these aren't necessarily marked as "Run in Background" in their Properties)
If we choose to suspend, how do we prevent users from launching failing new instances of Boxes before the operation has completed?
I think we could keep the application alive until the operation finishes (user sees a spinner/notification/ideas?).