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

Meta PR: Implement offline support #1239

Merged
merged 92 commits into from
Feb 12, 2025
Merged

Meta PR: Implement offline support #1239

merged 92 commits into from
Feb 12, 2025

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Aug 26, 2024

This PR is a temporary "main" for all Offline features until everything is ready to be merged into our main branch

PR List:

Related PRs:

### ✨ Features

* Add support for Offline mode (for now only on cozy-home and mespapiers)

### 🐛 Bug Fixes

*

### 🔧 Tech

*

TODO:

@Ldoppea Ldoppea requested review from acezard and zatteo as code owners August 26, 2024 16:09
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Aug 26, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Aug 27, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
@zatteo
Copy link
Contributor

zatteo commented Sep 2, 2024

🎉🎉

Ldoppea added a commit to cozy/mespapiers that referenced this pull request Sep 13, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Sep 13, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Sep 16, 2024
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Sep 19, 2024
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Sep 24, 2024
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Sep 24, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Sep 25, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Jan 20, 2025
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
`react-native-quick-sqlite` is enforced to version `8.0.6` in order to
be compatible with RN0.72

Related article:
https://dev.to/craftzdog/a-performant-way-to-use-pouchdb7-on-react-native-in-2022-24ej
We want the Flagship app to work when offline

To make this possible we configure cozy-client with CozyPouchLink which
role will be to synchronize necessary doctypes into a local PouchDB and
serve them from it instead of from the cozy-stack when the device is
offline

For now the list of synchronized doctypes is hardcoded but in the
future we expect to implement a dynamic list based on cozy-apps'
manifests

Related PR: cozy/cozy-client#1507
In previous commit we configured cozy-client to use CozyPouchLink for
its queries

This commit also adds StackLink as the first Link so by default it will
do its queries through the remote cozy-stack

CozyClient has been modified to handle offline mode and redirect to the
next link when it is detected

Related PR: cozy/cozy-client#1507
This plugin is required by cozy-client to process `find` queries

Related PR: cozy/cozy-client#1507
PouchDB can handle only `client.query()` requests

For all other requests, like `client.fetchJSON()` we want to be able to
store the request result in the device's AsyncStorage so we can re-use
this result when the device is offline

Data is stored using the client's url and the request content as key
(it can be a string or a full request object)
`/apps/:slug/open` request is based on `client.fetchJSON()` and is on
the critical execution path for the application to boot

So we want to use the new caching mechanism from previous commit in
order to retrieve this request's cached result if the application is
booted while the device is offline
`cozy-intent` has been upgraded to `2.23.0` to retrieve new interfaces
for FlagshipLink and files downloading

Related PR: cozy/cozy-libs#2562
In previous commits we configured the application's cozy-client to use
CozyPouchLink

This link is configured for all react-native side queries, but not for
cozy-app queries as they are served inside of WebViews and use a
different cozy-client instance

We want cozy-apps to benefits from the CozyPouchLink by redirecting
their queries to the react-native side using the new FlagshipLink
interface

With this interface, all cozy-apps queries can be redirected to the
react-native side using cozy-intent/post-me

In order to intercept them, then we should declare
`FlagshipLinkRequest()` method `localMethods`

Related PR: cozy/cozy-client#1505
When a cozy-app's WebView is served offline, then the cozy-app bundle
is served from local folder using the CozyProxyWebview, and since
previous commits, the cozy-client's queries are served through
`FlagshipLink`

With those mechanisms, nearly all data are available offline except two
things:
- cozy-stack static assets (i.e. some css files, avatar, partners logos
etc)
- `fetchJSON()` requests

This commit tries to handle the static assets part

Those assets are often served with HTTP cache activated, and so the
WebView should be able to load them correctly when the device is
offline. However on Android, the WebView's cache seems not to persist
after the application is closed

Activating the `cacheMode=LOAD_CACHE_ELSE_NETWORK` seems to fix this
behavior. But it prioritizes too much the cache over fresh data, so we
want to activate it only when strictly necessary, which is when the
application is offline

This also allows to load partners logos that are not cached by the
cozy-stack (as of today). But we expect to modify the cozy-stack to
enable cache on them
Ldoppea and others added 24 commits February 12, 2025 10:29
For some reasons, the ReactNative API fails to resolve
`cozy-dataproxy-lib/api` path so we must use `/dist` version instead

On the opposite, Jest will fail to resolve the `/dist` version so we
cannot mock cozy-dataproxy-lib

To fix this, we wrap the imports in a local file so we can mock this
local file in Jest
CozyClient.registerPlugin typing requires an `option` parameter to be
defined

But the RealtimePlugin expect this parameter to be optional or to be an
object

If `null` is given, then the application would crash. We injected
`null` in #1279 because the CI did reject the initial attempt with no
parameter, but this was not the correct solution, the correct one would
be to inject an empty object

In the future we may want to make this parameter optional in the
`registerPlugin` definition
`cozy-dataproxy-lib` has been upgraded to `3.2.0` in order to retrieve
the new Performance API implementation

Related PR: cozy/cozy-libs#2720
In cozy/cozy-libs#2720 we added PerformanceAPI in the SearchEngine

This commit reflect the changes to the SearchEngine constructor

Related PR: cozy/cozy-libs#2720
Since cozy/cozy-libs/pull/2729 the SearchEngine requires the consuming
app to provide a storage provider in order to persist its index

Related PR: cozy/cozy-libs#2729
In #1253 we upgraded ReactNative we now need node version 18 or higher

The change has been made in the package.json but we forgot to reflect
it in the `.nvmrc` file
When implementing the offline support, we did test the unlock screen
using the PIN code

But we found that the Unlock by Password mode would require internet
access in order to retrieve the number of KDF iterations for hashing
the password

By caching this method's result, we allow this method to retrieve the
number of KDF iteration even when offline
When implementing the offline support, we did test the unlock screen
using the PIN code

But we found that the Unlock by Password mode would require internet
access in order to verify the password on the cozy-stack side

By nature this is impossible to do when offline, and we already check
the entered password against the one stored in the phone's keychain

So we want to make this method resilient to connectivity issues

When disconnected, the app will now only checks the password agains the
hash stored in the local keychain
This database can be extremly large and brings few value
This is a tradeoff between power consumption and reactivity.
But the realtime updates should mitigate the need to replicate too often
`cozy-dataproxy-lib` has been upgraded to `3.4.0` in order to allow
waiting for the SearchEngine initialization

Related PR: cozy/cozy-libs#2730
`cozy-realtime` has been upgraded to `5.6.4` in order to retrieve a fix
on refreshToken mechanism that would break the realtime stream

Related PR: cozy/cozy-libs#2731
`cozy-client` and `cozy-pouch-link` have been upgraded to `54.0.0` in
order to retrieve a fix on the refreshToken mechanism that did not work
when token expired during a Pouch replication

Related PR: cozy/cozy-client#1587
We used to init search at app initilization. However, we noticed that
this can be time consuming and slow down the app openening. Thus, we
prefer to make the user wait for an extra few seconds for the first
search, to init the search at this moment, rather than waiting at each
app opening.  Note we previously have added the index persistence
feature, in order to speed up this initialization.
@Ldoppea Ldoppea merged commit 3707229 into master Feb 12, 2025
1 check passed
@Ldoppea Ldoppea deleted the feat/meta_offline branch February 12, 2025 10:03
paultranvan pushed a commit to cozy/cozy-home that referenced this pull request Feb 12, 2025
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Feb 12, 2025
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Feb 12, 2025
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
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.

3 participants