azymohliad / watchmate

PineTime smart watch companion app for Linux phone and desktop
GNU General Public License v3.0
136 stars 4 forks source link

Run in the background #37

Closed PhilDevProg closed 8 months ago

PhilDevProg commented 9 months ago

At the moment I have to keep the app open all the time. It would be great if the app could run in the background.

azymohliad commented 9 months ago

Yep, I completely agree. Thanks for filing an issue. I'll try to look into it soon

TheKrafter commented 8 months ago

This would be great!

TheKrafter commented 8 months ago

How easy would it be to make just the UI close (with the rest of the app still running) on window destroy, and when the app is launched it simply reopens the UI?

I would love to contrib but am unfortunately not very familiar with rust (yet)

azymohliad commented 8 months ago

I don't know yet how easy is that, never done it before. But I've resumed the work on the app today, and planned to implement background service tomorrow. Sorry for being inactive on it for so long.

I've just finished and merged basic automatic reconnection and persistent settings support (#41), which I think are both needed for proper background service implementation. Besides just keeping running in background after closing the window, I also want to implement proper GNOME background app indicator before releasing it

azymohliad commented 8 months ago

I would love to contrib but am unfortunately not very familiar with rust (yet)

The contributions are most welcome! Though I genuinely don't know if this is a good first issue to learn the code base from. I will know more tomorrow, but I'd also try to implement it while I have momentum.

In general if you're interested to dive deeper into the code, I'm happy to answer any questions that I can (I could enable github discussions if this isn't the best place, or matrix/telegram/discord also work for me).

azymohliad commented 8 months ago

A little update. Running in background should be pretty easy with GTK in theory, but Watchmate doesn't use GTK directly, but a functional-style wrapper Relm4 on top. And it turns out, it's not currently supported there. The good news is that it shouldn't be very hard to implement the support, and I'll try to help and lead the effort.

To give a bit more details, I've found two options to close the GUI and keep the app running:

  1. Simply hide the main window e.g. using Gtk.Window.set_hide_on_close
  2. Destroy the GUI on close, but keep the app running anyway using Gio.Application.hold. I assume the main point here is to release some memory while in background.

Additionally, sandboxed apps need to request a permission to run in background from org.freedesktop.portal.Background. All that is easily doable with Relm4.

But to switch back to foreground, it should handle the Gio.Application::activate signal, and restore the GUI there (set the main window visible or reinitialize it depending on the options above). But this signal is used by Relm4 internally for the initial setup, so currently can't be reused for anything else.

azymohliad commented 8 months ago

So the Relm4 patch is accepted and a simple background mode is merged now. GNOME 44 background app indicator works automagically. Now I need to add a main menu to have an explicit quit option.

azymohliad commented 8 months ago

Hey, so v0.5.0 is out, bringing a whole bunch of features necessary for a good background mode experience. It should be up on Flathub in a few hours and hopefully soon in community distro packages. I'll close the issue now. If it doesn't work for you folks, I'd appreciate a bug report :)