Skip to content

Settings changed in the last 3 seconds before exit are never saved: the debounced options save is not flushed on close #454

Description

@matt-edmondson

What's wrong

ProjectDirector debounces its own options saves:

  • QueueSaveOptions only stamps SaveOptionsQueuedTime (ProjectDirector/ProjectDirector.cs:285).
  • SaveOptionsIfRequired (:389-398), called from Tick, writes the file only after 3 seconds with no further queued change.

Nothing flushes a pending save on shutdown:

  • Main (:62-71) sets no OnClosing handler and does nothing after ImGuiApp.Start returns.
  • File > Exit calls ImGuiApp.Stop() directly (:933).
  • ktsu.AppDataStorage flushes on dispose or exit only for saves queued through its own QueueSave(). The app never calls that; it calls Options.Save() directly (:81, :283).

Failure scenario

The user runs Set Dev Directory, Add New GitHub Owner or a Scan, or resizes a divider, then closes the window within 3 seconds. The change is gone at the next launch.

Token migration is exposed too. The constructor saves options at :81 before PrepareTokens moves the legacy tokens into the OS secret store (:107-111), and the blanked plaintext token reaches disk only through a queued save. Closing within 3 seconds of startup leaves the plaintext GitHubToken/GitHubOwners in the settings file until a later session re-runs the migration.

This was traced from the code and the library documentation. It was not run, because reproducing it needs the ImGui window.

Suggested fix

  • Flush on shutdown: save when SaveOptionsQueuedTime > LastSaveOptionsTime, from an OnClosing handler and after ImGuiApp.Start returns. Alternatively, switch to AppDataStorage's own QueueSave/SaveIfRequired, which already saves on exit.
  • After a startup migration that moved tokens, call Options.Save() immediately instead of queueing the save.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions