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 #16 from manifoldjs/v0.1.1-extendedsplashscreen
Browse files Browse the repository at this point in the history
V0.1.1 extendedsplashscreen (Issue #14)
  • Loading branch information
msrodri committed Jun 9, 2015
2 parents dbc6d78 + 82c0279 commit 12ed61b
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 12 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 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";
}
}
};
6 changes: 4 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

<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="after_prepare" src="scripts/updateConfigurationAfterPrepare.js" />
<hook type="after_build" src="scripts/updateConfigurationAfterBuild.js" />

<js-module src="www/hostedWebApp.js" name="hostedwebapp">
<clobbers target="hostedwebapp" />
</js-module>
Expand All @@ -37,6 +37,8 @@

<!-- windows -->
<platform name="windows">
<hook type="after_prepare" src="scripts/replaceWindowsWrapperFile.js" />
<hook type="before_plugin_rm" src="scripts/rollbackWindowsWrapperFiles.js" />
<js-module src="src/windows/HostedWebAppPluginProxy.js" name="HostedWebAppPluginProxy">
<merges target="" />
</js-module>
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).
96 changes: 96 additions & 0 deletions scripts/replaceWindowsWrapperFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env node

var fs = require('fs'),
path = require('path'),
url = require('url'),
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);
};

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

// create a parser for the Cordova configuration
projectRoot = context.opts.projectRoot;
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();
}

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();
}

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();
}

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

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

return task.promise;
};
97 changes: 97 additions & 0 deletions scripts/rollbackWindowsWrapperFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/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;
}

Q = context.requireCordovaModule('q');
var projectRoot = context.opts.projectRoot;
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;
};
2 changes: 1 addition & 1 deletion scripts/test/updateConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function initializeContext(testDir) {
var ctx = {
opts : {
plugin: {
id: 'com-manifoldjs-hostedwebapp'
id: 'cordova-plugin-hostedwebapp'
},
projectRoot : testDir
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/updateConfigurationAfterPrepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function configureParser(context) {

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

var windowsDir = path.join(projectRoot, 'platforms', 'windows');
if (fs.existsSync(windowsDir)) {
var windowsXml = cordova_util.projectConfig(windowsDir);
Expand All @@ -45,11 +45,11 @@ module.exports = function (context) {

// save the updated configuration
config.write();

if (windowsConfig) {
// Patch for windows: restoring the start page to index.html
logger.log('Restoring local start page in windows configuration...');
windowsConfig.setAttribute('content', 'src', 'index.html');
windowsConfig.setAttribute('content', 'src', 'wrapper.html');
windowsConfig.write();
}
}
15 changes: 9 additions & 6 deletions src/windows/HostedWebAppPluginProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ var _whiteList = [];

// creates a webview to host content
function configureHost(url, zOrder, display) {

// workaround to avoid the webview scaling issue
var div = document.getElementById("deviceready");
div.classList.remove("blink");

var webView = document.createElement(cordova.platformId === 'windows8' ? 'iframe' : 'x-ms-webview');
var style = webView.style;
style.position = 'absolute';
Expand Down Expand Up @@ -166,6 +161,12 @@ function configureWhiteList(manifest) {
}
}

// hides the extended splash screen
function hideExtendedSplashScreen(e) {
var extendedSplashScreen = document.getElementById("extendedSplashScreen");
extendedSplashScreen.style.display = "none";
}

module.exports = {
// loads the W3C manifest file and parses it
loadManifest: function (successCallback, errorCallback, args) {
Expand Down Expand Up @@ -231,5 +232,7 @@ module.exports.loadManifest(
configureOfflineSupport('offline.html');
configureWhiteList(manifest);
_mainView = configureHost(manifest ? manifest.start_url : 'about:blank', _zIndex);
_mainView.addEventListener("MSWebViewDOMContentLoaded", hideExtendedSplashScreen, false);

cordova.fireDocumentEvent("webviewCreated", { webView: _mainView });
});
});

0 comments on commit 12ed61b

Please sign in to comment.