Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mobile) - Add better offline support #3279

Merged
merged 14 commits into from
Jul 28, 2023

Conversation

ddshd
Copy link
Contributor

@ddshd ddshd commented Jul 15, 2023

  • Added an option in the settings panels that will allow the user to choose if there should be offline access or not (if they don't want someone to disable the internet and have access to the files still).
  • The app no longer wait to validate tokens or for some other server API calls to succeed, it will allow user access and then handle the results later

Should fix #3239, #3199- would like Android testers to confirm. Was able to recreate the same issue on iOS and tested the fix to work.

@vercel
Copy link

vercel bot commented Jul 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
immich ⬜️ Ignored (Inspect) Visit Preview Jul 16, 2023 10:58pm

@alextran1502
Copy link
Contributor

I don't think this should be set as a setting. It should be handled by default by fixing, and implementing better support for offline cases.

@ddshd
Copy link
Contributor Author

ddshd commented Jul 15, 2023

I don't think this should be set as a setting. It should be handled by default by fixing, and implementing better support for offline cases.

This PR basically supports for a user to stay authenticated even if they're offline (currently it will hit multiple long timeouts waiting for several API endpoints to complete resolving).

I can take out the setting option but this way users have the option to choose if their immich app shows images even if they're offline and their token cannot be validated. I can see some users not wanting to allow that to happen...

@jrasm91
Copy link
Contributor

jrasm91 commented Jul 15, 2023

Google photos and most photo apps don't have that as far as I am aware though. If we added a setting to restrict app access, it seems like a fingerprint option would make more sense IMO.

@ddshd
Copy link
Contributor Author

ddshd commented Jul 15, 2023

Appreciate the feedback from both, I'll remove the setting and we can revisit a restriction feature later on

@ddshd
Copy link
Contributor Author

ddshd commented Jul 15, 2023

Removed setting option

mobile/lib/shared/services/api.service.dart Outdated Show resolved Hide resolved
mobile/lib/routing/auth_guard.dart Outdated Show resolved Hide resolved
mobile/lib/routing/auth_guard.dart Outdated Show resolved Hide resolved
@GadiZimerman
Copy link

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Analysis

  • 🎯 Main theme: Adding better offline support to the mobile application
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • Focused PR: Yes, the PR has a clear and coherent title and description, and all PR code diff changes are properly derived from the title and description.
  • 🔒 Security concerns: No, the PR does not introduce any apparent security concerns. The changes primarily involve local data storage and retrieval, and any server interactions are handled through existing, presumably secure, APIs.

PR Feedback

  • 💡 General PR suggestions: The PR is well-structured and the changes are well-documented in the PR description. However, it would be beneficial to add tests to ensure the new offline functionality works as expected. Additionally, consider handling potential exceptions that may occur during offline mode to ensure the application doesn't crash.

How to use

Tag me in a comment '@CodiumAI-Agent' and add one of the following commands:
/review - Request a review of the latest update to the PR.
/describe - Modify the PR title and description based on the contents of the PR.
/improve - Suggest improvements to the code in the PR. These will be provided as pull request comments, ready to commit.
/ask - Pose a question about the PR.

bool retResult = false;

if (offlineLogin) {
User? offlineUser = Store.tryGet(StoreKey.currentUser);

Choose a reason for hiding this comment

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

Consider adding error handling for the case when the user is offline and the stored user data is null. This could prevent potential crashes or undefined behavior. [important]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed

if (accessToken != null && serverUrl != null) {
try {
// Resolve API server endpoint from user provided serverUrl
await apiService.resolveAndSetEndpoint(serverUrl);
} catch (e) {
// okay, try to continue anyway if offline
deviceIsOffline = true;

Choose a reason for hiding this comment

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

Consider adding a fallback or error message for the user in the case that the device is offline and login is unsuccessful. This would improve user experience by providing clear feedback. [medium]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the device is offline and the login is unsuccessful (i.e. there is no user information stored locally) then it will try to do an online login. If that also fails then it will redirect user back to the login page

@ddshd ddshd force-pushed the offline-loading branch from f53e0c5 to 6e22da3 Compare July 16, 2023 22:38
@ddshd ddshd requested review from fyfrey and CodiumAI-Agent July 18, 2023 03:57
Copy link
Contributor

@fyfrey fyfrey left a comment

Choose a reason for hiding this comment

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

I've tested on Android, offline usage works fine as before. Login/splashscreen takes quite a while (~ 5 seconds), maybe that can be reduced.

@@ -70,6 +76,29 @@ class ApiService {
return url;
}

Future<bool> _isEndpointAvailable(String serverUrl) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we would hit the .well-known endpoint to get the /api if the user forgot to put it in. Maybe only applicable to https but not local IP, can you help me double check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lmk if you have any more question after this after the discussion on Discord

} else {
debugPrint("Error [onNavigation] ${e.toString()}");
router.replaceAll([const LoginRoute()]);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no return statement here, what would happen?

@alextran1502 alextran1502 merged commit fe9ef1a into immich-app:main Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Android: Stuck on the start screen when the server not reachable
6 participants