imsd-messages/project.cpp

211 lines
9.6 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// lint-disable-file no-char-pointer
import std;
import Crafter.Build;
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git" commit "e906f797da2cd0b1776dd1b420f9b04d3cd24baf"
import Crafter.LintRules;
namespace fs = std::filesystem;
using namespace Crafter;
// pkg-config wrapper (std-only: no popen in import std). Returns the flags
// split on whitespace, or empty if pkg-config is unavailable — callers
// provide a fallback for that case.
static std::vector<std::string> PkgConfig(std::string_view args) {
fs::path tmp = fs::temp_directory_path() /
std::format("imsd-messages-pkgconfig-{}.txt", std::hash<std::string_view>{}(args));
std::string cmd = std::format("pkg-config {} > {} 2>/dev/null", args, tmp.string());
std::vector<std::string> flags;
if (std::system(cmd.c_str()) == 0) {
std::ifstream f(tmp);
std::string flag;
while (f >> flag)
flags.push_back(flag);
}
std::error_code ec;
fs::remove(tmp, ec);
return flags;
}
// GDBus (gio-2.0) — bus layer for the two daemons; chosen over sd-bus because
// the platform stack (ModemManager, libqmi for the future direct-AKA port) is
Bus: the GDBus client, imsd's dictionaries, the notifier and the owned name The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
2026-10-17 23:45:29 +02:00
// GLib, so they want a GMainLoop regardless. (imsd's reasoning; the same
// layer here.) Computed once, for each target that takes them.
struct GioFlags {
std::vector<std::string> compile;
std::vector<std::string> link;
};
static GioFlags ComputeGioFlags(const Configuration& cfg) {
GioFlags f;
if (!cfg.sysroot.empty()) {
// cross build (e.g. --target=aarch64-alpine-linux-musl
// --sysroot=<packaging/make-sysroot.sh output>): the host's
// pkg-config would answer for the wrong architecture. glib's
// include layout is stable across distros; the `-I=` form makes
// clang resolve the paths inside the sysroot.
Bus: the GDBus client, imsd's dictionaries, the notifier and the owned name The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
2026-10-17 23:45:29 +02:00
f.compile = { "-I=/usr/include/glib-2.0", "-I=/usr/lib/glib-2.0/include" };
f.link = { "-lgio-2.0", "-lgobject-2.0", "-lglib-2.0" };
return f;
}
Bus: the GDBus client, imsd's dictionaries, the notifier and the owned name The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
2026-10-17 23:45:29 +02:00
// native build: ask pkg-config. Only -I/-D flags pass through:
// pkg-config also emits -pthread, which would config-mismatch the
// shared prebuilt std.pcm (and pthread lives in libc on every
// platform we target).
for (std::string& flag : PkgConfig("--cflags gio-2.0"))
if (flag.starts_with("-I") || flag.starts_with("-D")) f.compile.push_back(std::move(flag));
for (std::string& flag : PkgConfig("--libs gio-2.0"))
if (flag.starts_with("-l") || flag.starts_with("-L")) f.link.push_back(std::move(flag));
if (f.link.empty()) f.link = { "-lgio-2.0", "-lgobject-2.0", "-lglib-2.0" };
return f;
}
static void ApplyGioFlags(Configuration& cfg, const GioFlags& f) {
for (const std::string& flag : f.compile) cfg.compileFlags.push_back(flag);
for (const std::string& flag : f.link) cfg.linkFlags.push_back(flag);
}
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
// --local builds Crafter.DB from the sibling checkout under ~/repos/Crafter
// instead of the forge, for work on both sides at once. The flag is this
// project's: it is removed before the arguments are forwarded, so a
// dependency's project.cpp never sees it.
std::vector<std::string> depArgs(args.begin(), args.end());
const bool local = std::erase(depArgs, "--local") > 0;
Configuration* db = local
? LocalProject({ .projectFile = "../Crafter/Crafter.DB/project.cpp", .args = depArgs })
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.DB.git" }, .args = depArgs });
Ui: the window on Crafter.Graphics, driven from the GLib main loop The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
2026-10-18 00:26:09 +02:00
// The window library. --local takes the branch worktree with the Wayland
// input work until it is merged.
Configuration* graphics = local
? LocalProject({ .projectFile = "../Crafter/Crafter.Graphics-imsd-messages/project.cpp", .args = depArgs })
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Graphics.git" }, .args = depArgs });
// imsd-messages-core — numbers, time, the model, word wrap, gestures,
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// the message field's editing, the store and the sync logic: std +
// Crafter.DB, no GLib, so every test runs with no bus, no phone and no
// GPU.
static auto Core = std::make_unique<Configuration>();
Core->path = "./";
Core->name = "imsd-messages-core";
Core->outputName = "imsd-messages-core";
ApplyStandardArgs(*Core, args);
Core->type = ConfigurationType::LibraryStatic;
Core->dependencies = { db };
{
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
std::array<fs::path, 9> ifaces = {
"interfaces/ImsdMessages",
"interfaces/ImsdMessages-Number",
"interfaces/ImsdMessages-Time",
"interfaces/ImsdMessages-Model",
"interfaces/ImsdMessages-Wrap",
"interfaces/ImsdMessages-Store",
"interfaces/ImsdMessages-Sync",
"interfaces/ImsdMessages-Gesture",
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
"interfaces/ImsdMessages-Edit",
};
std::array<fs::path, 0> impls = {};
Core->GetInterfacesAndImplementations(ifaces, impls);
}
// imsd-messages-bus — the GLib side: imsd's dictionaries, the GDBus client
// of net.catcrafts.IMS1.Messaging, the desktop notifications and the app's
// own session-bus name. No window.
static auto Bus = std::make_unique<Configuration>();
Bus->path = "./";
Bus->name = "imsd-messages-bus";
Bus->outputName = "imsd-messages-bus";
ApplyStandardArgs(*Bus, args);
Bus->type = ConfigurationType::LibraryStatic;
Bus->dependencies = { Core.get() };
{
std::array<fs::path, 5> ifaces = {
"interfaces/ImsdMessages.Bus",
"interfaces/ImsdMessages.Bus-Variant",
"interfaces/ImsdMessages.Bus-Client",
"interfaces/ImsdMessages.Bus-Notifier",
"interfaces/ImsdMessages.Bus-Instance",
};
std::array<fs::path, 0> impls = {};
Bus->GetInterfacesAndImplementations(ifaces, impls);
}
Bus: the GDBus client, imsd's dictionaries, the notifier and the owned name The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
2026-10-17 23:45:29 +02:00
const GioFlags gio = ComputeGioFlags(*Bus);
ApplyGioFlags(*Bus, gio);
Ui: the window on Crafter.Graphics, driven from the GLib main loop The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
2026-10-18 00:26:09 +02:00
// imsd-messages-ui — the window: Crafter.Graphics driven from the GLib
// main loop.
static auto Ui = std::make_unique<Configuration>();
Ui->path = "./";
Ui->name = "imsd-messages-ui";
Ui->outputName = "imsd-messages-ui";
ApplyStandardArgs(*Ui, args);
Ui->type = ConfigurationType::LibraryStatic;
Ui->dependencies = { Core.get(), graphics };
{
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
std::array<fs::path, 6> ifaces = {
Ui: the window on Crafter.Graphics, driven from the GLib main loop The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
2026-10-18 00:26:09 +02:00
"interfaces/ImsdMessages.Ui",
"interfaces/ImsdMessages.Ui-Loop",
"interfaces/ImsdMessages.Ui-Canvas",
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
"interfaces/ImsdMessages.Ui-Compose",
Ui: the window on Crafter.Graphics, driven from the GLib main loop The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
2026-10-18 00:26:09 +02:00
"interfaces/ImsdMessages.Ui-Screens",
"interfaces/ImsdMessages.Ui-App",
};
std::array<fs::path, 0> impls = {};
Ui->GetInterfacesAndImplementations(ifaces, impls);
}
ApplyGioFlags(*Ui, gio);
// imsd-messages — the executable: the command line, the window and the
// wiring between the bus layer and the UI.
Configuration cfg;
cfg.path = "./";
cfg.name = "imsd-messages";
cfg.outputName = "imsd-messages";
ApplyStandardArgs(cfg, args);
cfg.type = ConfigurationType::Executable;
Ui: the window on Crafter.Graphics, driven from the GLib main loop The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
2026-10-18 00:26:09 +02:00
cfg.dependencies = { Core.get(), Bus.get(), Ui.get(), db };
{
std::array<fs::path, 0> ifaces = {};
std::array<fs::path, 1> impls = { "implementations/main" };
cfg.GetInterfacesAndImplementations(ifaces, impls);
}
Bus: the GDBus client, imsd's dictionaries, the notifier and the owned name The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
2026-10-17 23:45:29 +02:00
ApplyGioFlags(cfg, gio);
Ui: the window on Crafter.Graphics, driven from the GLib main loop The window library. Loop makes the Wayland display a GSource (libwayland's prepare_read protocol) so D-Bus and the window are served from one thread without the library's StartSync, which runs a loop of its own that serves no GMainContext and would starve the bus; the app owns its frame callback too — a redraw is a frame request and a bare commit, the compositor's done runs one Window::Update, and nothing re-arms unless something is dirty or animating — or the day changes: the captions name the day and an idle window draws no frame by itself, so a timer on the wall clock, which wakes at the next local midnight and whenever that clock is set, asks for one when the local date is another one (DayWatch); when the compositor's connection breaks the source stops and says so (App's onDisplayLost), since the process cannot connect its display again. Canvas initialises the device once per process and holds the window, the font with a word wrapper and a text width over its unrounded advances, as DrawText draws them, and four compositing layers (background, the clipped scrolling content, the chrome, an overlay): within one fused dispatch all quads composite before all text, so the layers are separate dispatches in that order. The layers' buffer slots hand their numbers back to the descriptor heap when they go, so the heap is declared before them and outlives them. Screens draw the conversation list (avatars, previews, time captions, unread badges, the new-conversation button, with room under the last row to scroll clear of it) and one conversation (day separators, wrapped bubbles, clock and state captions — only what is in view, the layer's glyph budget being finite) and record the regions a tap can hit. App wires them to the store and Sync: mouse events become gestures (the detector's slop and fling threshold set from the window's scale, the positions being buffer pixels), a tap is resolved against the last frame's regions (which name the conversation or message they drew, not a position a reload may shift), scrolling is by wheel, drag or fling (a press stops a fling; a screen change stops a fling and cancels the press under it, so the scroll left behind keeps no velocity for a return to revive and a release after a link's or a notification's Open is no tap on the new screen), the window is created on the first Show (when the library cannot and says so — no display, a compositor without wl_shm, wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open opens nothing, and the app runs on without one; a later Show fails at once, the device's set-up running only once) and torn down in order on Shutdown. ScreenshotThenQuit renders one frame outside the compositor's pacing and saves it; a window it creates first waits 600 ms for the compositor's configure, which sizes it (to the screen, on a phone). A capture with no window to render it — none could be made, or it went before the frame — is logged and sets App's exitCode to 1. project.cpp gains Crafter.Graphics (--local takes the branch worktree with the Wayland input work until it is merged), the imsd-messages-ui library, and libevdev from the prefix of packaging/build-libevdev.sh on the library's include path and the executable's library path (a sysroot build looks for it in the sysroot instead).
2026-10-18 00:26:09 +02:00
cfg.files.push_back("assets/NotoSans-Regular.ttf");
// libevdev, for Crafter.Graphics's gamepad backend: the crafter-build
// Flatpak's SDK has none, so a sysroot build looks for it in the
// sysroot and a native build in the prefix of
// packaging/build-libevdev.sh. Crafter.Graphics itself names
// the host's directory, which is an ignored, absent path in the sandbox.
if (!cfg.sysroot.empty()) {
graphics->compileFlags.push_back("-I=/usr/include/libevdev-1.0");
} else {
const std::string arch = cfg.target.substr(0, cfg.target.find('-'));
const char* env = std::getenv("IMSD_MESSAGES_LIBEVDEV");
const char* home = std::getenv("HOME");
const fs::path prefix = env ? fs::path(env) : fs::path(home ? home : ".") / ".cache" / "imsd-messages" / std::format("libevdev-{}", arch);
if (!fs::exists(prefix / "include" / "libevdev-1.0")) std::println(std::cerr, "imsd-messages: no libevdev at {} — run packaging/build-libevdev.sh first", prefix.string());
graphics->compileFlags.push_back(std::format("-I{}", (prefix / "include" / "libevdev-1.0").string()));
cfg.linkFlags.push_back(std::format("-L{}", (prefix / "lib").string()));
cfg.linkFlags.push_back(std::format("-Wl,-rpath,{}", (prefix / "lib").string()));
}
cfg.AddTest("Number").Dependencies({ Core.get() });
cfg.AddTest("Time").Dependencies({ Core.get() });
cfg.AddTest("Wrap").Dependencies({ Core.get() });
cfg.AddTest("Model").Dependencies({ Core.get() });
Store: the message database on Crafter.DB One table without an ordered column: Crafter.DB enforces the order on every write, and a List() import after a restart can carry an older stamp than the last row, so a conversation is sorted on read. A row carries the plan it was written under, the SIM's country code and its operator, a column each. Messages are looked up by imsd id (unique across imsd's runs by its run token: an id names one message, and an empty one — a text imsd has not answered yet — none); read marks and deletes go per message and per conversation; every write but a Compact is caught at this one boundary — a store that refuses one (Crafter.DB's IOError: the disk full, the file system read-only) answers nullopt from Add, false or a count of 0 (a row appended before its Flush failed is tombstoned; an in-place write whose Flush failed stays in the row as the process reads it; SetState's state and imsd's id land in place even when a reason cannot — the id is inline in the row, 64 bytes as imsd bounds it, one past that refused rather than thrown), and tells its onWriteState listener once of the refusal and once of the next write that got room, which is one that grew a file: Crafter.DB allocates its extents, so a write that fit the ones it had (an in-place one, a short row) is no recovery. So a refused write ends no caller's process and the app's banner can say so. A lock file beside the table, held for the store's life, makes a second store on the same directory throw LockedError (the table's own lock sits on an inode a Compact replaces); it is built on Crafter.DB's File and Os — the directory made 0700 at every component, the file 0600 and never a symlink, a lock that fails for any reason but another holder an IOError, not a LockedError. Every change a call answers as made — a row id, true, a count — is committed before the call returns, so a row Add returned is on disk. The file's format is held by the build: static_asserts on the row's size and layout fingerprint (Crafter.DB's Layout) and on the stored values of Direction and MessageState, so a column changed without a version bump fails the build and not a user's open, and an enumerator moved fails it where an open would misread the stored states without a word. Tested: tests/Store in a temp directory: the round trip, the sort of a later-appended older message, the updates, the lookup by imsd id and an erased row's, an id past imsd's bound refused, the lock from a second open, persistence across a reopen, Compact, a row kept by a child process that ends without a flush, the private file modes, and a write refused under the file-size limit (told once with its reason, the rows before it standing, an in-place write going through and telling nothing, a state landing without its refused reason and imsd's id beside it, the next Add after the limit's lifting telling of the recovery once), and a Flush failing after its Append (the descriptor pointed at /dev/null for the one write) tombstoning the row Add refused.
2026-10-17 23:25:48 +02:00
cfg.AddTest("Store").Dependencies({ Core.get(), db });
Sync: the app's side of the Messaging interface over an abstract transport imsd keeps a received text it could store until the app deletes it and sends its signals unicast to subscribers, so the logic is: Subscribe whenever net.catcrafts.IMS1 appears (imsd's restart empties its list), then GetStatus, whose answer ends the connecting state, and List, both at once — a listed or signalled text keys itself by the number it arrived for (imsd's `to`, the subscriber's own number at receipt) or, lacking one, by the service centre that delivered it (Model's MessageFromReceived), so no import waits for a status; import what the store lacks, keyed by imsd's id (its run's token makes it unique across imsd's runs, §8.4), and delete imsd's copy — again for a copy still listed, so a delete that timed out gets another chance. A short message type 0 (Model's IsType0) is not imported: imsd acknowledged it, and its copy is deleted like any other. A copy polkit refused to delete is counted on the banner and tried again at the next List imsd admits (one polkit action gates List and Delete, so an admitted List means an admitted Delete) and once imsd has restarted. A Received signal imports and lists again, because a signal is queued for nobody. The listener is called through a guard (GuardedListener): a throw out of a handler — a logging failure, a bad_alloc — is caught and told once, so no handler can stop Sync's own sequence, whatever the order of a word and the step after it. A store that refuses a write (its disk full) is on the banner. A listed text stays imsd's — nothing is deleted — and a signalled one is held in memory and told through OnUnstored: imsd signals a text its own store refused too, the signal then its only delivery, so no List may ever carry it; the held text is tried again whenever a List comes back with imsd's texts and at each Refresh, which is wanted while one is held, until its row is in or a List carries it; one imsd did not store is lost with a process that ends before then. Of the refusal itself the store tells Sync of a refusal once and once of the next write that got room (one that grew a file), every write but a Compact passing that one gate, and the flag stays the store's — read again after the start's sweep and after imsd's vanish; a send still goes, its own write a try — refused, it answers kNotStored and the caller keeps the text; through, it goes to imsd, and imsd's id lands in place (the store keeps it inline) — a recovery lists at once and the Refresh lists meanwhile, so the held imports are tried once there is room. A listener's call can come from inside Sync's own (the store's word on a write, inside Send), which the listener interface says. A Send stores the message pending under its conversation key and asks imsd for the address as dialled (the key groups; a country code completed for it is never dialled), the row carrying the plan it is dialled under — the country code of the SIM's own number, never the service centre's stand-in, and its operator, which imsd's status gives — which a retry under another SIM's plan fails on, since the address would reach another subscriber or another service there (Number's AnotherPlan, here with its first caller: the same operator is the same plan, a side's code known or not; under another operator a national number means the same while both SIMs' own numbers have one country code, and a short code is the operator's own; without both operators the codes decide alone), and the StateChanged for its id (unique across imsd's runs by the run's token, so it names one message) moves it on — each word as it comes, imsd giving them in order (the submission's first, a report's after sent; its AGENTS.md section 8.4) — and a retry drops the failed attempt's imsd id (a row's id names its current attempt); a Send's error fails the row and Retry sends the text again, so the transport's contract (ImsdTransport's comment) is that a Send is answered by imsd, or because imsd has left the bus, and never by a clock of the transport's own, since imsd sends what it was asked once its polkit prompt lets the call through, however late; imsd vanishing fails what was in flight, and a message still pending from an earlier run is failed at start, because its answer may have come while the app was not running. A refused Subscribe or List is the degraded mode: the banner says so and sending is off — until Refresh is admitted again, since imsd asks polkit on every gated call and a refusal that held while the session was inactive lifts when it is active (a List answered ends it, a refused Subscribe is made again; every refusal is announced, and RefreshWanted() asks for the Refresh). A Subscribe that fails otherwise, a GetStatus or a List (one that timed out: the texts imsd holds would wait for the next signal) is tried again by Refresh too, which RefreshWanted() asks for — one Subscribe at a time, so a rule that prompts is not asked again while that Subscribe waits on its prompt; a registration change reads the status again, since imsd fills in the subscriber's own number and the service centre's when it registers; the own number's country code completes a typed national number (a received one carries its own), the centre's stands in when the network gave no tel: URI (an MVNO's centre can be abroad); without either a national number stays as typed, since the store's correspondents do not say where the subscriber is. The transport is an interface with callbacks, so the tests' fake can stand in for the bus. Tested: tests/Sync on a fake transport that records every call and answers when told, the retries, the second GetStatus, the as-dialled destination, a retry under another SIM (refused for a national number under another country's and for a short code under another operator of the same country; let through under the same operator, its own number read or not, and for a national number under another operator of its country), the plan's code the own number's or the constructor's override and never the centre's, a short message type 0 left out of the store with imsd's copy deleted, a text signalled before the status's answer imported at once by the number it arrived for, a listener's throw at a status — the constructor's among them, over a store that refuses — a log line and a registration change caught and told, stopping no step, a Refresh over an unanswered Subscribe sending none, a List that timed out listed again, the words applied as they come, a retry under a new id, and a refusal lifted among them; the store's refusal under the file-size limit (the flag, the Refresh wanted and the log; a send answered kNotStored with imsd asked nothing; an import refused leaving imsd's copy with the banner up across imsd's restart; a short text sent through the refusal, imsd's id landing in place and its `sent` with it, a failed attempt's id dropped at the retry; then, room again, the send's own write clearing the flag and the held text imported and deleted at the List the recovery sends); a signalled text the store refuses that no List carries (told as unstored once, unread though its conversation is open, held across a List's answer and a Refresh, stored at the Refresh after there is room, its delete answered NotFound), one a List does carry (the copy held here dropped, the text imported by the next List), and one still held when another write gives the store room (a Refresh wanted for it alone until the recovery's List is answered); a listed text the store refuses is not held.
2026-10-17 23:36:20 +02:00
cfg.AddTest("Sync").Dependencies({ Core.get() });
cfg.AddTest("Gesture").Dependencies({ Core.get() });
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
cfg.AddTest("Edit").Dependencies({ Core.get() });
Bus: the GDBus client, imsd's dictionaries, the notifier and the owned name The GLib side of the app. Variant reads imsd's Received dictionary by key and type as its SmsVariant writes it (`to`, the number the text arrived for, a tel: URI read like the status's `ppi`; `operator`, the SIM it arrived under), the GetStatus one with the subscriber's own number and the SIM's operator in it (`ppi`, a tel: URI as the frozen interface gives it; `operator`), and maps a GError to the core's error kinds off GDBus's own mapping. Client is the Sync logic's transport: asynchronous calls with their continuations as user data — every reply guarded where it is delivered (OnCallDone), as are the signal handlers and the name watch's callbacks: a throw is a fault the events hear, not the end of the process — the calls behind imsd's polkit gate allow interaction: Subscribe, List and Delete wait two minutes; Send has no bound of the client's, since imsd sends the text once its prompt lets the call through, however late, and a Send given up on would be failed by Sync and be sent all the same; GetStatus ten seconds — (one call: the Messaging status carries the own number, imsd reading both from one snapshot; AGENTS.md §1 names both interfaces), the Messaging and RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose appeared callback is where Sync subscribes. Notifier shows one desktop notification per conversation and replaces it as more texts arrive: one Notify at a time per conversation, since the id to replace comes with the answer; its default action asks the app for that conversation; the body is escaped when the server renders markup (GetCapabilities, asked once; Plasma and GNOME do), so a text's '<' or '&' shows as typed. Instance owns net.catcrafts.ImsdMessages and serves org.freedesktop.Application there, the Desktop Entry Specification's interface of a running application: Activate, Open and ActivateAction, each with its platform data — sent empty and not read: nothing in the app can use an activation token yet — and one action, quit, any other refused (the object registered before the name is asked for, so a launch that forwards the moment the name is granted finds it; Own tells a name another instance holds from a request that failed or was refused, and keeps the error's words); it forwards a call to the owner. project.cpp computes the gio flags once for the bus library, the executable and the Decode test. Tested: tests/Decode (every key of imsd's Received dictionary, one with ten of them, GetStatus, the own number, the SIM's operator, the error kinds, the markup escape, the parameters of the instance's three calls).
2026-10-17 23:45:29 +02:00
// The bus library's decoding test includes GLib's headers: the library's
// compile flags (its link flags come with the library).
TestBuilder decode = cfg.AddTest("Decode");
decode.Dependencies({ Core.get(), Bus.get() });
for (const std::string& flag : gio.compile) decode.CompileFlag(flag);
LintRules::AddRules(cfg);
return cfg;
}