Skip to content

Split main.rs: 28k lines, a 1,700-line main() and an 86-field WorkerState - #232

Merged
Sythos merged 1 commit into
mainfrom
enhancement-issue-206-main
Oct 3, 2026
Merged

Sythos merged 1 commit into
mainfrom
enhancement-issue-206-main

Conversation

@Sythos

@Sythos Sythos commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Closes #206.

Last step of the split of main.rs. The 172 ui.on_* registrations of main() move verbatim into 21 functions in the new crates/cordiale-ui/src/ui_callbacks.rs (radio, connect, security, passkeys, saved profile, navigation, members, channels, directory, DCC and archive, links, views, attach, composer, themes, notifications, four admin areas and the settings screens). Every function is pub(crate) fn register_<area>_callbacks(ui: &AppWindow, worker_tx: &mpsc::UnboundedSender<WorkerCommand>) and is called as register_<area>_callbacks(&ui, &worker_tx); in the same order as the original statements. main() goes from 1,725 to 168 lines and main.rs from 12,391 to 10,836. What stays inline: the setup and the settings-driven UI state, the worker channel and thread, the auto_connect block, the foreground timer (a slint::Timer that must live until the end of main()), the cfg-gated key_prompt::install(&ui) and ui.run() with the quit handshake.

Both parameters are only used by shared reference (ui.on_*, ui.as_weak(), ui.window() and worker_tx.clone()), nothing is moved out of main(), and no Slint callback closure captures a reference parameter (they 'static-capture clones made inside the run, exactly as before). Checked by script: every helper body is token-identical to the original statements (11,563 tokens, no normalisation needed); the token stream of main.rs with the runs masked equals the original (64,460 tokens), apart from the mod and use lines and the 21 call statements; every name bound inside a run stays inside it; no ?, return, break, continue or label outside closure bodies; no name collides with another module; the #[test] count is unchanged (305). The CI log should show the same test counts as main (390 for cordiale-ui). Not verified: nothing is compiled before CI, and runtime behaviour is unchanged only by construction (same statements, same order, same ownership).

This closes the series. What landed under #206, each as its own pull request with the test count checked against main:

main.rs went from 28,699 to about 10,800 lines. Still open for later: a further split of the remaining run_worker arms and of the 10,800 lines of main.rs itself, now cheap to do one module at a time.

Branch: enhancement-issue-206-main

Last step of splitting main.rs: the 172 ui.on_* registrations of main()
move verbatim into 21 register_*_callbacks functions in
src/ui_callbacks.rs, each taking the window and the worker channel by
reference, and main() keeps the setup, the worker thread, the list of
register_* calls and ui.run(). main() goes from 1,725 to 168 lines. No
behaviour change. Fixes #206.
@Sythos Sythos added the enhancement New feature or request label Oct 3, 2026
@Sythos Sythos linked an issue Oct 3, 2026 that may be closed by this pull request
@Sythos Sythos self-assigned this Oct 3, 2026
@Sythos
Sythos merged commit 2a19849 into main Oct 3, 2026
8 checks passed
@Sythos
Sythos deleted the enhancement-issue-206-main branch October 3, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split main.rs: 28k lines, a 1,700-line main() and an 86-field WorkerState

1 participant