Repository navigation
Replace OSXAdapter with java.awt.Desktop handlers - #557
tonygermano wants to merge 2 commits into
Conversation
OSXAdapter is Apple's sample adapter, carried under Apple's own license header, that installs the macOS About and Quit handlers by reflection against com.apple.eawt.Application. Its pre-Java-9 path implements com.apple.eawt.ApplicationListener, which JEP 272 removed, and its Java 9+ path only works because the client launcher passes --add-opens java.desktop/com.apple.eawt. Both reach the same java.awt.desktop handlers that java.awt.Desktop has exposed publicly since Java 9. Register the two handlers through Desktop directly, guarded by isSupported so the IS_OS_MAC check is no longer needed; Linux and Windows report both actions unsupported and keep their Help menu and window close behavior. The quit handler keeps the old contract: Frame.logout(true) does not call System.exit, so it calls performQuit when quitMac returns true and cancelQuit otherwise. Delete OSXAdapter.java and drop the --add-opens for com.apple.eawt, which existed only for it, from the JNLP template, its test, and the devClient task. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Tony Germano <tony@germano.name>
openURL located java.awt.Desktop by reflection and, when that failed, fell back to com.apple.eio.FileManager on macOS or rundll32 on Windows. Java 17 is the baseline, so Desktop is always present, and on macOS and Windows it is always supported on a desktop JVM, so neither branch could be reached. Call Desktop.browse directly and keep only the Unix browser search, which still matters on Linux desktops without the GNOME libraries that Desktop needs. Drop the --add-opens for com.apple.eio from the JNLP template, its test, and the devClient task. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Tony Germano <tony@germano.name>
38124c6 to
3b73238
Compare
| String browser = null; | ||
| for (String b : browsers) | ||
| if (browser == null | ||
| && Runtime.getRuntime().exec(new String[] { "which", b }).getInputStream().read() != -1) | ||
| Runtime.getRuntime().exec(new String[] { browser = b, url }); | ||
| if (browser == null) | ||
| throw new Exception(Arrays.toString(browsers)); |
There was a problem hiding this comment.
Can we just go for the exec? This seems like it is a TOCTOU. Presumably the exec of the browser will fail sufficiently to avoid which - which is not required to be present as a binary in the first place - it's normally a shell built-in.
There was a problem hiding this comment.
That was preexisting code that came from the upsteam launcher. It's only showing up here because of a whitespace change.
It's iterating through an array of options, so we'd need to wrap it in a new try/catch to ignore all of the exceptions until it exhausts the list. I'm not sure what we would gain since this works in all Linux environments I've tested it in.
There was a problem hiding this comment.
If you review only commit 2 and hide whitespace changes, this change is just a delete and directly importing Desktop instead of finding it by reflection.
Summary
OSXAdapteris Apple's sample adapter, under Apple's own license header (relates to #472), that installs the macOS About and Quit handlers by reflection againstcom.apple.eawt.Application. Its pre-Java-9 path implementscom.apple.eawt.ApplicationListener, which JEP 272 removed; its Java 9+ path only works because the launcher passes--add-opens java.desktop/com.apple.eawt. Both end up at the samejava.awt.desktophandlers thatjava.awt.Desktophas exposed publicly since Java 9, so the reflection, the add-opens, and the Apple-licensed file can all go. #544 drew attention to the class while converting its stderr prints.OSXAdapter.javaand registers the two handlers withjava.awt.Desktop.setAboutHandler/setQuitHandler, guarded byisSupportedinstead ofIS_OS_MAC. Linux and Windows report both actions unsupported, so nothing changes there. The quit handler keeps the old contract:Frame.logout(true)doesn't callSystem.exit, so it callsperformQuit()whenquitMac()returns true andcancelQuit()otherwise.BareBonesBrowserLaunch.openURLto callDesktop.browsedirectly and drops itscom.apple.eio.FileManagerandrundll32fallbacks, which can't be reached on Java 17 sinceDesktopis always supported on macOS and Windows. The Unix browser search stays for Linux desktops without the GNOME librariesDesktopneeds.--add-opensforcom.apple.eawtandcom.apple.eiofromserver/mirth-client.jnlp,WebStartServletTest, and thedevClientGradle task. Nothing else referenced those packages.Testing
I verified that the browser launching still works from non-GNOME linux.
This needs a manual check on macOS, which I can't do
That is the behavior the old Java 9+ path provided, so no change is expected.
Claude checked:
./gradlew clean build: all 797 tests pass.com.appleanywhere in the repository.🤖 Drafted with Claude Code