Skip to content

Commit

Permalink
feat: Implement FlagshipLink
Browse files Browse the repository at this point in the history
When hosted in the Flagship app, we want the cozy-apps to be able to
forward their queries to the native code

This will allow the native code to have control on the data lifecycle
and chose between the cozy-stack or a local Pouch database as the
source for executing the query

For now we use cozy-intent in order to communicate through post
messages as it is the fastest implementation possible but this may
change in the future if we encounter performances issues (i.e. using a
local HTTP server)
  • Loading branch information
Ldoppea committed Jul 26, 2024
1 parent 16ca7bc commit 3273cc3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/cozy-client/src/FlagshipLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import CozyLink from './CozyLink'
import logger from './logger'

export default class FlagshipLink extends CozyLink {
/**
* @param {object} [options] - Options
* @param {object} [options.stackClient] - A StackClient
* @param {object} [options.client] - A StackClient (deprecated)
* @param {import('cozy-intent').WebviewService} [options.webviewIntent] - The webview's intent reference
*/
constructor({ client, stackClient, webviewIntent } = {}) {
super()
if (client) {
logger.warn(
'Using options.client is deprecated, prefer options.stackClient'
)
}
this.stackClient = stackClient || client
this.webviewIntent = webviewIntent
}

registerClient(client) {
this.stackClient = client.stackClient || client.client
}

reset() {
this.stackClient = null
}

async request(operation, result, forward) {
return this.webviewIntent.call('flagshipLinkRequest', operation)
}

async persistData(data, forward) {
// Persist data should do nothing here as data is already persisted on Flagship side
return
}
}
1 change: 1 addition & 0 deletions packages/cozy-client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { default } from './CozyClient'
export { default as CozyLink } from './CozyLink'
export { default as StackLink } from './StackLink'
export { default as FlagshipLink } from './FlagshipLink'
export { default as compose } from 'lodash/flow'
export {
QueryDefinition,
Expand Down

0 comments on commit 3273cc3

Please sign in to comment.