Get value from WebDialog during AppObserver#onQuit


#1

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 :slight_smile:)

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

#2

Try …

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.


#3

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?


#4

which ‘icons’ are you resizing. those contained in the .skp or the images shown in the dialog?

is the plugin deployed on both platforms?

john


#5

The icons are in a plugin dialog. The plugin is deployed on both platforms, but
I’ve only been able to test these changes on mac os so far.


#6

can you upload an image showing the page layout…

and your original slider js code…

changing the page image css should not be creating any bottleneck…

john


#7

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.


#8

One way would be to code your own JS close event that sends the last icon size to the Ruby side for saving.


#9

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?


#10

I just send the ‘onChange’ value to ruby as it happens and update the stored param in write_defaults

john


#11

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.)

But there is also onunload event …

https://www.w3schools.com/jsref/event_onunload.asp


#12

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!


#13

I just checked some of my sliders and for immediate ruby side updates it seems I opted for

oninput='js2ruby(this.value, this.id)'

in another, to limit the ruby responses, I use

<body onMouseOut="updateRubySide();">

john


#14

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.