Skip to content

Commit

Permalink
[startup] fix sonoma brew openjdk crash
Browse files Browse the repository at this point in the history
  • Loading branch information
jerowang committed Nov 12, 2023
1 parent fcfeffb commit 966ca7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/cburch/logisim/gui/start/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,13 @@ public static Startup parseArgs(String[] args) {
shallClearPreferences = cmd.hasOption(ARG_CLEAR_PREFS_LONG);
}
if (!isTty) {
// we're using the GUI: Set up the Look&Feel to match the platform
System.setProperty("apple.laf.useScreenMenuBar", "true");
// Check if using Sonoma and Homebrew OpenJDK
// Currently, Homebrew OpenJDK on Sonoma crashes on launch
// https://github.com/Homebrew/homebrew-core/issues/150824
if (MacCompatibility.isSwingUsingScreenMenuBar()) {
// we're using the GUI: Set up the Look&Feel to match the platform
System.setProperty("apple.laf.useScreenMenuBar", "true");
}
// Initialize graphics acceleration if appropriate
AppPreferences.handleGraphicsAcceleration();
}
Expand Down Expand Up @@ -1068,5 +1073,4 @@ public void eventDispatched(AWTEvent event) {
}
}
}

} // Startup
11 changes: 9 additions & 2 deletions src/main/java/com/cburch/logisim/util/MacCompatibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public final class MacCompatibility {

private static final boolean runningOnMac =
System.getProperty("os.name").toLowerCase().contains("mac");
private static boolean usingScreenMenuBar = runningOnMac;

private static final boolean runningOnMacAndSonomaHomebrewOpenJDK =
runningOnMac
&& System.getProperty("os.version").startsWith("14")
&& System.getProperty("java.vendor").toLowerCase().startsWith("homebrew")
&& System.getProperty("java.runtime.name").toLowerCase().startsWith("openjdk");

private static boolean usingScreenMenuBar = runningOnMac && !runningOnMacAndSonomaHomebrewOpenJDK;

private MacCompatibility() {
throw new IllegalStateException("Utility class. No instantiation allowed.");
Expand Down Expand Up @@ -45,7 +52,7 @@ public static boolean isSwingUsingScreenMenuBar() {
public static void setFramelessJMenuBar(JMenuBar menubar) {
try {
// DHH This method allows the app to run without a frame on the Mac. The menu will still show.
if (runningOnMac) {
if (runningOnMac && !runningOnMacAndSonomaHomebrewOpenJDK) {
Desktop.getDesktop().setDefaultMenuBar(menubar);
}
} catch (Exception t) {
Expand Down

0 comments on commit 966ca7a

Please sign in to comment.