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: Implement offline support through CozyPouchLink #1209

Open
wants to merge 17 commits into
base: feat/meta_offline
Choose a base branch
from

Commits on Sep 25, 2024

  1. feat: Add react-native modules for PouchDB

    `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
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    9edfd8b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6f9d3ec View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6d95b9d View commit details
    Browse the repository at this point in the history
  4. feat: Configure CozyClient to use CozyPouchLink

    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
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    9876b02 View commit details
    Browse the repository at this point in the history
  5. feat: Configure CozyClient to also use StackLink (when online)

    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
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    4f7614c View commit details
    Browse the repository at this point in the history
  6. feat: Add PouchDBFind plugin to the PouchDB configuration

    This plugin is required by cozy-client to process `find` queries
    
    Related PR: cozy/cozy-client#1507
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    4badb35 View commit details
    Browse the repository at this point in the history
  7. feat: Add clientCachedStorage to handle CozyClient's requests cache

    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)
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    28c007f View commit details
    Browse the repository at this point in the history
  8. feat: Cache /apps/:slug/open request for offline support

    `/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
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    0320297 View commit details
    Browse the repository at this point in the history
  9. feat: Upgrade cozy-intent to 2.23.0

    `cozy-intent` has been upgraded to `2.23.0` to retrieve new interfaces
    for FlagshipLink and files downloading
    
    Related PR: cozy/cozy-libs#2562
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    b5e9ba0 View commit details
    Browse the repository at this point in the history
  10. feat: Implement FlagshipLinkRequest interface through localMethods

    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
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    9f7493c View commit details
    Browse the repository at this point in the history
  11. feat: Enable CacheMode for CozyProxyWebView on android when offline

    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 committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    d0ee380 View commit details
    Browse the repository at this point in the history
  12. feat: Ignore queries warmup on PouchLink

    With previous changes, we now expect the CozyPouchLink to be the last
    link of the chain, so forwarding the query would result to an exception
    thrown
    
    This mean we cannot forward the query when warmup queries are not
    finished yet
    
    So we want to allow CozyPouchLink to ignore the verification step and
    process the query independently of the warmup queries status
    
    To allow this we introduce the `ignoreWarmup` parameter. When set to
    `true` the CozyPouchLink will process the query even if warmup is not
    finished yet
    
    Related PR: cozy/cozy-client#1506
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    6f784de View commit details
    Browse the repository at this point in the history
  13. feat: Declare schemas into cozy-client instance

    Some cozy-apps declare a data `schema` into cozy-client instance
    
    This schema is then used for processing queries
    
    As we now process cozy-app queries on the react-native side through
    FlagshipLinkRequest, we want to declared this schema in the Flagship
    app's cozy-client
    
    For now we only need to implement the one from cozy-home
    
    The ideal implementation would be to extract it from the cozy-app's
    bundle, but we did not implement anything to support this (we should
    first investigate how to do this). So for now it is hardcoded
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    dd1b07a View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    ffd0b10 View commit details
    Browse the repository at this point in the history
  15. feat: Allow to send Pouch databases through email for debug purpose

    By adding offline support through PouchDB, we expect database related
    bugs to happens in the future
    
    In order to ease debugging them, we want to allow exploring the local
    PouchDB files
    
    The easier way is to add the ability to extract them from the device
    and send them through email to cozy's support team
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    8ceea9b View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    fa2d727 View commit details
    Browse the repository at this point in the history
  17. feat: Prevent local PouchDB modification to be replicated to remote DB

    For now we don't want to replicate local changes into remote PouchDB as
    we first want to ensure everything works as expected locally before
    activating two-way replication in the future
    Ldoppea committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    749ef40 View commit details
    Browse the repository at this point in the history