Skip to content

Commit

Permalink
Don't crash when Application.addPreferencesMenuItem() does not exist …
Browse files Browse the repository at this point in the history
…on some newer OSX versions (#42)
  • Loading branch information
aleksandarmilicevic authored Apr 8, 2018
1 parent d34359b commit 2fc2ba3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,21 @@ public void handleQuit(ApplicationEvent arg0) {
}
});
}

/**
* Delegates the call to {@link #addMenus(SimpleGUI)} catching all errors. If no
* error is caught, <code>null</code> is returned; otherwise, the caught {@link Error}
* is returned.
*
* Use this method to guard from runtime exceptions thrown when running on newer versions
* of OSX that do not support adding OSX-specific menus from Java applications.
*/
public Error tryAddMenus(SimpleGUI simpleGUI) {
try {
addMenus(simpleGUI);
return null;
} catch (Error e) {
return e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ private SimpleGUI(final String[] args) {
}
if (Util.onMac()) {
macUtil = new MacUtil();
macUtil.addMenus(this);
macUtil.tryAddMenus(this);
}

doLookAndFeel();
Expand Down

0 comments on commit 2fc2ba3

Please sign in to comment.