Update app.js, webloader.js

This commit is contained in:
Namhyeon Go 2020-07-23 11:41:33 +09:00
parent bb996f41a5
commit 4677eba275
2 changed files with 41 additions and 23 deletions

54
app.js
View File

@ -33,35 +33,34 @@
// must define main = function(args) {}, which is called once the module is
// loaded.
var messages = [];
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') {
WScript.echo(msg);
}
},
error: function(msg, status) {
this.log(msg);
if (typeof(WScript) !== 'undefined') {
var exit = function(status) {
if (typeof(WScript) !== "undefined") {
WScript.quit(status);
}
};
var console = {
__messages: [],
__echo: function(msg) {
if (typeof(WScript) !== "undefined") {
WScript.echo(msg);
}
this.__messages.push(msg);
},
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);
}
}

View File

@ -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]);