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
          @controller.close_dialog
}

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 …