Split main.rs: 28k lines, a 1,700-line main() and an 86-field WorkerState - #232
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #206.
Last step of the split of
main.rs. The 172ui.on_*registrations ofmain()move verbatim into 21 functions in the newcrates/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 ispub(crate) fn register_<area>_callbacks(ui: &AppWindow, worker_tx: &mpsc::UnboundedSender<WorkerCommand>)and is called asregister_<area>_callbacks(&ui, &worker_tx);in the same order as the original statements.main()goes from 1,725 to 168 lines andmain.rsfrom 12,391 to 10,836. What stays inline: the setup and the settings-driven UI state, the worker channel and thread, theauto_connectblock, the foreground timer (aslint::Timerthat must live until the end ofmain()), the cfg-gatedkey_prompt::install(&ui)andui.run()with the quit handshake.Both parameters are only used by shared reference (
ui.on_*,ui.as_weak(),ui.window()andworker_tx.clone()), nothing is moved out ofmain(), 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 ofmain.rswith the runs masked equals the original (64,460 tokens), apart from themodanduselines and the 21 call statements; every name bound inside a run stays inside it; no?,return,break,continueor 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 asmain(390 forcordiale-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(Move the unit tests of cordiale-ui out of main.rs #218);WorkerStategrouped into six sub-structs (Group the panel fields of WorkerState into PanelState #225, Group the settings and preferences fields of WorkerState into SettingsState #226, Group the per-network fields of WorkerState into NetworkState #227, Group the transcript and window-content fields of WorkerState into TranscriptState #228, Group the connection and session fields of WorkerState into SessionState #229, Group the window and sidebar fields of WorkerState into WindowState #230);run_workercommand bodies extracted (Move 26 run_worker command bodies into worker_commands.rs #231);main.rswent from 28,699 to about 10,800 lines. Still open for later: a further split of the remainingrun_workerarms and of the 10,800 lines ofmain.rsitself, now cheap to do one module at a time.Branch:
enhancement-issue-206-main