You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by Sergei Grebnov Home <se...@gmail.com> on 2014/03/15 12:33:29 UTC

Platform specific preferences

Hi,

 

Propose to add optional 'platform' attribute to 'preference' element
(config.xml) so that we can specify different preferences for different
platforms. For example, right now there is a <preference name="SplashScreen"
/> (I'm looking on Android code) but I'm not sure single splash screen image
can fit all different platforms (size, image format, etc).

 

<preference name="BackgroundColor" value="#FFD2691E" platform="wp8" /> <-
wp8 only

<preference name="SplashScreen" value="assets\SplashScreen.png." />  <-- by
default applied to all platforms

<preference name="SplashScreen"
value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" /> <- wp8
will use this image; if remove this preference, wp8 will use preference
above

 

Thoughts?

 

Thx!

Sergey


RE: Platform specific preferences

Posted by Jonathan Bond-Caron <jb...@gdesolutions.com>.
On Tue Mar 18 04:20 PM, Andrew Grieve wrote:
> No idea :P. Stumbled upon it when I was doing a recent CLI refactoring.
> 
> 

+1 for the change but we'd have to drop the widget namespace, no?
https://github.com/apache/cordova-cli/commit/45e80ac1b2c73a18155e74ac286067a4299742d8#diff-6e0c580ec9d220fc4b32a0ffd9b41595R151


Even tests for it:
https://github.com/apache/cordova-cli/commit/45e80ac1b2c73a18155e74ac286067a4299742d8#diff-3a9ac8021b53843b4e1be5b27e6d7188R241

IMHO, "proper" way to do this would be ~
<preference name="SplashScreen" value=" assets/SplashScreen.png">
<preference name=" wp8/SplashScreen" value=" assets/SplashScreen.png">
<preference name=" [platform]/SplashScreen" value=" assets/SplashScreen.png">

And after removing widget spec:

<platform name="wp8">
   <preference name="SplashScreen" value=" assets/SplashScreen.png">
</platform>

Well anyways, assuming splashcreen is a preference instead of a required image.

But heck looks like inconsistency is winning,
J
 

RE: Platform specific preferences

Posted by "Sergey Grebnov (Akvelon)" <v-...@microsoft.com>.
#1 Btw, which version of config.xml must be passed to platform specific update_from_config:function(config) function call by design (cordova-cli)? Original (from cordova root folder) or platform specific derived version (after it was refined)? Right now I see that original one is passed on WP8. Is it bug or by design?

#2  I've also found out that in derived config.xml platform specific preferences are added to the beginning, but according to ConfigParser logic we always take the last one preference. So in case we have platform specific preference and default one we will proceed with default one.

Original config.xml
  <?xml version='1.0' encoding='utf-8'?>
  <widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
      <name>HelloCordova</name>
      <description>
          A sample Apache Cordova application that responds to the deviceready event.
      </description>
      <author email="dev@cordova.apache.org" href="http://cordova.io">
          Apache Cordova Team
      </author>
      <content src="index.html" />
      <access origin="*" />
      <preference name="BackgroundColor" value="#FFD2691E" platform="wp8" />
      <preference name="SplashScreen" value="SpashScreenImage-Default.jpg"/>
      <platform name="wp8">
          <preference name="SplashScreen" value="SplashScreenImage-WP8.jpg"/>
      </platform>
  </widget>

Derived config.xml

  <?xml version='1.0' encoding='utf-8'?>
  <widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
      <preference name="SplashScreen" value="SplashScreenImage-WP8.jpg" />
      <name>HelloCordova</name>
      <description>
          A sample Apache Cordova application that responds to the deviceready event.
      </description>
      <author email="dev@cordova.apache.org" href="http://cordova.io">
          Apache Cordova Team
      </author>
      <content src="index.html" />
      <access origin="*" />
      <preference name="BackgroundColor" platform="wp8" value="#FFD2691E" />
      <preference name="SplashScreen" value="SpashScreenImage-Default.jpg" />
  </widget>

Thx!
Sergey
-----Original Message-----
From: Sergey Grebnov (Akvelon) [mailto:v-segreb@microsoft.com] 
Sent: Wednesday, March 19, 2014 11:58 AM
To: dev@cordova.apache.org
Subject: RE: Platform specific preferences

I didn't know we support <platform> tag inside widget. This is great.

But we should also patch cordova-cli ConfigParser.getPreference function to handle this case.
https://github.com/apache/cordova-cli/blob/master/src/ConfigParser.js#L82

Before

getPreference: function(name) {
    var preferences = this.doc.findall('preference');
    var ret = null;
    preferences.forEach(function (preference) {
        // Take the last one that matches.
        if (preference.attrib.name.toLowerCase() === name) {
            ret = preference.attrib.value;
        }
    });
    return ret;
},

After

getPreference: function(name, platform) {
    var preferences = this.doc.findall('preference');


    if (platform) { // if specified, we search for platform specfic preferences also
        preferences = preferences.concat(this.doc.findall('platform[@name=\'' + platform + '\']/preference'));
    }


    var ret = null;
    preferences.forEach(function (preference) {
        // Take the last one that matches.
        if (preference.attrib.name.toLowerCase() === name) {
            ret = preference.attrib.value;
        }
    });
    return ret;
}

Thx!
Sergey
-----Original Message-----
From: agrieve@google.com [mailto:agrieve@google.com] On Behalf Of Andrew Grieve
Sent: Wednesday, March 19, 2014 12:20 AM
To: dev
Subject: Re: Platform specific preferences

No idea :P. Stumbled upon it when I was doing a recent CLI refactoring.


On Tue, Mar 18, 2014 at 6:55 AM, Bryan Higgins <br...@bryanhiggins.net>wrote:

> When was that added Andrew? That's a super useful feature that 
> deserves to be documented!
>
> https://git-wip-us.apache.org/repos/asf?p=cordova-docs.git;h=759820
>
>
> On Mon, Mar 17, 2014 at 10:58 PM, Andrew Grieve <agrieve@chromium.org
> >wrote:
>
> > I believe that for projects created with the `cordova` tool, putting 
> > tags in <platform> tags already works (they are conditionally copied 
> > to the derived config.xml within platforms/).
> >
> >
> > On Mon, Mar 17, 2014 at 4:44 PM, David Kemp <dr...@chromium.org> wrote:
> >
> > > Currently preferences can be specified inside a <platform> tag in 
> > > the plugin XML. This provides the functionality you describe for a plugin.
> > > I would suggest if we need to add the same functionality at the 
> > > app
> > level,
> > > then we do it the same way (put preferences inside a Platform tag)
> > >
> > >
> > >
> > >
> > > On Sat, Mar 15, 2014 at 7:33 AM, Sergei Grebnov Home < 
> > > sergei.grebnov@gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > >
> > > >
> > > > Propose to add optional 'platform' attribute to 'preference' 
> > > > element
> > > > (config.xml) so that we can specify different preferences for
> different
> > > > platforms. For example, right now there is a <preference 
> > > > name="SplashScreen"
> > > > /> (I'm looking on Android code) but I'm not sure single splash
> screen
> > > > image
> > > > can fit all different platforms (size, image format, etc).
> > > >
> > > >
> > > >
> > > > <preference name="BackgroundColor" value="#FFD2691E" platform="wp8"
> />
> > <-
> > > > wp8 only
> > > >
> > > > <preference name="SplashScreen" value="assets\SplashScreen.png." 
> > > > />
> >  <--
> > > by
> > > > default applied to all platforms
> > > >
> > > > <preference name="SplashScreen"
> > > > value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" 
> > > > />
> <-
> > > wp8
> > > > will use this image; if remove this preference, wp8 will use
> preference
> > > > above
> > > >
> > > >
> > > >
> > > > Thoughts?
> > > >
> > > >
> > > >
> > > > Thx!
> > > >
> > > > Sergey
> > > >
> > > >
> > >
> >
>

RE: Platform specific preferences

Posted by "Sergey Grebnov (Akvelon)" <v-...@microsoft.com>.
I didn't know we support <platform> tag inside widget. This is great.

But we should also patch cordova-cli ConfigParser.getPreference function to handle this case.
https://github.com/apache/cordova-cli/blob/master/src/ConfigParser.js#L82

Before

getPreference: function(name) {
    var preferences = this.doc.findall('preference');
    var ret = null;
    preferences.forEach(function (preference) {
        // Take the last one that matches.
        if (preference.attrib.name.toLowerCase() === name) {
            ret = preference.attrib.value;
        }
    });
    return ret;
},

After

getPreference: function(name, platform) {
    var preferences = this.doc.findall('preference');


    if (platform) { // if specified, we search for platform specfic preferences also
        preferences = preferences.concat(this.doc.findall('platform[@name=\'' + platform + '\']/preference'));
    }


    var ret = null;
    preferences.forEach(function (preference) {
        // Take the last one that matches.
        if (preference.attrib.name.toLowerCase() === name) {
            ret = preference.attrib.value;
        }
    });
    return ret;
}

Thx!
Sergey
-----Original Message-----
From: agrieve@google.com [mailto:agrieve@google.com] On Behalf Of Andrew Grieve
Sent: Wednesday, March 19, 2014 12:20 AM
To: dev
Subject: Re: Platform specific preferences

No idea :P. Stumbled upon it when I was doing a recent CLI refactoring.


On Tue, Mar 18, 2014 at 6:55 AM, Bryan Higgins <br...@bryanhiggins.net>wrote:

> When was that added Andrew? That's a super useful feature that 
> deserves to be documented!
>
> https://git-wip-us.apache.org/repos/asf?p=cordova-docs.git;h=759820
>
>
> On Mon, Mar 17, 2014 at 10:58 PM, Andrew Grieve <agrieve@chromium.org
> >wrote:
>
> > I believe that for projects created with the `cordova` tool, putting 
> > tags in <platform> tags already works (they are conditionally copied 
> > to the derived config.xml within platforms/).
> >
> >
> > On Mon, Mar 17, 2014 at 4:44 PM, David Kemp <dr...@chromium.org> wrote:
> >
> > > Currently preferences can be specified inside a <platform> tag in 
> > > the plugin XML. This provides the functionality you describe for a plugin.
> > > I would suggest if we need to add the same functionality at the 
> > > app
> > level,
> > > then we do it the same way (put preferences inside a Platform tag)
> > >
> > >
> > >
> > >
> > > On Sat, Mar 15, 2014 at 7:33 AM, Sergei Grebnov Home < 
> > > sergei.grebnov@gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > >
> > > >
> > > > Propose to add optional 'platform' attribute to 'preference' 
> > > > element
> > > > (config.xml) so that we can specify different preferences for
> different
> > > > platforms. For example, right now there is a <preference 
> > > > name="SplashScreen"
> > > > /> (I'm looking on Android code) but I'm not sure single splash
> screen
> > > > image
> > > > can fit all different platforms (size, image format, etc).
> > > >
> > > >
> > > >
> > > > <preference name="BackgroundColor" value="#FFD2691E" platform="wp8"
> />
> > <-
> > > > wp8 only
> > > >
> > > > <preference name="SplashScreen" value="assets\SplashScreen.png." 
> > > > />
> >  <--
> > > by
> > > > default applied to all platforms
> > > >
> > > > <preference name="SplashScreen"
> > > > value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" 
> > > > />
> <-
> > > wp8
> > > > will use this image; if remove this preference, wp8 will use
> preference
> > > > above
> > > >
> > > >
> > > >
> > > > Thoughts?
> > > >
> > > >
> > > >
> > > > Thx!
> > > >
> > > > Sergey
> > > >
> > > >
> > >
> >
>

Re: Platform specific preferences

Posted by Andrew Grieve <ag...@chromium.org>.
No idea :P. Stumbled upon it when I was doing a recent CLI refactoring.


On Tue, Mar 18, 2014 at 6:55 AM, Bryan Higgins <br...@bryanhiggins.net>wrote:

> When was that added Andrew? That's a super useful feature that deserves to
> be documented!
>
> https://git-wip-us.apache.org/repos/asf?p=cordova-docs.git;h=759820
>
>
> On Mon, Mar 17, 2014 at 10:58 PM, Andrew Grieve <agrieve@chromium.org
> >wrote:
>
> > I believe that for projects created with the `cordova` tool, putting tags
> > in <platform> tags already works (they are conditionally copied to the
> > derived config.xml within platforms/).
> >
> >
> > On Mon, Mar 17, 2014 at 4:44 PM, David Kemp <dr...@chromium.org> wrote:
> >
> > > Currently preferences can be specified inside a <platform> tag in the
> > > plugin XML. This provides the functionality you describe for a plugin.
> > > I would suggest if we need to add the same functionality at the app
> > level,
> > > then we do it the same way (put preferences inside a Platform tag)
> > >
> > >
> > >
> > >
> > > On Sat, Mar 15, 2014 at 7:33 AM, Sergei Grebnov Home <
> > > sergei.grebnov@gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > >
> > > >
> > > > Propose to add optional 'platform' attribute to 'preference' element
> > > > (config.xml) so that we can specify different preferences for
> different
> > > > platforms. For example, right now there is a <preference
> > > > name="SplashScreen"
> > > > /> (I'm looking on Android code) but I'm not sure single splash
> screen
> > > > image
> > > > can fit all different platforms (size, image format, etc).
> > > >
> > > >
> > > >
> > > > <preference name="BackgroundColor" value="#FFD2691E" platform="wp8"
> />
> > <-
> > > > wp8 only
> > > >
> > > > <preference name="SplashScreen" value="assets\SplashScreen.png." />
> >  <--
> > > by
> > > > default applied to all platforms
> > > >
> > > > <preference name="SplashScreen"
> > > > value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" />
> <-
> > > wp8
> > > > will use this image; if remove this preference, wp8 will use
> preference
> > > > above
> > > >
> > > >
> > > >
> > > > Thoughts?
> > > >
> > > >
> > > >
> > > > Thx!
> > > >
> > > > Sergey
> > > >
> > > >
> > >
> >
>

Re: Platform specific preferences

Posted by Bryan Higgins <br...@bryanhiggins.net>.
When was that added Andrew? That's a super useful feature that deserves to
be documented!

https://git-wip-us.apache.org/repos/asf?p=cordova-docs.git;h=759820


On Mon, Mar 17, 2014 at 10:58 PM, Andrew Grieve <ag...@chromium.org>wrote:

> I believe that for projects created with the `cordova` tool, putting tags
> in <platform> tags already works (they are conditionally copied to the
> derived config.xml within platforms/).
>
>
> On Mon, Mar 17, 2014 at 4:44 PM, David Kemp <dr...@chromium.org> wrote:
>
> > Currently preferences can be specified inside a <platform> tag in the
> > plugin XML. This provides the functionality you describe for a plugin.
> > I would suggest if we need to add the same functionality at the app
> level,
> > then we do it the same way (put preferences inside a Platform tag)
> >
> >
> >
> >
> > On Sat, Mar 15, 2014 at 7:33 AM, Sergei Grebnov Home <
> > sergei.grebnov@gmail.com> wrote:
> >
> > > Hi,
> > >
> > >
> > >
> > > Propose to add optional 'platform' attribute to 'preference' element
> > > (config.xml) so that we can specify different preferences for different
> > > platforms. For example, right now there is a <preference
> > > name="SplashScreen"
> > > /> (I'm looking on Android code) but I'm not sure single splash screen
> > > image
> > > can fit all different platforms (size, image format, etc).
> > >
> > >
> > >
> > > <preference name="BackgroundColor" value="#FFD2691E" platform="wp8" />
> <-
> > > wp8 only
> > >
> > > <preference name="SplashScreen" value="assets\SplashScreen.png." />
>  <--
> > by
> > > default applied to all platforms
> > >
> > > <preference name="SplashScreen"
> > > value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" /> <-
> > wp8
> > > will use this image; if remove this preference, wp8 will use preference
> > > above
> > >
> > >
> > >
> > > Thoughts?
> > >
> > >
> > >
> > > Thx!
> > >
> > > Sergey
> > >
> > >
> >
>

Re: Platform specific preferences

Posted by Andrew Grieve <ag...@chromium.org>.
I believe that for projects created with the `cordova` tool, putting tags
in <platform> tags already works (they are conditionally copied to the
derived config.xml within platforms/).


On Mon, Mar 17, 2014 at 4:44 PM, David Kemp <dr...@chromium.org> wrote:

> Currently preferences can be specified inside a <platform> tag in the
> plugin XML. This provides the functionality you describe for a plugin.
> I would suggest if we need to add the same functionality at the app level,
> then we do it the same way (put preferences inside a Platform tag)
>
>
>
>
> On Sat, Mar 15, 2014 at 7:33 AM, Sergei Grebnov Home <
> sergei.grebnov@gmail.com> wrote:
>
> > Hi,
> >
> >
> >
> > Propose to add optional 'platform' attribute to 'preference' element
> > (config.xml) so that we can specify different preferences for different
> > platforms. For example, right now there is a <preference
> > name="SplashScreen"
> > /> (I'm looking on Android code) but I'm not sure single splash screen
> > image
> > can fit all different platforms (size, image format, etc).
> >
> >
> >
> > <preference name="BackgroundColor" value="#FFD2691E" platform="wp8" /> <-
> > wp8 only
> >
> > <preference name="SplashScreen" value="assets\SplashScreen.png." />  <--
> by
> > default applied to all platforms
> >
> > <preference name="SplashScreen"
> > value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" /> <-
> wp8
> > will use this image; if remove this preference, wp8 will use preference
> > above
> >
> >
> >
> > Thoughts?
> >
> >
> >
> > Thx!
> >
> > Sergey
> >
> >
>

Re: Platform specific preferences

Posted by David Kemp <dr...@chromium.org>.
Currently preferences can be specified inside a <platform> tag in the
plugin XML. This provides the functionality you describe for a plugin.
I would suggest if we need to add the same functionality at the app level,
then we do it the same way (put preferences inside a Platform tag)




On Sat, Mar 15, 2014 at 7:33 AM, Sergei Grebnov Home <
sergei.grebnov@gmail.com> wrote:

> Hi,
>
>
>
> Propose to add optional 'platform' attribute to 'preference' element
> (config.xml) so that we can specify different preferences for different
> platforms. For example, right now there is a <preference
> name="SplashScreen"
> /> (I'm looking on Android code) but I'm not sure single splash screen
> image
> can fit all different platforms (size, image format, etc).
>
>
>
> <preference name="BackgroundColor" value="#FFD2691E" platform="wp8" /> <-
> wp8 only
>
> <preference name="SplashScreen" value="assets\SplashScreen.png." />  <-- by
> default applied to all platforms
>
> <preference name="SplashScreen"
> value="assets\SplashScreenImage.screen-WVGA.jpg." platform="wp8" /> <- wp8
> will use this image; if remove this preference, wp8 will use preference
> above
>
>
>
> Thoughts?
>
>
>
> Thx!
>
> Sergey
>
>