Click here to Skip to main content
15,886,873 members
Articles / Programming Languages / Javascript
Technical Blog

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
15 Oct 2013CPOL2 min read 12.5K   1  
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)


Written By
Software Developer
United States United States
Caleb is a software development consultant specialized in creating web solutions for critical business problems. He has a passion for front-end development and helping other developers find their role. He enjoys making development easier to do, easier to learn and easier to improve upon. His days are pleasantly filled with TypeScript, HTML5 and C#.

Comments and Discussions

 
-- There are no messages in this forum --