HTMLDialog #set_on_closed closes dialog before running callback

When writing HTMLDialog interfaces, I use #get_size and #get_position from inside of #set_on_closed, so that I can restore the position and size of the dialog when it’s next opened:

@dialog.set_on_closed {
          puts "dialog #{@dialog} closed with position #{@dialog.get_position} and size #{@dialog.get_size}"
          @position = @dialog.get_position
          @size = @dialog.get_size
          @dialog = nil

I am on Windows 10, and I have confirmed that this works fine on Sketchup 21.1.322, but on Sketchup 22.0.354, I get nil for both, and the console reports:

saved position as , size as 

As the documentation says, “A nil value is returned if the HtmlDialog is not visible.” So my guess is that something changed to make the dialog close before the callback is run, which is unfortunate.

Both WebDialog and HtmlDialog are supposed to automatically save the size and position, … and then restore it next time it is opened. This is what the :preferences_key argument is for in the constructor call.

There is an open issue in the official tracker. Is your issue related ?

1 Like

No, I think that’s a separate issue, where the dialog is open at the time that the user exits Sketchup, and the on_close callback is not called. In my case, the callback does run, but after the HtmlDialog is closed.

Is it okay to go ahead and log the issue on the Github page, or is it preferred to raise them here first?

It is always OK either way. What many coders do is insert a link back to a forum topic in the GitHub report, if they discussed it here first. Also always good to post a link to the GitHub issue report in such forum threads.

Also, Thomas has said …

However, the documentation for the UI::HtmlDialog class indicates that developers should be using the #set_can_close callback to run a block of code before the dialog window closes. This callback must return a boolean value to tell the SketchUp internals whether to proceed with closing the CEF window.

The documentation is quite clear that the #set_on_closed callback is … “used to attach a block that will be executed when a dialog is already in the process of closing” …

So, despite that it worked differently in older versions, it still does not violate the API contract per the documentation. Some other fix likely has made the CEF windows close quicker than it did previously.

( Comment echoed to GitHub Issue #791 )