Click here to Skip to main content
Click here to Skip to main content

Strategist: Detecting Windows Store App Configuration Mode (Debug vs. Release) in JavaScript

, 15 Oct 2013
Rate this:
Please Sign up or sign in to vote.
Detecting Windows Store app configuration mode.

Windows Library for JavaScript (WinJS) is an amazing library. This along with the projected winmd libraries, developers have almost everything they would ever need to develop an average Windows Store App. One thing that is missing that I recently came across is the ability to detect which configuration mode the App is currently running in (Debug or Release).

I needed to enhance a few debugging capabilities if the App is in Debug mode. To detect the current mode in JavaScript I used the beauty of language projection. The following sections will examine this in more detail.

C#

First, I used a C# Windows Runtime Component to enable the capability of using the implementations in JavaScript. I then created what I called a ConfigurationManager. Below is the code:

namespace AppName.Utilities
{
    public sealed class ConfigurationManager
    {
        public static bool IsDebug {
            get {
#if DEBUG
                return true;
#else
                return false;
#endif
            }
        }
    }
}

The simplicity of this class cannot be overstated. It has a single static property called IsDebug. The key part of the implementation is the use of compiler directives #if and #else.

#if the DEBUG constant is defined, then the App is in Debug mode. #else (otherwise), the App is in Release mode.

JS

After adding a reference to this component and rebuilding, I can now detect the current configuration mode in the JavaScript App:

var isDebug = AppName.Utilities.ConfigurationManager.IsDebug;
if(isDebug) {
    //debug-specific code.
} else {
    //release-specific code.
}

Please note that this depends on the compiler. There is one potential issue with this: the perceived configuration mode of the App is solely dependent on the configuration mode of the projected component.

Appendix A

There is a Debug object in JavaScript. This object does not contain abilities to determine the configuration mode but merely whether a debugger is attached (and various other debugger type mechanisms). This object also exists in both Debug and Release modes. The solution provided in this article shows one of the easiest ways of accomplishing the feat of determining whether the configuration mode is Debug or Release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Caleb McElrath
Software Developer Magenic Technologies Inc
United States United States
Developer for Magenic Technologies Inc.
 
Caleb began his trek at the age of 16 starting with Turbo Pascal (wanting to expand his horizons from the basics of HTML). Realizing this was not nearly a modern industry standard programming language, he moved on to Visual C++. There he was met with many object-oriented and data structure problems and solutions. His horizons took on the world from there where he explored everything from Ruby, Python, PHP, Flash, to .NET, Java, and jQuery.
 
In Microsoft technologies is where Caleb finds most of his time spent. His days and long nights are filled with the .NET Framework and SQL Server.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 15 Oct 2013
Article Copyright 2013 by Caleb McElrath
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid