Added support for (attempting to) suppress alerts that are meaningless if the user has aborted a machine by exiting the page before it was done loading

This commit is contained in:
Jeff Parsons 2017-06-22 15:53:34 -07:00 • committed by Jeff Parsons
commit 1ce03810d3
32 changed files with 1827 additions and 1591 deletions

View file

@ -2493,6 +2493,7 @@ class Component {
busy: false,
busyCancel: false,
powered: false,
unloading: false,
error: false
};
@ -3211,7 +3212,8 @@ class Component {
* @this {Component}
* @return {string}
*/
toString() {
toString()
{
return (this.name? this.name : (this.id || this.type));
}
@ -3221,7 +3223,8 @@ class Component {
* @this {Component}
* @return {number} unique machine number
*/
getMachineNum() {
getMachineNum()
{
var nMachine = 1;
if (this.idMachine) {
var aDigits = this.idMachine.match(/\d+/);
@ -3243,7 +3246,8 @@ class Component {
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
setBinding(sHTMLType, sBinding, control, sValue) {
setBinding(sHTMLType, sBinding, control, sValue)
{
switch (sBinding) {
case "clear":
if (!this.bindings[sBinding]) {
@ -3316,7 +3320,8 @@ class Component {
* @param {string} [s] is the message text
* @param {string} [type] is the message type
*/
log(s, type) {
log(s, type)
{
if (!COMPILED) {
Component.log(s, type || this.id || this.type);
}
@ -3337,7 +3342,8 @@ class Component {
* @param {boolean|number} f is the expression asserted to be true
* @param {string} [s] is a description of the assertion to be displayed or logged on failure
*/
assert(f, s) {
assert(f, s)
{
if (DEBUG) {
if (!f) {
s = "assertion failure in " + (this.id || this.type) + (s? ": " + s : "");
@ -3384,7 +3390,8 @@ class Component {
* @param {string} [type] is the message type
* @param {string} [id] is the caller's ID, if any
*/
println(s, type, id) {
println(s, type, id)
{
Component.println(s, type, id || this.id);
}
@ -3396,7 +3403,8 @@ class Component {
*
* @param {string} s is the message text
*/
status(s) {
status(s)
{
this.println(this.idComponent + ": " + s);
}
@ -3412,7 +3420,18 @@ class Component {
* @param {boolean} [fPrintOnly]
* @param {string} [id] is the caller's ID, if any
*/
notice(s, fPrintOnly, id) {
notice(s, fPrintOnly, id)
{
if (!fPrintOnly) {
/*
* See if the associated computer, if any, is "unloading"....
*/
var computer = Component.getComponentByType("Computer", this.id);
if (computer && computer.flags.unloading) {
console.log("ignoring notice during unload: " + s);
return;
}
}
Component.notice(s, fPrintOnly, id || this.type);
}
@ -3424,7 +3443,8 @@ class Component {
* @this {Component}
* @param {string} s describes a fatal error condition
*/
setError(s) {
setError(s)
{
this.flags.error = true;
this.notice(s); // TODO: Any cases where we should still prefix this string with "Fatal error: "?
}
@ -3448,7 +3468,8 @@ class Component {
* @this {Component}
* @return {boolean} true if a fatal error condition exists, false if not
*/
isError() {
isError()
{
if (this.flags.error) {
this.println(this.toString() + " error");
return true;
@ -3469,7 +3490,8 @@ class Component {
* @param {function()} [fnReady]
* @return {boolean} true if the component is in a "ready" state, false if not
*/
isReady(fnReady) {
isReady(fnReady)
{
if (fnReady) {
if (this.flags.ready) {
fnReady();
@ -3489,7 +3511,8 @@ class Component {
* @this {Component}
* @param {boolean} [fReady] is assumed to indicate "ready" unless EXPLICITLY set to false
*/
setReady(fReady) {
setReady(fReady)
{
if (!this.flags.error) {
this.flags.ready = (fReady !== false);
if (this.flags.ready) {
@ -3510,7 +3533,8 @@ class Component {
* @param {boolean} [fCancel] is set to true to cancel a "busy" state
* @return {boolean} true if "busy", false if not
*/
isBusy(fCancel) {
isBusy(fCancel)
{
if (this.flags.busy) {
if (fCancel) {
this.flags.busyCancel = true;
@ -3530,7 +3554,8 @@ class Component {
* @param {boolean} fBusy
* @return {boolean}
*/
setBusy(fBusy) {
setBusy(fBusy)
{
if (this.flags.busyCancel) {
this.flags.busy = false;
this.flags.busyCancel = false;
@ -3552,7 +3577,8 @@ class Component {
* @param {boolean} [fRepower] is true if this is "repower" notification
* @return {boolean} true if successful, false if failure
*/
powerUp(data, fRepower) {
powerUp(data, fRepower)
{
this.flags.powered = true;
return true;
}
@ -3565,7 +3591,8 @@ class Component {
* @param {boolean} [fShutdown]
* @return {Object|boolean} component state if fSave; otherwise, true if successful, false if failure
*/
powerDown(fSave, fShutdown) {
powerDown(fSave, fShutdown)
{
if (fShutdown) this.flags.powered = false;
return true;
}
@ -3579,7 +3606,8 @@ class Component {
* @param {number} [bitsMessage] is zero or more MESSAGE_* category flag(s)
* @return {boolean} true if all specified message enabled, false if not
*/
messageEnabled(bitsMessage) {
messageEnabled(bitsMessage)
{
if (DEBUGGER && this.dbg) {
if (this === this.dbg) {
bitsMessage |= 0;
@ -3603,7 +3631,8 @@ class Component {
* @param {number|boolean} [bitsMessage] is zero or more MESSAGE_* category flag(s)
* @param {boolean} [fAddress] is true to display the current address
*/
printMessage(sMessage, bitsMessage, fAddress) {
printMessage(sMessage, bitsMessage, fAddress)
{
if (DEBUGGER && this.dbg) {
if (bitsMessage === true || this.messageEnabled(bitsMessage | 0)) {
this.dbg.message(sMessage, fAddress);
@ -3625,7 +3654,8 @@ class Component {
* @param {number|null} [bIn] is the input value, if known, on an input operation
* @param {number|boolean} [bitsMessage] is zero or more MESSAGE_* category flag(s)
*/
printMessageIO(port, bOut, addrFrom, name, bIn, bitsMessage) {
printMessageIO(port, bOut, addrFrom, name, bIn, bitsMessage)
{
if (DEBUGGER && this.dbg) {
if (bitsMessage === true) {
bitsMessage = 0;
@ -24201,6 +24231,8 @@ class Computer8080 extends Component {
var computer = /** @type {Computer8080} */ (Component.getComponentByType("Computer", parmsComputer['id']));
if (computer) {
computer.flags.unloading = false;
if (DEBUG && computer.messageEnabled()) {
computer.printMessage("onShow(" + computer.fInitialized + "," + computer.flags.powered + ")");
}
@ -24255,6 +24287,11 @@ class Computer8080 extends Component {
var computer = /** @type {Computer8080} */ (Component.getComponentByType("Computer", parmsComputer['id']));
if (computer) {
/*
* Added a new flag that Component functions (eg, notice()) should check before alerting the user.
*/
computer.flags.unloading = true;
if (DEBUG && computer.messageEnabled()) {
computer.printMessage("onExit(" + computer.flags.powered + ")");
}