Skip to content

[Architecture] Session State Serialization (Restore Last State) #82

@yashksaini-coder

Description

@yashksaini-coder

Goal

Let users "pick up where they left off" when restarting TRX.

Description

Save and restore session state so TRX opens in the same context the user left it:

State to persist (~/.local/state/trx/state.toml):

  • Current tab (Tab enum variant)
  • Last search query (input string)
  • Package list scroll position (selected index)
  • Details scroll offset (details_scroll)

Implementation:

  1. Define a SessionState struct deriving Serialize/Deserialize
  2. On App::new(), attempt to load state.toml; apply the state after the first render
  3. On exit (the main loop's cleanup path), serialize and write the current state

Handle migration gracefully: if the schema changes, fall back to defaults rather than crashing.

Tech

Rust, Serde (serde_toml)

Difficulty

Level 3 – Advanced

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions