/**
 * Copyright (C) 2015 Laverna project Authors.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
/*global define, Modernizr*/
define([
    'underscore',
    'jquery',
    'backbone',
    'backbone.radio',
    'devicejs',
    'regions/regionManager',
    'marionette'
], function(_, $, Backbone, Radio, Device) {
    'use strict';

    var App = new Backbone.Marionette.Application(),
        env = {
            isWebkit : ('WebkitAppearance' in document.documentElement.style),
            isMobile : (Device.mobile() === true || Device.tablet() === true),
            platform : 'browser'
        };

    env.useWorkers = (Modernizr.webworkers && window.location.protocol !== 'file:' && !env.isWebkit);

    if (env.isMobile) {
        env.platform = 'mobile';
    }
    else if (window.requireNode) {
        env.platform = 'electron';
    }

    // Customize underscore template
    _.templateSettings = {
        interpolate : /\{\{(.+?)\}\}/g,
        evaluate    : /<%([\s\S]+?)%>/g
    };

    // Start a module
    App.startSubApp = function(appName, args) {
        var currentApp = appName ? App.module(appName) : null;
        if (App.currentApp === currentApp) { return; }

        // Stop previous app if current app is not modal
        if (App.currentApp && (!currentApp.options.modal || env.isMobile)) {
            App.currentApp.stop();
        }

        App.currentApp = currentApp;
        if (currentApp) {
            App.channel.trigger('app:module', appName);
            currentApp.start(args);
        }
    };

    // Returns current app
    Radio.reply('global', 'app:current', function() {
        return App.currentApp;
    });

    // @ToMove somewhere else
    App.channel.on('app:start', function() {
        $('.-loading').removeClass('-loading');
    });

    Radio.reply('global', 'device', function(method) {
        return Device[method]();
    });

    Radio.reply('global', 'platform', function() {
        return env.platform;
    });

    Radio.reply('global', 'use:webworkers', function() {
        return env.useWorkers;
    });

    App.on('before:start', function() {
        Radio.trigger('global', 'app:init');
    });

    App.on('start', function() {
        console.timeEnd('App');
        Backbone.history.start({pushState: false});
        Radio.trigger('global', 'app:start');
    });

    return App;
});

@@ -746,16 +746,67 @@
 browser'
+,%0A            ua       : window.navigator.userAgent
 %0A       
@@ -909,24 +909,110 @@
 isWebkit);%0A%0A
+    if (/(palemoon%7Csailfish)/i.test(env.ua)) %7B%0A        env.useWorkers = false;%0A    %7D%0A%0A
     if (env.

Disable WebWorkers in Pale Moon and Sailfish