Skip to content

Commit

Permalink
[fix] Split out Mac OS X Dock icon functionality
Browse files Browse the repository at this point in the history
That part still works on Sequoia 15.1.1 (24B91), despite https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-97C1D0BB-D5D3-4CAD-B17D-03A87A0AAF3B ; while the menu part doesn't anymore.
  • Loading branch information
Dominique Quatravaux authored and hbitteur committed Dec 31, 2024
1 parent c726ea5 commit f603e7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
37 changes: 24 additions & 13 deletions app/src/main/java/org/audiveris/omr/ui/MacApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,31 +203,42 @@ public static boolean setupMacMenus ()
Method addListener = appClass.getMethod("addApplicationListener", listenerClass);
addListener.invoke(app, listenerProxy);

// display audiveris icon in the dock instead of default java one
Method getApplication = appClass.getMethod("getApplication");
Object application = getApplication.invoke(app);

URI uri = UriUtil.toURI(WellKnowns.RES_URI, "icon-256.png");
Image icon = new ImageIcon(uri.toURL()).getImage();

Method setDockImage = application.getClass().getMethod("setDockIconImage", Image.class);
setDockImage.invoke(application, icon);

return true;
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException
| InstantiationException | NoSuchMethodException | SecurityException
| InvocationTargetException | MalformedURLException ex) {
logger.warn("Unable to setup Mac OS X GUI integration", ex);
| InvocationTargetException ex) {
logger.warn("Unable to setup Mac OS X menu integration", ex);

return false;
}
}

public static boolean setupMacMenus ()
public static boolean setupMacDockIcon ()
{
if (!WellKnowns.MAC_OS_X) {
return false;
}

try {
Class<?> appClass = getMacAppClass();
Object app = getMacAppInstance();

Method getApplication = appClass.getMethod("getApplication");
Object application = getApplication.invoke(app);

URI uri = UriUtil.toURI(WellKnowns.RES_URI, "icon-256.png");
Image icon = new ImageIcon(uri.toURL()).getImage();

Method setDockImage = application.getClass().getMethod("setDockIconImage", Image.class);
setDockImage.invoke(application, icon);

return true;
} catch (NoSuchMethodException | InstantiationException |
ClassNotFoundException | IllegalAccessException |
InvocationTargetException | MalformedURLException ex) {
logger.warn("Unable to setup Mac OS X dock icon", ex);
return false;
}
}

static Class<?> getMacAppClass ()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/audiveris/omr/ui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ private void defineMenus ()
// Mac Application menu
if (WellKnowns.MAC_OS_X) {
MacApplication.setupMacMenus();
MacApplication.setupMacDockIcon();
}
}

Expand Down

0 comments on commit f603e7d

Please sign in to comment.