Dave is a Principal Technical Evangelist for Microsoft focused on Windows, Windows Phone, Windows Azure and the Web. Based out of the Greater Philadelphia Area.
I’ve been working on a Windows 8 Metro Style App written, using JavaScript, I call Space Cadet.
All of the code samples I have previously posted were built on the Consumer Preview (CP) bits so I thought I would attempt at converting the app to the just announced Release Preview (RP).
I had to do a couple of things to get my app up and running on RP from the CP bits. I will break it down into the following five categories.
I found the easiest way to save time was to start a new project and then copy/paste over my old files in. This ensured I didn’t miss any of the new project/solution settings..
The WinJS library file has been updated from version 0.6 to 1.0.RC. I went into my default.html file and referenced the updated libraries.
CP:
<!-- WinJS references -->
<link href="//Microsoft.WinJS.0.6/css/ui-dark.css" rel="stylesheet">
<script src="//Microsoft.WinJS.0.6/js/base.js"></script>
<script src="//Microsoft.WinJS.0.6/js/ui.js"></script>
RP:
<link href="//Microsoft.WinJS.1.0.RC/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>
<script src="//Microsoft.WinJS.1.0.RC/js/ui.js"></script>
After the creation of the app reference to WinJS.Application there is a new activation variable referencing Windows.ApplicationModel.Activation as well as a call to WinJS strictProcessing. I made sure to include these in my default.js as well. The strictProcessing call will opt your app in to improved error handling.
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
WinJS.strictProcessing();
The way that the app.onactivated event is called has been changed. The checks for termination and resuming have now been created for you. I made sure to include the update checks.
app.onactivated = function (eventObject) {
if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
//TODO: Load State
WinJS.UI.processAll();
}
};
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
args.setPromise(WinJS.UI.processAll());
The Event Handler for ViewState has been greatly simplified. Instead of worrying about viewstatechanged on the current ApplicationView we simply add a resize Event Handler to the window object.
Getting the current ViewState inside our Event Handler has been updated too. Instead of looking at the eventArgs we now grab the value of Windows.UI.ViewManagement.ApplicationView.
Windows.UI.ViewManagement.ApplicationView.getForCurrentView().addEventListener("viewstatechanged", onViewStateChanged);
function onViewStateChanged(eventArgs) {
var viewStates = Windows.UI.ViewManagement.ApplicationViewState, msg;
var newViewState = eventArgs.viewState;
if (newViewState === viewStates.snapped) {
showMenu('snapped');
} else if (newViewState === viewStates.filled) {
showMenu('filled');
} else if (newViewState === viewStates.fullScreenLandscape) {
showMenu('landscape');
} else if (newViewState === viewStates.fullScreenPortrait) {
//Currently not supported
window.addEventListener("resize", onViewStateChanged);
var newViewState = Windows.UI.ViewManagement.ApplicationView.value;
Pretty easy update with only five things to think about. Hopefully this post will help aid you in converting over your own CP apps to RP! I’ll be doing additional testing over the next few days and will post anything I find here as well as any official update guidance that gets released.
If you are currently working on a Windows 8 app and want to get into the Windows Store I would love to hear about it! You may also want to check out my previous Windows 8 Metro Style Development Tips:
Thanks Dave! This will be useful in moving my app from CP to RP. I got my token at the NYC accelerator labs the day they took the store down for submissions, so I'm hoping to get in there and keep the momentum, this will help make it smooth! Installing RP today.
-Jason