Ui, main: closing the window hides it; Activate shows it again

The resident model: a close tears the window down — a fling stops, the
device finishes its frame, the listeners let go, the frame driver and
the canvas go — and keeps the process, the store, the screens and the
bus subscription. Show builds the window again, with a conversation left
open coming back (its caret blinking again; an Open or a Show that lands
between a close and its deferred teardown keeps the window); the Wayland
display source is kept across a hide. A text that arrives for the kept
conversation while the window is hidden — from the close on, not from
its deferred teardown — stays unread and keeps its notification, like
any other conversation's; showing the window again marks it read and
closes the notification. Without a session bus, where nothing could show
the window again, a close ends the process as before. A second launch
reaches the running instance over the bus name and a notification's tap
through its ActionInvoked signal, as before.

--hide-after and --hide-every drive the cycle from the bench as closes
(without a session bus such a close ends the process, as any close does
there), and are window flags as --screenshot is.
This commit is contained in:
Jorijn van der Graaf 2026-10-18 01:16:35 +02:00
commit 07c6c3e5bd
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
2 changed files with 121 additions and 28 deletions

View file

@ -48,6 +48,8 @@ struct Options {
std::optional<fs::path> screenshot;
double screenshotAfter = 2.5; // seconds after start
std::optional<double> quitAfter; // seconds
std::optional<double> hideAfter; // seconds: the bench's close
std::optional<double> hideEvery; // seconds: the bench's repeated close
std::optional<std::string> prefill; // typed into the opened conversation's field
bool sendDraft = false; // and sent, as if the button were tapped
std::string country;
@ -59,7 +61,7 @@ struct Options {
// a running instance, whose window is not this one. What configures a
// process (its store, its country code) is not among them: beside a
// running instance that instance's own stands.
bool WindowFlags(const Options& o) { return o.screenshot || o.prefill || o.sendDraft; }
bool WindowFlags(const Options& o) { return o.screenshot || o.prefill || o.sendDraft || o.hideAfter || o.hideEvery; }
// A bench clock's seconds, which its timer takes as a guint of
// milliseconds: what is not such a number is the error.
@ -88,6 +90,8 @@ Options Parse(std::span<const char* const> args) {
else if (a == "--screenshot" && i + 1 < args.size()) o.screenshot = fs::path(args[++i]);
else if (a == "--screenshot-after" && i + 1 < args.size()) o.screenshotAfter = Seconds(a, args[++i], o.error);
else if (a == "--quit-after" && i + 1 < args.size()) o.quitAfter = Seconds(a, args[++i], o.error);
else if (a == "--hide-after" && i + 1 < args.size()) o.hideAfter = Seconds(a, args[++i], o.error);
else if (a == "--hide-every" && i + 1 < args.size()) o.hideEvery = Seconds(a, args[++i], o.error);
else if (a == "--prefill" && i + 1 < args.size()) o.prefill = args[++i];
else if (a == "--send-draft") o.sendDraft = true;
else if (a == "--country" && i + 1 < args.size()) o.country = args[++i];
@ -106,6 +110,7 @@ Options Parse(std::span<const char* const> args) {
// and CountryCodeOf gives it back from a number that begins with it): a
// completed key is made of it as it is, and read by that rule.
if (!o.country.empty() && (o.country.front() == '0' || CountryCodeOf(std::format("+{}0000000", o.country)) != o.country)) o.error = "--country: not a country code (one to three digits, without its +)";
if (o.hideEvery && *o.hideEvery * 1000 < 1) o.error = "--hide-every: a millisecond at least";
if (o.send && o.quit) o.error = "--send and --quit do not go together";
if (o.send && o.uri) o.error = "--send and an sms: link do not go together";
if (o.send && WindowFlags(o)) o.error = "--send and a window do not go together";
@ -271,7 +276,7 @@ int main(int argc, char** argv) {
return 0;
}
if (o.help) {
std::println("imsd-messages [--daemon|--headless] [--send NUMBER TEXT] [--quit] [--session] [--data-dir DIR] [--country CC] [--screenshot FILE.png] [--screenshot-after SECONDS] [--quit-after SECONDS] [--prefill TEXT] [--send-draft] [sms:NUMBER] [--version]");
std::println("imsd-messages [--daemon|--headless] [--send NUMBER TEXT] [--quit] [--session] [--data-dir DIR] [--country CC] [--screenshot FILE.png] [--screenshot-after SECONDS] [--quit-after SECONDS] [--hide-after SECONDS] [--hide-every SECONDS] [--prefill TEXT] [--send-draft] [sms:NUMBER] [--version]");
return 0;
}
@ -364,6 +369,7 @@ int main(int argc, char** argv) {
shell.sync = &sync;
app.emplace(*store, AssetDir(), CacheDir());
if (o.screenshot) app->exitCode = 1; // an asked-for screenshot is a failure until the PNG is written: a run that ends first says so
app->closeQuits = session == nullptr;
app->sync = &sync;
app->onQuit = [loop] { g_main_loop_quit(loop); };
app->onConversationOpened = [&notifier](const std::string& conversation) { notifier.Close(conversation); };
@ -427,6 +433,14 @@ int main(int argc, char** argv) {
g_unix_signal_add(SIGINT, OnQuitSignal, &shell);
g_unix_signal_add(SIGTERM, OnQuitSignal, &shell);
if (o.send) g_timeout_add_seconds(60, OnSendTimeout, &shell);
if (o.hideAfter) g_timeout_add(static_cast<guint>(*o.hideAfter * 1000), [](gpointer data) -> gboolean {
static_cast<Ui::App*>(data)->Close();
return G_SOURCE_REMOVE;
}, &*app);
if (o.hideEvery) g_timeout_add(static_cast<guint>(*o.hideEvery * 1000), [](gpointer data) -> gboolean {
static_cast<Ui::App*>(data)->Close();
return G_SOURCE_CONTINUE;
}, &*app);
// A bench's clock: the smoke tests on the phone end on their own.
if (o.quitAfter) g_timeout_add(static_cast<guint>(*o.quitAfter * 1000), [](gpointer data) -> gboolean {
static_cast<Shell*>(data)->QuitAfter();