Windows store app: detecting if your app is visible or not

I wanted to find out if my game app was visible or not because I wanted to pause the game if the user Alt-Tabbed or pressed the windows key. I found the following article on stack overflow that explained that you can listen to the msvisibilitychange event to detect changes like this:

document.addEventListener("msvisibilitychange", function ()
{
    //Pause function
});

However Microsoft doesn’t seem to be very happy with you putting to much code in this event as it might cause a “less fluid user experience”. I just pause the game there though 🙂

Windows 8: Using jQuery in your Windows Store app

Right, so I thought it would be great to write a HTML5 app in windows 8 since it’s supported and everything. The one thing I refuse to skip though is jQuery. So, I added jQuery 1.9.1 to my app, referenced it in my html-file and ran the app. The following popup showed up:

JavaScript runtime error: Unable to add dynamic content. A script attempted to inject dynamic content or elements previously modified dynamically that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content or explicitly create elements and attributes with a method such as createElement.
The error I received

I searched the web and I found that the only solution that seems safe at the time of writing is to use a “fixed” version for Windows 8, supplied by a company called AppendTo. The files can be downloaded here:
https://github.com/appendto/jquery-win8

Currently the latest jQuery release is 1.9.1 and the AppendTo conversion is 1.8.2 but it’s close enough and it works for me.

According to a couple of videos floating around and some articles on the subject the jQuery 2.0 release will have full support for Windows 8 so that should be great. But until then the AppendTo solution seems to be the best one out there.

Windows 8: App badge logo validation error

As I am almost done with my first Windows 8 App, Himmelsblå Dagar (a Swedish app), I was trying out the Windows App Cert Kit Tool used to validate your application before sending it into Microsoft. It was a good tool as it found two errors I had. One was that I was still building in Debug mode (doh!) and the other was the following:

Image reference “Assets\BadgeLogo.png”: The image “C:\Program Files\WindowsApps\XXX_1.0.0.0_neutral__123456789\Assets\BadgeLogo.png” has an ABGR value “0xFFDDEEFF” at position (0, 0) that is not valid. The pixel must be white (##FFFFFF) or transparent (00######).

I couldn’t figure out what the problem was as I wasn’t using transparency in my badge logo, just a really scaled down version of my normal logo icon. That was the problem. The badge logo can only use white (#FFFFFF) and transparency so I created a new logo using only the color white and it worked.

🙂

Windows 8: Task manager galore

I’ve installed Windows 8 and I had a couple of reasons for it:

  • I was running Windows Vista (need more reasons?)
  • It was cheap (special price, just for you and everyone else!)
  • I was interested in developing apps in C#

After installing Windows 8 I started hating it immediately as I was installing it before heading to bed and I couldn’t find the Shut down button. Also, it ran really slow on my old computer even though it passed Microsoft´s checklist just fine.
I finally found the shut down button soon enough and the next day I found some better drivers so the computer ran more smoothly. So, now I was gonna take a look around and I found the best thing since Microsoft killed of Clippy; the new Task Manager:

It’s a whole lot better then in previous versions of Windows and it gives you much more information about the current status of your computer and what’s running. It separates the information between desktop software and apps and it even has a “Simple View” if you just want to see what’s running:

This is great and I really like it!