You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a ModulesAddedEvent, ModulesRemovedEvent or ModulesUpdatedEvent
is published, we only care if we have already initialized the menu
structure, and that structure would thus need to be updated.
In the case where no menu structure has yet been generated, we can
ignore the module events. We just need to be careful if module events
come in while we are generating the menu structure. If that happens, we
block (thanks to the event handling methods being synchronized now)
until menus are created, and then update them in response to the event.
Among other benefits, this commit fixes a bug in ImageJ on macOS whereby
scripts in legacy directories (i.e.: in plugins and plugins/Scripts)
were no longer appearing in the menu structure. It was happening because
the following order of events occurred:
1. The DefaultPlatformService initialized the MacOSPlatform.
2. The MacOSPlatform edited app commands (About, Quit and Preferences)
to remove their menu paths, since they are specially handled.
3. The MacOSPlatform fired a ModulesUpdatedEvent to notify others of it.
4. The DefaultMenuService subscribed to the ModulesUpdatedEvent; in
response, its event handler method eagerly initialized the menus.
5. The menu initialization code looped over ModuleService.getModules().
6. The call to getModules() triggered the deferred addition of modules.
7. The deferred addition of modules triggered the DefaultScriptService
to discover scripts in the currently registered script directories.
All of the above happened before the LegacyService initialized, and
therefore the DefaultScriptService did not yet know about the legacy
script directories to include in its script discovery process. Once the
scripts have been discovered, adding the additional script directories
has no effect (i.e., no additional script discovery is triggered).
This commit addresses step (4), changing the DefaultMenuService to do
nothing when modules change in the case of menus still uninitialized.
After this change, the order of events now becomes:
1. The DefaultPlatformService initializes the MacOSPlatform.
2. The MacOSPlatform edits the app command menu paths.
3. The MacOSPlatform fires a ModulesUpdatedEvent to notify others.
4. The DefaultMenuService still receives the ModulesUpdatedEvent, but
does nothing in response.
5. Later, the LegacyService loops over ModuleService.getModules().
6. The call to getModules() triggers the deferred addition of modules.
7. The deferred addition of modules triggers the DefaultScriptService
to discover scripts in the currently registered script directories,
which include the legacy directories added by the LegacyService.
So the problem is solved, at least for now.
There are still questions and potential issues with the design:
- Why does the DefaultPlatformService (at priority normal) initialize
before the LegacyService (at priority normal+1)?
- What if some other service triggers script discovery before the
additional script directories can be registered? There are many
code paths and service calls, such as MenuService and ModuleService
methods, that would do so. Should we make the ScriptService smarter
such that scripts are rescanned when additional script directories
are registered after initial script discovery has taken place?
Doing so would be more robust, but substantially complicate things.
0 commit comments