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

Commit

Permalink
Merge pull request #22 from manifoldjs/v0.1.1
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
msrodri committed Jun 16, 2015
2 parents 6837d37 + e5b2c33 commit 0215d75
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 68 deletions.
Binary file modified assets/defaultImages/windows/1152x1920.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/defaultImages/windows/44x44.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/defaultImages/windows/71x71.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/defaultImages/wp8/480x800.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/windows/wrapper.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions assets/windows/wrapper.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/wrapper.css">
<title>Hello World</title>
</head>
<body>
<div id="extendedSplashScreen" class="extendedSplashScreen" style="background-color: #464646; height:100%">
<img class="extendedSplashImage" src="/images/SplashScreen.scale-100.png" alt="Launching..." />
<progress class="loading-progress"></progress>
</div>

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/wrapper.js"></script>
</body>
</html>
70 changes: 70 additions & 0 deletions assets/windows/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var setupExtendedSplashScreen, updateSplashScreenPositioning,
splashScreen, splashScreenEl, splashScreenImageEl,
isWindows = navigator.appVersion.indexOf("Windows Phone 8.1") === -1;

WinJS.Application.addEventListener("activated", function (e) {
if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
splashScreen = e.detail.splashScreen;

// Listen for window resize events to reposition the extended splash screen image accordingly.
// This is important to ensure that the extended splash screen is formatted properly in response to snapping, unsnapping, rotation, etc...
window.addEventListener("resize", updateSplashPositioning, false);

var previousExecutionState = e.detail.previousExecutionState;
var state = Windows.ApplicationModel.Activation.ApplicationExecutionState;
if (previousExecutionState === state.notRunning
|| previousExecutionState === state.terminated
|| previousExecutionState === state.closedByUser) {
setupExtendedSplashScreen();
}
}
}, false);

setupExtendedSplashScreen = function () {
splashScreenEl = document.getElementById("extendedSplashScreen");
splashScreenImageEl = (splashScreenEl && splashScreenEl.querySelector(".extendedSplashImage"));
splashLoadingEl = (splashScreenEl && splashScreenEl.querySelector(".loading-progress"));

if (!splashScreen || !splashScreenEl || !splashScreenImageEl) { return; }

var imgSrc = "/images/splashScreenPhone.png"
if (isWindows) {
imgSrc = "/images/SplashScreen.png"
}

splashScreenImageEl.setAttribute("src", imgSrc);

updateSplashPositioning();

// Once the extended splash screen is setup, apply the CSS style that will make the extended splash screen visible.
splashScreenEl.style.display = "block";
};

updateSplashPositioning = function () {
if (!splashScreen || !splashScreenImageEl) { return; }
// Position the extended splash screen image in the same location as the system splash screen image.
if (isWindows) {
splashScreenImageEl.style.top = splashScreen.imageLocation.y + "px";
splashScreenImageEl.style.left = splashScreen.imageLocation.x + "px";
splashScreenImageEl.style.height = splashScreen.imageLocation.height + "px";
splashScreenImageEl.style.width = splashScreen.imageLocation.width + "px";
} else {
var curOrientation = Windows.Devices.Sensors.SimpleOrientationSensor.getDefault().getCurrentOrientation();
if ((curOrientation == Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise || curOrientation == Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise) &&
Windows.Graphics.Display.DisplayInformation.autoRotationPreferences != Windows.Graphics.Display.DisplayOrientations.portrait) {
splashScreenImageEl.src = "/images/splashscreen.png";
} else {
splashScreenImageEl.src = "/images/splashScreenPhone.png";
}
splashScreenImageEl.style.width = "100%";
splashScreenImageEl.style.height = "100%";
}

if (splashLoadingEl) {
if (isWindows) {
splashLoadingEl.style.top = (splashScreen.imageLocation.y + splashScreen.imageLocation.height + 20) + "px";
} else {
splashLoadingEl.style.top = (window.innerHeight * 0.8) + "px";
}
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-hostedwebapp",
"version": "0.1.0",
"version": "0.1.1",
"description": "Hosted Web App Plugin",
"cordova": {
"id": "cordova-plugin-hostedwebapp",
Expand Down
17 changes: 12 additions & 5 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-hostedwebapp"
version="0.1.0">
version="0.1.1">
<name>HostedWebApp</name>
<description>Hosted Web App Plugin</description>
<license>MIT License</license>
Expand All @@ -11,15 +11,22 @@

<dependency id="cordova-plugin-whitelist" version=">=1.0.1" />
<dependency id="cordova-plugin-network-information" version=">=1.0.0" />
<hook type="before_prepare" src="scripts/updateConfiguration.js" />

<hook type="before_prepare" src="scripts/updateConfigurationBeforePrepare.js" />
<hook type="after_prepare" src="scripts/updateConfigurationAfterPrepare.js" />
<hook type="after_build" src="scripts/updateConfigurationAfterBuild.js" />

<hook type="after_prepare" src="scripts/replaceWindowsWrapperFiles.js" />
<hook type="before_plugin_rm" src="scripts/rollbackWindowsWrapperFiles.js" />

<js-module src="www/hostedWebApp.js" name="hostedwebapp">
<clobbers target="hostedwebapp" />
</js-module>

<engines>
<engine name="cordova-windows" version="4.0.0" />
<engine name="cordova-ios" version="3.8.0" />
<engine name="cordova-android" version="4.0.2" />
</engines>

<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,6 @@ Cordova for Android and iOS platforms provide a security policy to control which
The Windows and Windows Phone platforms do not provide control for these kind of requests, and they will be allowed.


## Changelog

Releases are documented in [GitHub](https://github.com/manifoldjs/ManifoldCordova/releases).
140 changes: 140 additions & 0 deletions scripts/replaceWindowsWrapperFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env node

var fs = require('fs'),
path = require('path'),
url = require('url'),
etree,
projectRoot;

var logger = {
log: function () {
if (process.env.NODE_ENV !== 'test') {
console.log.apply(this, arguments)
}
},
warn: function() {
if (process.env.NODE_ENV !== 'test') {
console.warn.apply(this, arguments)
}
}
};

function copyFile(source, target, callback) {
var cbCalled = false;

function done(err) {
if (!cbCalled) {
callback(err);
cbCalled = true;
}
}

var rd = fs.createReadStream(source);
rd.on('error', done);

var wr = fs.createWriteStream(target);
wr.on('error', done);
wr.on('close', function() {
done();
});
rd.pipe(wr);
};

function updateManifestFile(manifestPath) {
var contents = fs.readFileSync(manifestPath, 'utf-8');
if(contents) {
//Windows is the BOM. Skip the Byte Order Mark.
contents = contents.substring(contents.indexOf('<'));
}

var startPage = "www/wrapper.html";
var manifest = new etree.ElementTree(etree.XML(contents));
var appNode = manifest.find('.//Application');

appNode.attrib.StartPage = startPage;

// Write out manifest
fs.writeFileSync(manifestPath, manifest.write({indent: 4}), 'utf-8');
}

function updateWindowsManifests() {
var MANIFEST_WINDOWS8 = 'package.windows80.appxmanifest',
MANIFEST_WINDOWS = 'package.windows.appxmanifest',
MANIFEST_PHONE = 'package.phone.appxmanifest',
MANIFEST_WINDOWS10 = 'package.windows10.appxmanifest';

// Apply appxmanifest changes
[ MANIFEST_WINDOWS,
MANIFEST_WINDOWS8,
MANIFEST_PHONE,
MANIFEST_WINDOWS10 ].forEach(
function(manifestFile) {
updateManifestFile(path.join(projectRoot, "platforms", "windows", manifestFile));
});
}

module.exports = function (context) {
projectRoot = context.opts.projectRoot;

// if the windows folder does not exist, cancell the script
var windowsPath = path.join(projectRoot, "platforms","windows");
if (!fs.existsSync(windowsPath)) {
return;
}

etree = context.requireCordovaModule('cordova-lib/node_modules/elementtree');

// move contents of the assets folder to the windows platform dir
var Q = context.requireCordovaModule('q');

var filename = "wrapper";

var sourcePath = path.resolve(__dirname, "..", "assets", "windows", "wrapper.html");
var destPath = path.join(projectRoot, "platforms","windows", "www", filename + ".html");

logger.log('Copying wrapper html file for the windows platform from '+ sourcePath + ' to ' + destPath + '.');

var task = Q.defer();
copyFile(sourcePath, destPath, function (err) {
if (err) {
console.error(err);
return task.reject(err);
}

console.log("Finished copying wrapper html file for the windows platform.");

var sourcePath = path.resolve(__dirname, "..", "assets", "windows", "wrapper.js");
var destPath = path.join(projectRoot, "platforms", "windows", "www", "js", filename +".js");

logger.log('Copying wrapper js file for the windows platform from '+ sourcePath + ' to ' + destPath + '.');

copyFile(sourcePath, destPath, function (err) {
if (err) {
console.error(err);
return task.reject(err);
}

console.log("Finished copying wrapper js file for the windows platform.");

var sourcePath = path.resolve(__dirname, "..", "assets", "windows", "wrapper.css");
var destPath = path.join(projectRoot, "platforms", "windows", "www", "css", filename + ".css");

logger.log('Copying wrapper css file for the windows platform from '+ sourcePath + ' to ' + destPath + '.');

copyFile(sourcePath, destPath, function (err) {
if (err) {
console.error(err);
return task.reject(err);
}

console.log("Finished copying wrapper css file for the windows platform.");

updateWindowsManifests();

task.resolve();
});
});
});

return task.promise;
};
104 changes: 104 additions & 0 deletions scripts/rollbackWindowsWrapperFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env node

var createConfigParser = require('./createConfigParser'),
fs = require('fs'),
path = require('path'),
url = require('url'),
pendingTasks = [],
Q,
config,
projectRoot,
etree;

var logger = {
log: function () {
if (process.env.NODE_ENV !== 'test') {
console.log.apply(this, arguments)
}
},
warn: function() {
if (process.env.NODE_ENV !== 'test') {
console.warn.apply(this, arguments)
}
}
};

function deleteFile(path) {
var t = Q.defer();
pendingTasks.push(t);

logger.log('Deleting ' + path + ' file for the windows platform.');

fs.unlink(path, function (err) {
if (err) {
console.log(err);
return t.reject();
}

t.resolve();
});
}

// Configure Cordova configuration parser
function configureParser(context) {
var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util'),
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser');
etree = context.requireCordovaModule('cordova-lib/node_modules/elementtree');

var xml = cordova_util.projectConfig(context.opts.projectRoot);
config = createConfigParser(xml, etree, ConfigParser);
}

module.exports = function (context) {
// If the plugin is not being removed, cancel the script
if (context.opts.plugins.indexOf(context.opts.plugin.id) == -1) {
return;
}

var projectRoot = context.opts.projectRoot;

// if the windows folder does not exist, cancell the script
var windowsPath = path.join(projectRoot, "platforms","windows");
if (!fs.existsSync(windowsPath)) {
return;
}

Q = context.requireCordovaModule('q');
var task = Q.defer();

var destPath = path.join(projectRoot, "platforms", "windows", "www", "wrapper.html");
if (fs.existsSync(destPath)) {
deleteFile(destPath);
}

destPath = path.join(projectRoot, "platforms", "windows", "www", "js", "wrapper.js");

if (fs.existsSync(destPath)) {
deleteFile(destPath);
}

destPath = path.join(projectRoot, "platforms", "windows", "www", "css", "wrapper.css");

if (fs.existsSync(destPath)) {
deleteFile(destPath);
}

Q.allSettled(pendingTasks).then(function (e) {
console.log("Finished removing assets for the windows platform.");

// restore content source to index.html in all platforms.
configureParser(context);
if (config) {
console.log("Restoring content source value to index.html");
config.setAttribute('content', 'src', 'index.html');
config.write();
}
else {
console.log("could not load config.xml file");
}

task.resolve();
});

return task.promise;
};
Loading

0 comments on commit 0215d75

Please sign in to comment.