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 E913CD02B for ; Tue, 4 Dec 2012 01:32:58 +0000 (UTC) Received: (qmail 72814 invoked by uid 500); 4 Dec 2012 01:32:58 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 72792 invoked by uid 500); 4 Dec 2012 01:32:58 -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 72783 invoked by uid 99); 4 Dec 2012 01:32:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2012 01:32:58 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of alunny@gmail.com designates 74.125.82.51 as permitted sender) Received: from [74.125.82.51] (HELO mail-wg0-f51.google.com) (74.125.82.51) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2012 01:32:51 +0000 Received: by mail-wg0-f51.google.com with SMTP id gg4so1319581wgb.18 for ; Mon, 03 Dec 2012 17:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=L8y55JOgdR0dwV0aNQePVXUWgVMdtOHRkW5KUm09FOw=; b=zbczpIRXFjg8PMkltYelHs9GKDMCl+RTDE8/AZWTNtqQTX8WfK16KplBtgbe6arM75 2S4QWXaMGC6cplu1QgrrpOAj9zj6xzU/r8bqUxq22x4TXJagwW/RjCRkPXGfRXqP+Ei4 vb1GkyT9KEKzg3wCihgO3yLXZay3Mv+fpgCnbt7nysT8SC5dUiizZMm4cjeEmVyh2cE3 pf70LNS5Cv8NeSHuUxV08auH96Ag+LbgFUl01L50cf2UUQTQW6ZCeeQAEhcAFRlJRo1w iiO1X97iUPAMFdTQSfqw3X06EE2lIgxDpI1fXkxNaHMraQMmfQCs/ar+nKSxS99icWW2 UArw== MIME-Version: 1.0 Received: by 10.180.86.7 with SMTP id l7mr1540671wiz.5.1354584751572; Mon, 03 Dec 2012 17:32:31 -0800 (PST) Received: by 10.216.100.68 with HTTP; Mon, 3 Dec 2012 17:32:31 -0800 (PST) Reply-To: alunny@gmail.com In-Reply-To: References: Date: Mon, 3 Dec 2012 17:32:31 -0800 Message-ID: Subject: Re: Determining if "you're in cordova" From: Andrew Lunny To: dev@cordova.apache.org Content-Type: multipart/alternative; boundary=f46d04428e02ef88e104cffcd6b2 X-Virus-Checked: Checked by ClamAV on apache.org --f46d04428e02ef88e104cffcd6b2 Content-Type: text/plain; charset=ISO-8859-1 The problem, afaict, is distinguishing between: 1) deviceready hasn't fired yet 2) deviceready isn't ever going to fire which right now boils down to "guess how long deviceready will take, and setTimeout() until some time after that." I tend to agree with Max - it'd be a worthwhile thing to have, unless the implementation is prohibitively difficult. On 3 December 2012 17:17, Anis KADRI wrote: > Well because it never fires you know that you are in a browser's context. > It will only fire if you're on a device or if you fire it yourself. > > There could be two reasons (as far as I know) that 'deviceready' would not > fire. > 1) not in a cordova app context (browser via file:// or http://). > 2) there is a problem with cordova itself (problem fetching device/network > info). > > actions for both > 1) You know whether or not you are in a cordova context: do whatever you > have to do: use childbrowser or a popup, don't use device apis that are > not available etc... > 2) find out if you're not missing anything and/or file a bug > > I believe that 'deviceready' is more reliable then document.location > because it really is cordova specific. > > > > > On Mon, Dec 3, 2012 at 5:06 PM, Filip Maj wrote: > > > But look at that situation from the browser's POV: it attaches to an > event > > that never fires. > > > > cordova.js is included and window.cordova exists, but in a browser's > > context, it does nothing. > > > > On 12/3/12 5:03 PM, "Anis KADRI" wrote: > > > > >document.addEventListener('deviceready', function() > {navigator.inCordova = > > >true;}, false); > > > > > >If you fire 'deviceready' yourself then you already know that you're not > > >in > > >a cordova app context. Don't you ? > > > > > >Sorry, I really don't see what the problem is. Maybe an real world > example > > >would help illustrate it. Or is there a reason why you don't want to use > > >deviceready as an indicator ? > > > > > > > > >On Mon, Dec 3, 2012 at 4:40 PM, Max Ogden wrote: > > > > > >> if cordova polyfilled standard apis for everything it wouldn't be > > >>cordovas > > >> problem. but right now there are only-in-cordova APIs that I need to > > >>use if > > >> i'm in cordova. it would be more convenient for me as an app developer > > >>if > > >> there was a supported way to know i'm in cordova. > > >> > > >> I can keep looking at window.location.href and make sure to always > run a > > >> local web server for development (and never open the file directly on > my > > >> dev machine) but the point here is that doing those things is more > > >>pitfall > > >> prone and less user friendly for new devs than doing "if > > >> (navigator.inCordova)". > > >> > > >> if its a ton of work to implement then I can understand not doing it > (I > > >> dont know what it would take to implement). i'm just trying to say it > > >>would > > >> be a nicer api :) it seems from my perspective that it would be easy > for > > >> cordova to tell the browser that cordova is present and it would save > > >>app > > >> developers from having to use yet another hacky technique. > > >> > > > > > --f46d04428e02ef88e104cffcd6b2--