Skip to content

Commit

Permalink
Plugins can now control the loading screen and read static config par…
Browse files Browse the repository at this point in the history
…ams from app.json
  • Loading branch information
Dovyski committed Sep 22, 2017
1 parent 64e2394 commit 9f5dab2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
/plugins/ide-web/config.local.php
/plugins/asset-finder/config.local.php
/plugins/ide-web/api/config.local.php
/app.json
3 changes: 2 additions & 1 deletion app.sample.json
@@ -1,5 +1,6 @@
{
"codebot": {
"bootstrap": "./js/web/codebot.bootstrap.web.js"
"bootstrap": "./js/web/codebot.bootstrap.web.js",
"keepLoadingScreen": false
}
}
23 changes: 13 additions & 10 deletions js/codebot.bootstrap.js
Expand Up @@ -30,15 +30,23 @@
*/

function codebotBootstrap(theAppConfig) {
var aIsNodeWebkit, aIsChromeApp;
var aIsNodeWebkit, aIsChromeApp, aCodebotConfig;

console.log('CODEBOT [bootstrap] App configuration file (app.json):', theAppConfig);
CODEBOT.STATIC_APP_CONFIG = theAppConfig;

if(theAppConfig && theAppConfig.bootstrap) {
if(CODEBOT.STATIC_APP_CONFIG.codebot) {
aCodebotConfig = CODEBOT.STATIC_APP_CONFIG.codebot;

} else {
console.error('Codebot app.json file has no "codebot" property. E.g. {"codebot": {...}}.');
}

if(CODEBOT.STATIC_APP_CONFIG && ('bootstrap' in aCodebotConfig)) {
// App config file tells us to use a custom-made bootstrapper.
// So be it!
console.log('CODEBOT [bootstrap] Firing up custom bootstrapper: ' + theAppConfig.bootstrap);
$('body').append('<script type="text/javascript" src="'+theAppConfig.bootstrap+'"></script>');
console.log('CODEBOT [bootstrap] Firing up custom bootstrapper: ' + aCodebotConfig.bootstrap);
$('body').append('<script type="text/javascript" src="' + aCodebotConfig.bootstrap + '"></script>');

} else {
aIsNodeWebkit = 'require' in window;
Expand All @@ -65,12 +73,7 @@ function codebotBootstrap(theAppConfig) {
$(function() {
$.getJSON('./app.json')
.done(function(theData) {
if(theData.codebot) {
codebotBootstrap(theData.codebot);

} else {
console.error('Codebot app.json file has no "codebot" property. E.g. {"codebot": {...}}.');
}
codebotBootstrap(theData);
})
.fail(function(theJqxhr, theTextStatus, theError) {
if(theJqxhr.status == 404) {
Expand Down
32 changes: 29 additions & 3 deletions js/codebot.js
Expand Up @@ -32,6 +32,22 @@ var CODEBOT = new function() {
var mPlugins = null;
var mSelf;

// Contain configuration parameters loaded from the app.json file. This file
// is loaded before everything and it can guide how Codebot should init and
// bootstrap itself.
this.STATIC_APP_CONFIG = {};

/**
* Get config params in the "codebot" section of the content loaded with the app.json file.
*
* @param {string} thePropertyName Name of the config property being read.
* @param {[type]} theDefaultValue If the informed property does not exist in the config content, return this value instead.
*/
this.config = function(thePropertyName, theDefaultValue) {
var aEntries = this.STATIC_APP_CONFIG && this.STATIC_APP_CONFIG['codebot'] ? this.STATIC_APP_CONFIG['codebot'] : null;
return (thePropertyName in aEntries) ? aEntries[thePropertyName] : theDefaultValue;
};

var handleError = function(theMsg, theUrl, theLineNumber) {
// Show some nice information to the user
mUI.toast(Codebot.UI.TOAST_ERROR, '<h2>An error just occured</h2><p>' + theMsg + '</p>');
Expand Down Expand Up @@ -74,6 +90,16 @@ var CODEBOT = new function() {
mIO.init();
};

this.setLoadingScreenVisibility = function(theStatus) {
if(theStatus) {
$('#loading').fadeIn();
$('#wrapper').hide();
} else {
$('#loading').fadeOut();
$('#wrapper').show();
}
};

this.init = function(theIODriver) {
console.log('CODEBOT [core] Initializing...');

Expand Down Expand Up @@ -106,9 +132,9 @@ var CODEBOT = new function() {
console.log('CODEBOT [core] Done, ready to rock!');
mSignals.ready.dispatch();

// Remove the loading icon
$('#loading').fadeOut();
$('#wrapper').show();
if(!mSelf.config('keepLoadingScreen', false)) {
mSelf.setLoadingScreenVisibility(false);
}

mSelf.showDebugger();
});
Expand Down
3 changes: 3 additions & 0 deletions plugins/cc.codebot.ide.web.js
Expand Up @@ -229,6 +229,9 @@ IdeWeb.Plugin = function() {
mContext.ui.addButton('newProject', {icon: '<i class="fa fa-desktop"></i>', panel: IdeWeb.Panel.CreateProject });
mContext.ui.addButton('openProject', {icon: '<i class="fa fa-hdd-o"></i>', panel: IdeWeb.Panel.OpenProject });

// Remove any loading indications
CODEBOT.setLoadingScreenVisibility(false);

// Schedule the rest of the UI initialization to happen only
// after a project has been opened.
mContext.signals.projectOpened.add(initUIAfterProjectOpened);
Expand Down

0 comments on commit 9f5dab2

Please sign in to comment.