From 4677eba2754b626a8292e4cf32f8fc229b85495f Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Thu, 23 Jul 2020 11:41:33 +0900 Subject: [PATCH] Update app.js, webloader.js --- app.js | 48 +++++++++++++++++++++++++----------------------- webloader.js | 16 ++++++++++++++++ 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 6b5beb0..da5943f 100644 --- a/app.js +++ b/app.js @@ -33,35 +33,34 @@ // must define main = function(args) {}, which is called once the module is // loaded. -var messages = []; +var exit = function(status) { + if (typeof(WScript) !== "undefined") { + WScript.quit(status); + } +}; var console = { - log: function(msg) { - if (typeof(window) !== 'undefined') { - if (typeof(window.jQuery) !== 'undefined') { - window.jQuery.toast({ - heading: "Information", - text: msg, - icon: "info" - }); - } else { - messages.push(msg); - } - } else if (typeof(WScript) !== 'undefined') { + __messages: [], + __echo: function(msg) { + if (typeof(WScript) !== "undefined") { WScript.echo(msg); } + this.__messages.push(msg); }, - error: function(msg, status) { - this.log(msg); - if (typeof(WScript) !== 'undefined') { - WScript.quit(status); - } + log: function(msg) { + this.__echo(msg); + }, + error: function(msg) { + var msg = "[ERROR] " + msg; + this.__echo(msg); }, info: function(msg) { - this.log(msg); + var msg = "[INFO] " + msg; + this.__echo(msg); }, warn: function(msg) { - this.log(msg); + var msg = "[WARN] " + msg; + this.__echo(msg); } }; @@ -174,13 +173,16 @@ function init_window(name, args, w, h) { if (app.main) { var exitstatus = app.main.call(app, args); if (exitstatus > 0) { - console.error("error", exitstatus); + console.error("error"); + exit(exitstatus); } } else { - console.error("Error, missing main entry point in " + name + ".js", 1); + console.error("Error, missing main entry point in " + name + ".js"); + exit(1); } } else { - console.error("Error, cannot find " + name + ".js", 1); + console.error("Error, cannot find " + name + ".js"); + exit(1); } } diff --git a/webloader.js b/webloader.js index d46ac55..6dd3882 100644 --- a/webloader.js +++ b/webloader.js @@ -7,6 +7,21 @@ */ var FILE = require('lib/file'); +// "override console.__echo()"; +global.console.__echo = function(msg) { + if (typeof(window.jQuery) !== "undefined") { + window.jQuery.toast({ + heading: "Information", + text: msg, + icon: "info" + }); + } else { + alert(msg); + } + + global.console.__messages.push(msg); +}; + // "less than IE 9"; window.enableEventListener = function(obj) {}; if (!window.addEventListener) { @@ -227,6 +242,7 @@ return { jQuery.support.cors = true; self.addScript("app/assets/js/jquery.toast-1.3.2.min.js", function(el) { + var messages = global.console.__messages; if (messages.length > 0) { for (var i in messages) { console.log(messages[i]);