Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 993E31834A for ; Tue, 21 Jul 2015 22:17:16 +0000 (UTC) Received: (qmail 38295 invoked by uid 500); 21 Jul 2015 22:17:16 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 38254 invoked by uid 500); 21 Jul 2015 22:17:16 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 38242 invoked by uid 99); 21 Jul 2015 22:17:16 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2015 22:17:16 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 8A03818B107 for ; Tue, 21 Jul 2015 22:17:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id zVq3fDPrMV8z for ; Tue, 21 Jul 2015 22:17:05 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id A906F2C6CB for ; Tue, 21 Jul 2015 22:17:04 +0000 (UTC) Received: by obbop1 with SMTP id op1so123937819obb.2 for ; Tue, 21 Jul 2015 15:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=/9oOpGHsRoyA4xUg4OMfIxMldFhUqC5/WAt98RBv/OE=; b=aFQSdSix9Kg+IsJjn+xmNU0gAu+a9Qq9WzDtjflMGBWxotvZ95B7mnwE928b+73JRc aHOaGxj987dvNV5kOlyeOWpRmpeqV0JxFzt5K51e57H4qD6/JqwAitLa2QvGG26wVh8c J6rmm6IC0XJxUzvdRYxhJv8zVWr/i0EJ/MzFL004lSasa5ci6cgnVMNIOCl194keyqrR 5//pCzU4naYqRACCkI74Rcmdv7JwhxgFmPypWvZUSrZq7qtkakHCuoZkP1k2VTH56m1x tXWWl2PFdN1vySRHP8w+PSmO9AsY1jaKH2FABuWLx8B2fbELOFZROVfyBpuvF2sbrJ7f FZ2A== MIME-Version: 1.0 X-Received: by 10.202.170.66 with SMTP id t63mr32536802oie.40.1437517024069; Tue, 21 Jul 2015 15:17:04 -0700 (PDT) Received: by 10.76.58.36 with HTTP; Tue, 21 Jul 2015 15:17:04 -0700 (PDT) In-Reply-To: <8370e75cedc244068eb2591e385dc09f@DFM-DB3MBX15-05.exchange.corp.microsoft.com> References: <8370e75cedc244068eb2591e385dc09f@DFM-DB3MBX15-05.exchange.corp.microsoft.com> Date: Tue, 21 Jul 2015 15:17:04 -0700 Message-ID: Subject: Re: Plugin discussion: Feature detection From: Jesse To: "dev@cordova.apache.org" Content-Type: multipart/alternative; boundary=001a113cb98e941054051b6a0334 --001a113cb98e941054051b6a0334 Content-Type: text/plain; charset=UTF-8 There are a couple different ways to go about this, but ultimately the mechanisms are already there. 1. WaitForInit If you look at the cordova-device plugin, it pre-populates data about the device it is running on, and this info is available when the deviceready event fires. Essentially the plugin creates a channel, and specifies that this channel must fire BEFORE the deviceready channel can fire, via the call channel.waitForInitialization('onCordovaInfoReady'); //[1] 2. addConstructor The window.cordova object defines an addConstructor method to allow a plugin to do some pre-deviceready work. All functions passed in to cordova.addConstructor will be called at the 'cordovaready' stage which is guaranteed to happen after 'nativeready' and before 'deviceready' [2] Another approach may be to add a getDeviceCapabilites async call to a plugin like Camera that has many varied capabilities depending on where it is running. We could simply instruct users to call this method ( after deviceready ) to know for certain what capabilities are available. The plugin (js) could also cache this info so later calls would not require a round trip. This would allow the app to be active as soon as possible, and place the responsibility on the app developer, especially relevant if the camera api is a small subset of the functionality of the app, and the capabilities are not essential at launch time. [1] https://github.com/apache/cordova-plugin-device/blob/master/www/device.js#L28 [2] https://github.com/apache/cordova-js/blob/master/src/cordova.js#L233 My team is hiring! @purplecabbage risingj.com On Mon, Jul 20, 2015 at 11:34 AM, Rob Paveza wrote: > We chatted briefly about this at the hangout last week, and I wanted to > continue on the discussion. I gave the example that the "Quirks" section > of CameraOptions [1] is longer than the actual API documentation. I like > to pick on the Camera plugin because it's one of the most-used and is very > well-documented, so its holes are easy to understand. > > I looked at a request to, for example, support the element within > a element in config.xml. When we drilled down into the request, > it was because the plugin wasn't well-supported on Windows, so the > developer wanted to be able to do feature detection and bypass using the > plugin there. Presently, Cordova.js doesn't support this; the proxy > doesn't have an opportunity to talk to native until the `deviceready` > event, at which point, mutating the public API surface of the proxy would > result in a race condition (because you're not sure who subscribed to > `deviceready` first). > > I think it's important to note that **how the API can support feature > detection should be up to the plugin author**. If the plugin is trying to > mimic a W3C standard, then it can do so; if it's just trying to fill a > feature gap, it can do that, too. The plugin developer can choose what > fits best. > > ==Proposal== > - I'll make a change to Cordova.js that will create a new event for > plugins to listen to. This will delay the invocation of `deviceready` > until all plugins have signaled completion (we'll avoid breaking > compatibility by having plugins opt-in to this behavior; if they don't opt > in, we'll treat them like they don't need to do anything). Once the plugin > initialization code has been run and the plugins have signaled readiness, > we'll then fire `deviceready`. > - I'd also like to go through the plugins at least in mobilespec and make > some targeted proposals about where we can refactor to improve > feature-detectability. The File Plugin is tough because it's > standards-based on a standard that is defunct, but the Camera plugin might > have some opportunities, as well as Vibration, etc (e.g., vibration is > supported on Windows mobile devices, but not on desktop PCs). > > == Guiding Principles == > - Feature detection should be based on the availability of the platform > API, not the availability of the platform to do the work. > - For example, if we created a Printer plugin, and the device can > support printing but no printers are attached, then the print() API should > be available. > - In such a case, calling print() should result in a runtime error. The > plugin author should provide a way to query for attached printers. > - This allows for a printer to be attached at a later time. > - Features should be in some way able to be queried by code at runtime. > - Whether that's via a "foo.hasFeature(bar)" method or "if (foo.bar)" > truthy check, we should try our best to follow web principles in making > these decisions and enable it to be similar to known practices on the web. > > Looking forward to hearing your thoughts... > -Rob > > [1] https://github.com/apache/cordova-plugin-camera#cameraoptions > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org > For additional commands, e-mail: dev-help@cordova.apache.org > > --001a113cb98e941054051b6a0334--