-
Notifications
You must be signed in to change notification settings - Fork 603
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
fix(android): run downloadFile asynchronously #2287
base: main
Are you sure you want to change the base?
Conversation
Released dev build of filesystem with dev version: 7.0.0-dev-2287-20241220T140459.0 |
public void downloadFile(PluginCall call, Bridge bridge, HttpRequestHandler.ProgressEmitter emitter, | ||
FilesystemDownloadCallback callback) throws IOException, URISyntaxException, JSONException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this method no longer throws the mentioned exceptions, but rather returns them in FilesystemDownloadCallback
, therefore we should update the signature
public void downloadFile(PluginCall call, Bridge bridge, HttpRequestHandler.ProgressEmitter emitter, | |
FilesystemDownloadCallback callback) throws IOException, URISyntaxException, JSONException { | |
public void downloadFile(PluginCall call, Bridge bridge, HttpRequestHandler.ProgressEmitter emitter, | |
FilesystemDownloadCallback callback) { |
AsyncTaskResult result = doDownloadInBackground(urlString, call, bridge, emitter); | ||
handler.post(() -> { | ||
if (result.error != null) { | ||
callback.onError(result.error); | ||
} else { | ||
callback.onSuccess(result.result); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that it is unnecessary to have this AsyncTaskResult
, since it either just wraps the result or error if it exists.
I feel like we could lift the try-catch out of doDownloadInBackground
, and have it return the JSObject
directly
AsyncTaskResult result = doDownloadInBackground(urlString, call, bridge, emitter); | |
handler.post(() -> { | |
if (result.error != null) { | |
callback.onError(result.error); | |
} else { | |
callback.onSuccess(result.result); | |
} | |
}); | |
try { | |
JSObject result = doDownloadInBackground(urlString, call, bridge, emitter); | |
handler.post(() -> callback.onSuccess(result)); | |
} catch (Exception error) { | |
handler.post(() -> callback.onError(error)); | |
} |
Also, if you do this change, add the throws IOException, URISyntaxException, JSONException
to the doDownloadInBackground
signature.
What do you think?
Closes #6861
This PR runs
downloadFile
in an async task so it does not block other plugin calls.