drummerSupport icon indicating copy to clipboard operation
drummerSupport copied to clipboard

The issue with dialog.alert

Open scripting opened this issue 4 years ago • 0 comments

Never mind!

I fixed it. The glue was still wrong. Here's the new glue that works.

alert: function (s) { //7/29/21 by DW
	return new Promise (function (resolve, reject) {
		alertDialog (s, function () {
			resolve (true);
			})
		});
	},

I still don't fully understand how this works. :oy:

I'm leaving the narrative below because there's actually some useful info in it. ;-)

The narrative

I've rewritten alertDialog this morning so that it can be called from its callback. This was the first problem I uncovered last night after @allenwb reported the problem with two consecutive calls to it.

So now if I do this from within the app, it now works -- it did not work before:

alertDialog ("hello", function () {
   alertDialog ("goodbye");
   }

It was using globals, it was something I wrote very early, before I had included closures in my work. I rewrote it as a completely self-contained thing, no globals.

I also rewrote the glue for dialog.alert to follow the pattern of dialog.confirm, which seems to work quite well.

if (dialog.confirm ("Eat my shorts?")) {
   dialog.alert ("¡Ay, caramba!");
   }

Here's the glue for dialog.alert.

alert: function (s) { //7/29/21 by DW
	return new Promise (function (resolve, reject) {
		alertDialog (s, resolve);
		});
	},

But if I run Allen's deadly demo:

dialog.alert ("one");
dialog.alert ("two");

I just get the first dialog, not the second.

Next, I ran a test to see if any code would run after a dialog.alert call.

dialog.alert ("hello");
file.writeWholeFile ("test.txt", "eat my shorts");

The file does not exist after running this.

However if I switch the order, the file test.txt does exist and contains the correct text.

So it seems pretty likely that my glue code is wrong! It isn't a weird interaction between two calls to dialog.alert. I think that's basically good news.

In any case, I'm glad to have documented the inner workings of the "magic" for my friend Allen. :smile:

scripting avatar Jul 30 '21 14:07 scripting