Bus, main: start at login through the Background portal

A text that arrives while the app is not running waits in imsd until the
app is opened, and nothing notifies. Inside its flatpak the instance now
asks the desktop portal's Background interface when it starts (not for
the --send errand or --headless) to run on with the window closed and to
start `imsd-messages --daemon` at login, the mode that imports and
notifies with no window. The portal keeps the answer and writes the
login entry again at each request it grants, so a deleted entry comes
back while the background permission allows it; set to no, the
permission makes the portal refuse the request, and an entry already
written stays. Outside its own flatpak nothing is asked.

tests/Portal covers the request path the answer arrives on and the
options the request carries.
This commit is contained in:
Jorijn van der Graaf 2026-10-20 23:23:30 +02:00
commit f07a3716b3
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
6 changed files with 221 additions and 9 deletions

View file

@ -430,6 +430,14 @@ int main(int argc, char** argv) {
notifier.onOpen = [&app](const std::string& conversation) { app->Open(conversation); };
Log(std::format("{} {}; database {}; imsd on the {} bus; notifications {}; assets {}", version, o.send ? "sending one text" : o.daemon ? "resident" : "starting", dataDir.string(), o.session ? "session" : "system", notifier.Enabled() ? "on" : "off", AssetDir().string()));
client.Start(sync);
// Inside its flatpak the app asks to run on with the window closed and
// to be started hidden at login; the errand and the smoke test do not.
std::optional<Bus::BackgroundRequest> background;
if (session && !o.send && !o.headless && Bus::InOwnFlatpak()) {
background.emplace(session, "To receive texts and show them while the window is closed", std::vector<std::string>{ "imsd-messages", "--daemon" });
background->onLog = Log;
background->Start();
}
if (o.uri) {
// The link's conversation opens at once, keyed with the country code
// known now — at a start --country's, else the number's own — and