Skip to content

Commit

Permalink
Fix mac OS dock icon display issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Jul 30, 2018
1 parent 9b8072b commit c06d069
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions main/src/main/java/org/pdown/gui/DownApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.lang.reflect.Method;
import java.net.URL;
import javafx.application.Platform;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -44,12 +45,28 @@ public class DownApplication extends AbstractJavaFxApplicationSupport {
public void start(Stage primaryStage) throws Exception {
this.stage = primaryStage;
Platform.setImplicitExit(false);
handleMacDockIcon();
loadTray();
loadBrowser();
loadWindow();
show();
}

private void handleMacDockIcon() {
if (OsUtil.isMac()) {
try {
Class<?> appClass = Class.forName("com.apple.eawt.Application");
Method getApplication = appClass.getMethod("getApplication");
Object application = getApplication.invoke(appClass);
Method setDockIconImage = appClass.getMethod("setDockIconImage", Image.class);
URL url = Thread.currentThread().getContextClassLoader().getResource("mac/dock_logo.png");
Image image = Toolkit.getDefaultToolkit().getImage(url);
setDockIconImage.invoke(application, image);
} catch (Exception e) {
}
}
}

//加载托盘
private void loadTray() throws AWTException {
if (SystemTray.isSupported()) {
Expand Down
Binary file added main/src/main/resources/mac/dock_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion runner/src/main/java/org/pdown/gui/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String[] args) throws IOException {
JAVA_CMD_PATH,
"-jar",
"-Dfile.encoding=GBK",
"-Dapple.awt.UIElement=true",
//"-Dapple.awt.UIElement=true",
"-Xms128m",
"-Xmx256m",
MAIN_JAR_PATH
Expand Down

0 comments on commit c06d069

Please sign in to comment.