Skip to content

Conversation

@ItzSouraseez
Copy link

PR Description

This PR implements an autosave on close feature that automatically saves all unsaved changes when the application closes, providing a modern, seamless user experience while maintaining backward compatibility with the existing prompt-based save mechanism.

Key Changes:

  • Added autoSaveOnExit boolean field to SettingsModel (defaults to true)
  • Updated ThemeStateNotifier to support the new setting
  • Added "Auto-save on Exit" checkbox in Settings UI
  • Refactored onWindowClose() handler with priority-based logic:
    1. Auto-save if enabled and has unsaved changes
    2. Show prompt dialog if auto-save disabled but prompt enabled
    3. Close immediately if no unsaved changes or both settings disabled
  • Added error handling to prevent data loss when save operations fail

User Experience:

  • By default, the app will auto-save on exit without showing a dialog
  • Users can disable auto-save and keep the traditional "Save Changes" prompt
  • Users can disable both for immediate closure without saving
  • If auto-save fails, an error dialog appears with retry and close-without-saving options

Technical Notes:

  • Fully backward compatible with existing user settings
  • Gracefully handles missing autoSaveOnExit field in stored settings (defaults to true)
  • Leverages existing saveData() method which handles both requests and environments
  • Cross-platform compatible (macOS, Windows, Linux)

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes
  • No, and this is why: The changes primarily affect UI behavior and window lifecycle events which are difficult to unit test. Manual testing has been performed across different setting combinations. Unit tests for SettingsModel serialization/deserialization would be a valuable addition in a follow-up PR.

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An autosave on close?

1 participant