cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daserge <...@git.apache.org>
Subject [GitHub] cordova-windows pull request #212: CB-9287 Not enough Icons and Splashscreen...
Date Mon, 28 Nov 2016 12:24:11 GMT
Github user daserge commented on a diff in the pull request:

    https://github.com/apache/cordova-windows/pull/212#discussion_r89770853
  
    --- Diff: template/cordova/lib/prepare.js ---
    @@ -439,6 +490,109 @@ function getUAPVersions(config) {
         };
     }
     
    +/** Checks if a targetProject matches splashscreen target name */
    +function splashScreenTargetProjectMatchesTargetName(targetProject, targetName) {
    +    if (targetName === SPLASH_SCREEN_DESKTOP_TARGET_NAME) {
    +        return targetProject === TARGET_PROJECT_81 || targetProject === TARGET_PROJECT_10;
    +    }
    +
    +    return targetProject === TARGET_PROJECT_WP81;
    +}
    +
    +/** Checks if the splash screen matches the target project
    + * @param targetName 'SplashScreen'|'SplashScreenPhone'
    + * @returns boolean */ 
    +function splashScreenTargetIs(splash, targetName) {
    +    var matchesTarget, targetImg;
    +
    +    if (splash.target) {
    +        // MRT syntax:
    +        matchesTarget = splash.target === targetName;
    +    } else {
    +        // Fall back on find by size for old non-MRT syntax:
    +        targetImg = findPlatformImage(splash.width, splash.height);
    +        matchesTarget = splashScreenTargetProjectMatchesTargetName(targetImg.targetProject,
targetName);
    +    }
    +
    +    return matchesTarget;
    +}
    +
    +// Updates manifests to match the app splash screen image types (PNG/JPG/JPEG)
    +function updateSplashScreenImageExtensions(cordovaProject, locations) {
    +
    +    // Saving all extensions used for targets to verify them later
    +    var extensionsUsed = {};
    +
    +    function checkThatExtensionsAreNotMixed() {
    +        for (var target in extensionsUsed) {
    +            /*jshint loopfunc: true */
    +            if (extensionsUsed.hasOwnProperty(target)) {
    +                var extensionsUsedForTarget = extensionsUsed[target];
    +
    +                // Check that extensions are not mixed:
    +                if (extensionsUsedForTarget.length > 1 && extensionsUsedForTarget.some(function(item)
{
    +                    return item !== extensionsUsedForTarget[0];
    +                })) {
    +                    events.emit('warn', '"' + target + '" splash screens have mixed file
extensions which is not supported. Some of the images will not be used.');
    +                }
    +            }
    +        }
    +    }
    +
    +    function checkTargetMatchAndUpdateUsedExtensions(img, target) {
    +        var matchesTarget = splashScreenTargetIs(img, target);
    +
    +        if (matchesTarget === true) {
    +            extensionsUsed[target] = extensionsUsed[target] || [];
    +            extensionsUsed[target].push(path.extname(img.src.toLowerCase()));
    +        }
    +
    +        return matchesTarget;
    +    }
    +
    +    function updateSplashExtensionInManifest(manifestFileName, splashScreen) {
    +        var manifest = AppxManifest.get(path.join(locations.root, manifestFileName));
    +        var newExtension = path.extname(splashScreen.src);
    +
    +        if (manifest.getVisualElements().getSplashScreenExtension() !== newExtension)
{
    +            events.emit('verbose', 'Set ' + manifestFileName + ' SplashScreen image extension
to "' + newExtension + '"');
    +            manifest.getVisualElements().setSplashScreenExtension(newExtension);
    +            manifest.write();
    +        }
    +    }
    +
    +    var splashScreens = cordovaProject.projectConfig.getSplashScreens('windows');
    +
    +    var desktopSplashScreen = splashScreens.filter(function(img) { 
    +        return checkTargetMatchAndUpdateUsedExtensions(img, SPLASH_SCREEN_DESKTOP_TARGET_NAME);
    +    })[0];
    +
    +    var phoneSplashScreen = splashScreens.filter(function(img) { 
    +        return checkTargetMatchAndUpdateUsedExtensions(img, SPLASH_SCREEN_PHONE_TARGET_NAME);
    +    })[0];
    +
    +    checkThatExtensionsAreNotMixed();
    --- End diff --
    
    ```xml
    <splash src="res/screen/windows/splashscreen.png" width="620" height="300"/>
    <splash src="res/screen/windows/splashscreen.scale-125.jpg" width="775" height="375"/>
    ```
    
    You should not mix image extensions for non-MRT syntax inside one project group - in this
case ^ the second JPG image will not be used as AppxManifest will have PNG for SplashScreen.Image'
extension.
    There is also a [test for this case](https://github.com/apache/cordova-windows/pull/212/files#diff-954e5996601fc5ce41f4107af4f31525R620).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message