# Get value from WebDialog during AppObserver#onQuit

**URL:** <https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471>\
**Category:** Ruby API\
**Created:** [March 5, 2018, 4:55pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471 "2018-03-05T16:55:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![fleawig](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fleawig/32/164115_2.png) [@fleawig](https://forums.sketchup.com/u/fleawig)\
**Post date:** [March 5, 2018, 4:55pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/1 "2018-03-05T16:55:27Z")

</div>

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:

```auto
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.

```auto
def self.get_asset_dialog()
  return @asset_dialog
end

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 5, 2018, 10:18pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/2 "2018-03-05T22:18:32Z")

</div>

> [@fleawig](#):
>
> ```ruby
> class XxxxAppObserver &lt; Sketchup::AppObserver
> 
> def onQuit
> asset_dialog = Core::get_asset_dialog
> js_command = 'getIconSize()'
> asset_dialog.execute_script(js_command.to_s)
> end
> 
> ```

Try …

```ruby
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](http://ruby.sketchup.com/file.ReleaseNotes.html).

---

<div class="post-metadata">

**Author:** ![fleawig](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fleawig/32/164115_2.png) [@fleawig](https://forums.sketchup.com/u/fleawig)\
**Post date:** [March 6, 2018, 9:17am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/3 "2018-03-06T09:17:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 6, 2018, 10:03am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/4 "2018-03-06T10:03:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fleawig](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fleawig/32/164115_2.png) [@fleawig](https://forums.sketchup.com/u/fleawig)\
**Post date:** [March 6, 2018, 10:10am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/5 "2018-03-06T10:10:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 6, 2018, 10:33am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/6 "2018-03-06T10:33:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fleawig](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fleawig/32/164115_2.png) [@fleawig](https://forums.sketchup.com/u/fleawig)\
**Post date:** [March 6, 2018, 5:33pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/7 "2018-03-06T17:33:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 6, 2018, 8:54pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/8 "2018-03-06T20:54:32Z")

</div>

> [@fleawig](#):
>
> … we decided to go a different route, …

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

---

<div class="post-metadata">

**Author:** ![fleawig](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fleawig/32/164115_2.png) [@fleawig](https://forums.sketchup.com/u/fleawig)\
**Post date:** [March 7, 2018, 12:31pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/9 "2018-03-07T12:31:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 7, 2018, 10:39pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/10 "2018-03-07T22:39:12Z")

</div>

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

john

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 7, 2018, 11:57pm UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/11 "2018-03-07T23:57:20Z")

</div>

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 …

> **[onunload Event](https://www.w3schools.com/jsref/event_onunload.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

---

<div class="post-metadata">

**Author:** ![fleawig](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/fleawig/32/164115_2.png) [@fleawig](https://forums.sketchup.com/u/fleawig)\
**Post date:** [March 8, 2018, 9:53am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/12 "2018-03-08T09:53:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 8, 2018, 11:12am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/13 "2018-03-08T11:12:50Z")

</div>

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

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

```

in another, to limit the ruby responses, I use

```nohighlight
<body onMouseOut="updateRubySide();">

```

john

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [June 8, 2018, 3:12am UTC](https://forums.sketchup.com/t/get-value-from-webdialog-during-appobserver-onquit/63471/14 "2018-06-08T03:12:55Z")

</div>

Closed on June 8, 2018, 3:12am UTC

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