api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

AppObserver.onOpenModel is called wrongly when opening multiple documents at once (MacOS)

Open SimonWeinbergerEnscape opened this issue 2 years ago • 2 comments

Repro steps:

  1. Start SketchUp 2023 (or earlier version) on MacOS
  2. Go to state with exactly one open document (document A)
  3. Attach simple AppObserver
class MyAppObserver < Sketchup::AppObserver
  def onOpenModel(model)
    puts "onOpenModel: #{model}"
  end
end

Sketchup.add_observer(MyAppObserver.new)
  1. Click Menu: "File" -> "Open..."
  2. Select multiple skp files by holding the command key, let's call them B1, B2, ... Bn
  3. Click button "Open"
  4. Observe the observer output

Expected behavior:

onOpenModel: B1
onOpenModel: B2
...
onOpenModel: Bn

Actual behavior:

onOpenModel: A
onOpenModel: A
...
onOpenModel: A (n-1 times in total)
onOpenModel: Bn

It is possible to detect onOpenModel calls with document A as being a duplicate, but there is no way to retrieve a Model instance before the user switches to that document.

If you replace step 2 with "Go to state without any open documents" the actual behavior changes slightly, but is still wrong:

onOpenModel: nil
onOpenModel: nil
...
onOpenModel. nil (n-1 times in total)
onOpenModel: Bn

Note: The behavior is correct when opening multiple documents during initial startup (Click button "Open file..." on welcome splash screen, select multiple skp files, click button "Open") in combination with AppObserver.expectsStartupModelNotifications returning true.

High level use case: Our plugin (Enscape) wants to keep track of all currently opened documents to show these documents and their content in our own UI elements.

SimonWeinbergerEnscape avatar Aug 01 '23 11:08 SimonWeinbergerEnscape

When models open on the Mac, do they become the active model for a moment before the next model is opened ?

Ie, I'm am wondering if the Mac-only AppObserver#onActivateModel gets called in these scenarios?

@SimonWeinbergerEnscape Our plugin (Enscape) wants to keep track of all currently opened documents to show these documents and their content in our own UI elements.

FYI

We had in the past, requested the exposure of the application's open model collection, but were denied. The reason was that the APIs are "thinly wrapped" around core functions which are all written to assume operation upon the active model object.

It was thought that exposing non-active model objects would encourage or allow function calls to be made upon objects not in the active model which would cause instability or crashes.

DanRathbun avatar Aug 01 '23 17:08 DanRathbun

Logged as: SKEXT-3815

sketchup[bot] avatar Aug 07 '23 06:08 sketchup[bot]