Skip to content

Commit

Permalink
Merge pull request #162 from nuald/master
Browse files Browse the repository at this point in the history
Windows 10 manifest support.
  • Loading branch information
EddyVerbruggen committed Apr 9, 2016
2 parents a6f0e92 + 442e7f7 commit 68ea5fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@

<!-- windows -->
<platform name="windows">
<hook type="before_prepare" src="src/windows/hooks/prepare-manifest.js" />
<config-file target="package.windows10.appxmanifest" parent="/Package/Applications/Application/Extensions">
<uap:Extension Category="windows.protocol" StartPage="www/index.html">
<uap:Protocol Name="$URL_SCHEME" />
</uap:Extension>
</config-file>
<config-file target="package.windows.appxmanifest" parent="/Package/Applications/Application/Extensions">
<Extension Category="windows.protocol" StartPage="www/index.html">
<Protocol Name="$URL_SCHEME" />
Expand Down
30 changes: 30 additions & 0 deletions src/windows/hooks/prepare-manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = function(context) {
var fs = context.requireCordovaModule('fs'),
et = context.requireCordovaModule('elementtree'),
path = context.requireCordovaModule('path'),
xml= context.requireCordovaModule('cordova-common').xmlHelpers,
projectRoot = path.join(context.opts.projectRoot, "platforms", "windows");

var MANIFEST_WINDOWS = 'package.windows.appxmanifest',
MANIFEST_PHONE = 'package.phone.appxmanifest',
MANIFEST_WINDOWS10 = 'package.windows10.appxmanifest',
MANIFEST_WINDOWS80 = 'package.windows80.appxmanifest';

function updateManifestFile(manifestPath) {
var doc = xml.parseElementtreeSync(manifestPath);
var root = doc.getroot();
var app = root.find('./Applications/Application');
if (!app) {
throw new Error(manifestPath + ' has incorrect XML structure.');
}
if (!app.find('./Extensions')) {
app.append(new et.Element('Extensions'));
}
fs.writeFileSync(manifestPath, doc.write({indent: 4}), 'utf-8');
}

[MANIFEST_PHONE, MANIFEST_WINDOWS80, MANIFEST_WINDOWS, MANIFEST_WINDOWS10]
.forEach(function(manifestFile) {
updateManifestFile(path.join(projectRoot, manifestFile));
});
}

0 comments on commit 68ea5fb

Please sign in to comment.