cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Grebnov (Akvelon)" <v-seg...@microsoft.com>
Subject RE: Platform specific preferences
Date Wed, 19 Mar 2014 07:57:44 GMT
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 <bryan@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 <drkemp@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
> > > >
> > > >
> > >
> >
>
Mime
View raw message