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(android): make AppRestoredResult also returns error info and success boolean #2497

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private JSInjector getJSInjector() {
protected void storeDanglingPluginResult(PluginCall call, PluginResult result) {
PluginHandle appHandle = getPlugin("App");
App appPlugin = (App) appHandle.getInstance();
appPlugin.fireRestoredResult(result.getWrappedResult(call));
appPlugin.fireRestoredResult(result);
}

/**
Expand Down
30 changes: 10 additions & 20 deletions android/capacitor/src/main/java/com/getcapacitor/PluginResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,18 @@ public String toString() {
return this.json.toString();
}

public JSObject getData() {
try {
return this.json.getJSObject("data", new JSObject());
} catch (JSONException ex) {
return null;
}
}

/**
* Return a new data object with the actual payload data
* along side additional metadata about the plugin. This is used
* for appRestoredResult, as it's technically a raw data response
* from a plugin, but with metadata about the plugin.
* @return
* Return plugin metadata and information about the result, if it succeeded the data, or error information if it didn't.
* This is used for appRestoredResult, as it's technically a raw data response from a plugin.
* @return the raw data response from the plugin.
*/
public PluginResult getWrappedResult(PluginCall call) {
public JSObject getWrappedResult() {
JSObject ret = new JSObject();
JSObject data = new JSObject();
data.put("pluginId", call.getPluginId());
data.put("methodName", call.getMethodName());
data.put("data", getData());
ret.put("data", data);
return new PluginResult(ret);
ret.put("pluginId", this.json.getString("pluginId"));
ret.put("methodName", this.json.getString("methodName"));
ret.put("success", this.json.getBoolean("success", false));
ret.put("data", this.json.getJSObject("data"));
ret.put("error", this.json.getJSObject("error"));
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void fireChange(boolean isActive) {

public void fireRestoredResult(PluginResult result) {
Log.d(getLogTag(), "Firing restored result");
notifyListeners(EVENT_RESTORED_RESULT, result.getData(), true);
notifyListeners(EVENT_RESTORED_RESULT, result.getWrappedResult(), true);
}

public void fireBackButton() {
Expand Down
12 changes: 11 additions & 1 deletion core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,17 @@ export interface AppRestoredResult {
* The result data passed from the plugin. This would be the result you'd
* expect from normally calling the plugin method. For example, `CameraPhoto`
*/
data: any;
data?: any;
/**
* Boolean indicating if the plugin call succeeded
*/
success: boolean;
/**
* If the plugin call didn't succeed, it will contain the error message
*/
error?: {
message: string;
}
}

//
Expand Down