Skip to content

Sync page added ux enhancements - #3885

Merged
aaravgarg merged 3 commits into
mainfrom
sync-page-added-ux-enhancements
Dec 23, 2025
Merged

aaravgarg merged 3 commits into
mainfrom
sync-page-added-ux-enhancements

Conversation

@aaravgarg

Copy link
Copy Markdown
Contributor

No description provided.

@aaravgarg
aaravgarg merged commit 3211811 into main Dec 23, 2025
@aaravgarg
aaravgarg deleted the sync-page-added-ux-enhancements branch December 23, 2025 16:27

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant UX enhancements to the sync page by refactoring the local and cloud storage settings into dedicated pages. This improves modularity and user experience. While the changes are generally positive, I've identified a critical issue in the new LocalStoragePage concerning improper state management within an asynchronous method, which could lead to application crashes. A detailed comment with a suggested fix is provided to address this.

Comment on lines +24 to +49
setState(() => _isSaving = true);
try {
SharedPreferencesUtil().unlimitedLocalStorageEnabled = value;
context.read<SyncProvider>().refreshWals();
setState(() => _isSaving = false);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
value ? 'Local storage enabled' : 'Local storage disabled',
),
backgroundColor: Colors.green,
),
);
}
} catch (e) {
setState(() => _isSaving = false);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to update settings: ${e.toString()}'),
backgroundColor: Colors.red,
),
);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are a couple of issues in the _toggleLocalStorage method that could lead to bugs:

  1. Potential crash: setState is called after an async operation without checking if the widget is still mounted. If the user navigates away from the page before the operation completes, this will throw an exception and crash the app.
  2. Race condition: The SharedPreferencesUtil().unlimitedLocalStorageEnabled = value; setter returns a Future which is not awaited. This means context.read<SyncProvider>().refreshWals() might be called before the preference is actually saved, leading to a state inconsistency.

To resolve these issues, you should await the preference saving operation and use a finally block to safely update the state only when the widget is mounted.

    setState(() => _isSaving = true);
    try {
      await SharedPreferencesUtil().saveBool('unlimitedLocalStorageEnabled', value);
      context.read<SyncProvider>().refreshWals();
      if (mounted) {
        ScaredPreferences.of(context).showSnackBar(
          SnackBar(
            content: Text(
              value ? 'Local storage enabled' : 'Local storage disabled',
            ),
            backgroundColor: Colors.green,
          ),
        );
      }
    } catch (e) {
      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text('Failed to update settings: ${e.toString()}'),
            backgroundColor: Colors.red,
          ),
        );
      }
    } finally {
      if (mounted) {
        setState(() => _isSaving = false);
      }
    }

Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
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.

1 participant