IBM Worklight - How can I execute JavaScript code

2019-08-13 00:29发布

When a new software update is available, if user has data stored in jsonstore I need to allow user to commit them to the server before applying the software update, so his/her uncommited updates don't get lost. Currently user is unable to use the application until the update is installed.

Is there a way to execute JavaScript code before updating the application so I can initialize the jsonstore, take the data and send to the adapter before performing the update installation?

2条回答
贼婆χ
2楼-- · 2019-08-13 00:54

We saw that the "unload" and "beforeunload" events are fired before a DirectUpdate. Maybe this is an option for code if the data is still available in memory at that point in time?

WL 5.0.6.1 Android - Direct Update keeps Native/Cordova resources active/in memory (e.g. BusyIndicator) but reference is lost

查看更多
Bombasti
3楼-- · 2019-08-13 01:04

There is no programmatic hook available for a developer to use in order to perform an action prior to a Direct Update request.

That said, a Direct Update does not take place during runtime per-se, rather only:

  1. Upon application initialization
  2. Upon returning from the background to the foreground

So from what I understand, only the second scenario above is not being handled.
In the first scenario the user did not yet perform any data manipulations.


Not sure I completely understand the scenario, as you didn't elaborate much, but...
A possible solution would be to use the Cordova Events API (pause, resume).

In theory, you could detect the case where the application was tasked with moving to the background and hopefully save the user data in a secondary collection before that.

And so, when the app is resumed but a Direct Update request has arrived and the primary collection was not previously saved/synced with the server (check with some flag, maybe?) then you could restore the app state using the secondary collection; essentially resume the app with the "unsaved" user data despite the Direct Update request. You/the user could then save and sync the data.

Or something like that.
Feel free to also submit a feature request.

查看更多
登录 后发表回答