-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters