Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

CB-11836 Allow setting of 'ForegroundText' property via config.xml #195

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions spec/unit/AppxManifest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ describe('AppxManifest', function () {
it('refineColor should leave CSS color name as is', function () {
expect(refineColor(CSS_COLOR_NAME)).toEqual(CSS_COLOR_NAME);
});

it('setForegroundText should change the ForegroundText property on non-Windows 10 platforms', function () {
var visualElementsWindows = AppxManifest.get(WINDOWS_MANIFEST).getVisualElements();
var visualElementsWindows10 = AppxManifest.get(WINDOWS_10_MANIFEST).getVisualElements();

var foregroundTextLight = 'light';
var foregroundTextDark = 'dark';
var foregroundTextDefault = foregroundTextLight;

// Set to 'light'
visualElementsWindows.setForegroundText(foregroundTextLight);
expect(visualElementsWindows.getForegroundText()).toEqual(foregroundTextLight);

// Set to 'dark'
visualElementsWindows.setForegroundText(foregroundTextDark);
expect(visualElementsWindows.getForegroundText()).toEqual(foregroundTextDark);

Copy link
Contributor

@daserge daserge Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also would be good to add a case for missing preference:

            // Simulate the absence of preference, should default to 'light'
            visualElementsWindows.setForegroundText(undefined);
            expect(visualElementsWindows.getForegroundText()).toEqual(foregroundTextLight);

// Simulate removal of preference, should change back to default vlaue 'light'
visualElementsWindows.setForegroundText(undefined);
expect(visualElementsWindows.getForegroundText()).toEqual(foregroundTextDefault);

// Returns nothing on Windows 10
visualElementsWindows10.setForegroundText(foregroundTextLight);
expect(visualElementsWindows10.getForegroundText()).toEqual(undefined);
});

});
});

13 changes: 13 additions & 0 deletions template/cordova/lib/AppxManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ AppxManifest.prototype.getVisualElements = function () {
return this.setBackgroundColor(color);
} catch (e) { return this; }
},
getForegroundText: function () {
return visualElements.attrib.ForegroundText;
},
setForegroundText: function (color) {
// If color is not set, fall back to 'light' by default
visualElements.attrib.ForegroundText = color || 'light';

return this;
},
getSplashBackgroundColor: function () {
var splashNode = visualElements.find('./' + self.prefix + 'SplashScreen');
return splashNode && splashNode.attrib.BackgroundColor;
Expand Down Expand Up @@ -589,6 +598,10 @@ Win10AppxManifest.prototype.getVisualElements = function () {
// See https://msdn.microsoft.com/ru-ru/library/windows/apps/dn423310.aspx
result.getToastCapable = function () {};
result.setToastCapable = function () { return this; };

// ForegroundText was removed in Windows 10 as well
result.getForegroundText = function () {};
result.setForegroundText = function () { return this; };

return result;
};
Expand Down
1 change: 1 addition & 0 deletions template/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function updateManifestFile (config, manifestPath) {
// Apply background color, splashscreen background color, etc.
manifest.getVisualElements()
.trySetBackgroundColor(config.getPreference('BackgroundColor'))
.setForegroundText(config.getPreference('ForegroundText'))
.setSplashBackgroundColor(config.getPreference('SplashScreenBackgroundColor'))
.setToastCapable(config.getPreference('WindowsToastCapable'))
.setOrientation(config.getPreference('Orientation'));
Expand Down