Hi there, I’m new to these forums so I hope I ask this well!
I’m working with a complex plugin that uses a WebDialog browser to select our company’s models. (Yes, we will be updating to HtmlDialog very soon )
The WebDialog was getting very slow when populated with lots of models, so we are moving more and more functionality to the dialog JS, and eliminating some Ruby callbacks. One of these was a function that called to Ruby to save the default icon size for our models every time a slider was changed. Now, the JS is handling the resizing, and I moved saving the default value to a set_on_close block on our dialog.
The problem I’m having is that #set_on_close doesn’t seem to fire when you quit SketchUp–only when you explicitly close the dialog. So if you open our dialog in SketchUp, move the slider around, and quit, without explicitly closing the dialog, the default isn’t saved. Our AppObserver is doing great for lots of things, but it doesn’t seem to be able to pull a value out from the dialog during its #onQuit–perhaps because the dialog has already been destroyed at that point.
Any insight on this would be very appreciated! Thanks.
Here’s what’s in our AppObserver:
class XxxxAppObserver < Sketchup::AppObserver
.
.
.
def onQuit
asset_dialog = Core::get_asset_dialog
js_command = 'getIconSize()'
asset_dialog.execute_script(js_command.to_s)
end
Here is the get_asset_dialog method referred to above. It is just fetching the dialog.
def self.get_asset_dialog()
return @asset_dialog
end
class XxxxAppObserver < Sketchup::AppObserver
def onQuit
Core::get_asset_dialog.close
end
I seem to remember that UI::WebDialog close block is bugged
(ie, it never got called on the Mac but did get called on PC),
… but the new UI::HtmlDialog it works on both platforms.
Also there were many versions when the AppObserver#onQuit processing was bugged and the engine did not wait until all #onQuit callbacks were done processing before destroying window objects.
It has since been fixed. Not sure which version, we’d need to check the API Release Notes.
Thanks for the response! It seems like it should work, but I am indeed getting a bug on quitting. I’m testing with SU 2018 on Mac OS, but the release notes say the bug was fixed on SU 2014. Any other ideas?
Just wanted to mention that, because of the past bugginess of onQuit, we decided to go a different route, or risk the problem occurring with people running older versions of SketchUp.
Yes absolutely–actually that was the first thing I tried, but I couldn’t find the event to bind to. It seems like variations of onunload or beforeunload couldn’t capture it, and there is no straightforward onclose available. Any ideas?
I like John’s approach best (because it saves the settings immediately after it changes, and a application freeze and hard close [or BugSplat] could cause the new setting to be lost.)
Absolutely–onChange was the basis of the original method, which I’ve reverted to, and it definitely prevents against problems after crashes and hard closes. We were just trying to reduce the number of calls from the browser to Ruby, but this is still the best option for now. For some reason I couldn’t seem to get onunload (or beforeunload) to work.
Just wanted to mention also how much I appreciated your attention and quick responses to this!