style: Remove the window icon and add the dock icon on macOS
@@ -13,19 +13,26 @@ import me.coley.recaf.control.gui.GuiController;
import me.coley.recaf.plugin.PluginsManager;
import me.coley.recaf.plugin.api.InternalPlugin;
import me.coley.recaf.plugin.api.WorkspacePlugin;
-import me.coley.recaf.ui.controls.*;
+import me.coley.recaf.ui.controls.ViewportTabs;
+import me.coley.recaf.ui.controls.WorkspaceNavigator;
import me.coley.recaf.ui.controls.popup.UpdateWindow;
import me.coley.recaf.ui.controls.view.ClassViewport;
import me.coley.recaf.ui.controls.view.FileViewport;
+import me.coley.recaf.util.OSUtil;
import me.coley.recaf.util.ThreadUtil;
-import me.coley.recaf.util.self.SelfUpdater;
import me.coley.recaf.util.VMUtil;
+import me.coley.recaf.util.self.SelfUpdater;
import me.coley.recaf.workspace.JavaResource;
import me.coley.recaf.workspace.Workspace;
import org.plugface.core.annotations.Plugin;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.PlatformLoggingMXBean;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import static me.coley.recaf.util.ClasspathUtil.resource;
@@ -61,7 +68,25 @@ public class MainWindow extends Application {
}
private void setup() {
+ if (OSUtil.getOSType() == OSUtil.MAC) {
+ try {
+ /* Why reflection?
+ com.apple.eawt.Application is platform-specific class, that stored in apple-distributed rt.jar
+ and if we use it directly, build must throw an error: "package com.apple.eawt does not exist"
+ */
+ BufferedImage image = ImageIO.read(resource("icons/logo.png"));
+ Class<?> applicationClass = Class.forName("com.apple.eawt.Application");
+ Object application = applicationClass.getMethod("getApplication").invoke(null);
+ Method dockIconSetter = applicationClass.getMethod("setDockIconImage", java.awt.Image.class);
+ dockIconSetter.invoke(application, image);
+ } catch (IOException | ClassNotFoundException | NoSuchMethodException
+ | IllegalAccessException | InvocationTargetException ignored) {
+ // Just ignore if we can't load dock image, it's not critical.
+ }
+ } else {
stage.getIcons().add(new Image(resource("icons/logo.png")));
+ }
+
stage.setTitle("Recaf");
menubar = new MainMenu(controller);
root = new BorderPane();
