-
Notifications
You must be signed in to change notification settings - Fork 48
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
Chrome.dart fails to abstract chrome apis on android (cordova) based applications #227
Comments
This is an interesting use case and while I dont know much about Cordova what I can tell you is that we auto-generate the Dart APIs from metadata in Chrome itself. That metadata describes the APIs for Chrome Extensions and Chrome Packged Apps in a machine parseable way. My understanding is that neither Chrome Packaged App nor Chrome Extensions are supported on mobile versions so chrome.dart won't be of much help to you in that case. What I think would be required would be a new feature that parse Cordova's APIs and emit the appropriate Dart. You can certainly file a feature request to support additional API sources (like Cordova) but to be completely honest it isnt something we would likely get to for some time. The work around (again without knowing much about Cordova) would be to use dart:js interop to invoke the Cordova api directly. |
Adam, thanks for the quick response! I completely understand. This is a bit of an outlier, and in fact, hard As you suggested, I've moved on to use dart:js... for my use case, I'm Here's an example implementation of my dart wrapper for getDevices(): Future<List<GenericBluetoothDevice>>getDevices() {
return newFuture.sync(() {
Completer c =newCompleter();
logger.info("cordova invoking getDevices");
voidonSuccess(JsArray data) {
/*
dartData: [{id: 00:18:9A:30:A7:43, class: 7936, address: 00:18:9A:30:A7:43, name: HQ_UHF_READER}]", source: chrome-extension://dfojickiabkojihjpddjdhgphbihlefn/scout.html.polymer.bootstrap.dart.js (13579)
*/
List dartData = _toDartSimpleObject(data);
logger.info("cordova getDevices succeeded: dartData:${dartData}");
List<GenericBluetoothDevice> devices = dartData.map((Map d) =>newGenericBluetoothDevice(d['address'],d['name'],false,false)).toList();
devices.forEach((GenericBluetoothDevice d) => logger.info("cordova BT DEVICE:${d}"));
c.complete(devices);
}
voidonFailure(e) {
logger.info("cordova getDevices failed: e:${_toDartSimpleObject(e)}");
c.complete([]);
}
context['bluetoothSerial'].callMethod('list',[(data) {onSuccess(data);},(error) {onFailure(error);}]);
returnc.future;
});
}
I'm not super fluent in js, so the tricky part for me was recognizing This method helped to deconstruct the onSuccess() parameters: /// from https://stackoverflow.com/questions/19691693/how-to-convert-javascript-object-to-dart-map }else if(thingisJsObject) { }else{ Thanks again for the response. If I turn up anything that further -Todd On 06/22/2015 07:38 AM, Adam Bender wrote:
|
Parsing cordova apis would be nice if they were represented by IDL, last, last I recall (2 years ago) there was no plans of doing that. It was mostly hand wired together with sticks and crazy glue. I think chrome.dart should work within chrome mobile apps for most usages, but there might be corner cases where something blows up and hard to tell why. @ToddG I'd check with the chrome mobile apps team if whatever behavior your seeing with the android/javascript version is expected. |
I have written a Chrome Desktop/Chrome Mobile (Cordova) application that uses the chrome.bluetooth API. Is it possible for chrome.dart to wrap the cordova chrome api implementations? If not what is the proposed work-around?
Typically, my service layer methods query for the chrome service, and then perform some an action such as connect|disconnect a device, list all devices, etc.
So, my existing code is written in dart and has a dependency on chrome.dart. In a perfect world, the underlying implementation would be transparent to me and I could just use chrome.dart on both chrome desktop and on chrome mobile (via cordova).
Any suggestions?
The text was updated successfully, but these errors were encountered: