mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-12-27 07:10:41 +08:00
修复 macOS Dock 中的图标 (#1862)
* High resolution logo * Load original icon on Java 8
This commit is contained in:
parent
5e685b7f26
commit
8c9c8fd28f
@ -28,7 +28,6 @@ import org.jackhuang.hmcl.setting.ConfigHolder;
|
|||||||
import org.jackhuang.hmcl.setting.SambaException;
|
import org.jackhuang.hmcl.setting.SambaException;
|
||||||
import org.jackhuang.hmcl.task.AsyncTaskExecutor;
|
import org.jackhuang.hmcl.task.AsyncTaskExecutor;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.ui.AwtUtils;
|
|
||||||
import org.jackhuang.hmcl.ui.Controllers;
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
import org.jackhuang.hmcl.upgrade.UpdateChecker;
|
import org.jackhuang.hmcl.upgrade.UpdateChecker;
|
||||||
import org.jackhuang.hmcl.upgrade.UpdateHandler;
|
import org.jackhuang.hmcl.upgrade.UpdateHandler;
|
||||||
@ -130,9 +129,6 @@ public final class Launcher extends Application {
|
|||||||
Platform.setImplicitExit(false);
|
Platform.setImplicitExit(false);
|
||||||
Controllers.initialize(primaryStage);
|
Controllers.initialize(primaryStage);
|
||||||
|
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
|
|
||||||
initIcon();
|
|
||||||
|
|
||||||
UpdateChecker.init();
|
UpdateChecker.init();
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
@ -148,11 +144,6 @@ public final class Launcher extends Application {
|
|||||||
Controllers.onApplicationStop();
|
Controllers.onApplicationStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initIcon() {
|
|
||||||
java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().getImage(Launcher.class.getResource("/assets/img/icon.png"));
|
|
||||||
AwtUtils.setAppleIcon(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if (UpdateHandler.processArguments(args)) {
|
if (UpdateHandler.processArguments(args)) {
|
||||||
return;
|
return;
|
||||||
|
@ -19,11 +19,13 @@ package org.jackhuang.hmcl;
|
|||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
|
import org.jackhuang.hmcl.ui.AwtUtils;
|
||||||
import org.jackhuang.hmcl.util.Logging;
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
import org.jackhuang.hmcl.util.SelfDependencyPatcher;
|
import org.jackhuang.hmcl.util.SelfDependencyPatcher;
|
||||||
import org.jackhuang.hmcl.ui.SwingUtils;
|
import org.jackhuang.hmcl.ui.SwingUtils;
|
||||||
import org.jackhuang.hmcl.util.platform.Architecture;
|
import org.jackhuang.hmcl.util.platform.Architecture;
|
||||||
import org.jackhuang.hmcl.util.platform.JavaVersion;
|
import org.jackhuang.hmcl.util.platform.JavaVersion;
|
||||||
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
@ -65,6 +67,9 @@ public final class Main {
|
|||||||
// This environment check will take ~300ms
|
// This environment check will take ~300ms
|
||||||
thread(Main::fixLetsEncrypt, "CA Certificate Check", true);
|
thread(Main::fixLetsEncrypt, "CA Certificate Check", true);
|
||||||
|
|
||||||
|
if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX)
|
||||||
|
initIcon();
|
||||||
|
|
||||||
Logging.start(Metadata.HMCL_DIRECTORY.resolve("logs"));
|
Logging.start(Metadata.HMCL_DIRECTORY.resolve("logs"));
|
||||||
|
|
||||||
checkJavaFX();
|
checkJavaFX();
|
||||||
@ -72,6 +77,11 @@ public final class Main {
|
|||||||
Launcher.main(args);
|
Launcher.main(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void initIcon() {
|
||||||
|
java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/assets/img/icon@8x.png"));
|
||||||
|
AwtUtils.setAppleIcon(image);
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkDirectoryPath() {
|
private static void checkDirectoryPath() {
|
||||||
String currentDirectory = new File("").getAbsolutePath();
|
String currentDirectory = new File("").getAbsolutePath();
|
||||||
if (currentDirectory.contains("!")) {
|
if (currentDirectory.contains("!")) {
|
||||||
|
@ -9,8 +9,8 @@ public final class AwtUtils {
|
|||||||
|
|
||||||
public static void setAppleIcon(Image image) {
|
public static void setAppleIcon(Image image) {
|
||||||
try {
|
try {
|
||||||
Class<?> taskbarClass = Class.forName("java.awt.TaskBar");
|
Class<?> taskbarClass = Class.forName("java.awt.Taskbar");
|
||||||
Method getTaskBarMethod = taskbarClass.getDeclaredMethod("getTaskBar");
|
Method getTaskBarMethod = taskbarClass.getDeclaredMethod("getTaskbar");
|
||||||
Object taskBar = getTaskBarMethod.invoke(null);
|
Object taskBar = getTaskBarMethod.invoke(null);
|
||||||
Method setIconImageMethod = taskbarClass.getDeclaredMethod("setIconImage", Image.class);
|
Method setIconImageMethod = taskbarClass.getDeclaredMethod("setIconImage", Image.class);
|
||||||
setIconImageMethod.invoke(taskBar, image);
|
setIconImageMethod.invoke(taskBar, image);
|
||||||
|
@ -57,7 +57,10 @@ import org.jackhuang.hmcl.upgrade.UpdateChecker;
|
|||||||
import org.jackhuang.hmcl.upgrade.UpdateHandler;
|
import org.jackhuang.hmcl.upgrade.UpdateHandler;
|
||||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||||
import org.jackhuang.hmcl.util.javafx.MappedObservableList;
|
import org.jackhuang.hmcl.util.javafx.MappedObservableList;
|
||||||
|
import org.jackhuang.hmcl.util.platform.JavaVersion;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@ -89,7 +92,16 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
titleNode.setAlignment(Pos.CENTER_LEFT);
|
titleNode.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
|
||||||
ImageView titleIcon = new ImageView();
|
ImageView titleIcon = new ImageView();
|
||||||
titleIcon.setImage(new Image("/assets/img/icon.png", 20, 20, false, false));
|
if (JavaVersion.CURRENT_JAVA.getParsedVersion() < 9) {
|
||||||
|
// JavaFX 8 has some problems with @2x images
|
||||||
|
// Force load the original icon
|
||||||
|
try (InputStream is = MainPage.class.getResourceAsStream("/assets/img/icon.png")) {
|
||||||
|
titleIcon.setImage(new Image(is, 20, 20, false, false));
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
titleIcon.setImage(new Image("/assets/img/icon.png", 20, 20, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
Label titleLabel = new Label(Metadata.FULL_TITLE);
|
Label titleLabel = new Label(Metadata.FULL_TITLE);
|
||||||
titleLabel.getStyleClass().add("jfx-decorator-title");
|
titleLabel.getStyleClass().add("jfx-decorator-title");
|
||||||
|
BIN
HMCL/src/main/resources/assets/img/icon@2x.png
Normal file
BIN
HMCL/src/main/resources/assets/img/icon@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.0 KiB |
BIN
HMCL/src/main/resources/assets/img/icon@8x.png
Normal file
BIN
HMCL/src/main/resources/assets/img/icon@8x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
Loading…
Reference in New Issue
Block a user