From 54e75ce6bdaa3b41cf57d1397fe1802bbf1aeb7f Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 25 Oct 2023 14:20:49 +0000 Subject: [PATCH] Fix javafx bundling --- .../java/io/xpipe/app/core/AppTrayIcon.java | 94 +------------------ dist/jpackage.gradle | 1 + gradle/gradle_scripts/extension_test.gradle | 6 +- gradle/gradle_scripts/javafx.gradle | 17 ++-- 4 files changed, 16 insertions(+), 102 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java b/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java index 0acd5002..6d2c69e9 100644 --- a/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java +++ b/app/src/main/java/io/xpipe/app/core/AppTrayIcon.java @@ -5,7 +5,6 @@ import io.xpipe.app.issue.ErrorEvent; import io.xpipe.core.process.OsType; import javax.imageio.ImageIO; -import javax.swing.*; import java.awt.*; import java.io.IOException; import java.lang.reflect.Field; @@ -15,19 +14,10 @@ public class AppTrayIcon { private boolean shown = false; - /** - * The default AWT SystemTray - */ private final SystemTray tray; - /** - * The AWT TrayIcon managed by FXTrayIcon - */ private final TrayIcon trayIcon; - /** - * The AWT PopupMenu managed by FXTrayIcon - */ private final PopupMenu popupMenu = new PopupMenu(); public AppTrayIcon() { @@ -72,12 +62,6 @@ public class AppTrayIcon { }); } - /** - * Gets the nested AWT {@link TrayIcon}. This is intended for extended - * instances of FXTrayIcon which require the access to implement - * custom features. - * @return The nest trayIcon within this instance of FXTrayIcon. - */ public final TrayIcon getAwtTrayIcon() { return trayIcon; } @@ -99,19 +83,8 @@ public class AppTrayIcon { } } - /** - * Adds the FXTrayIcon to the system tray. - * This will add the TrayIcon with the image initialized in the - * {@code FXTrayIcon}'s constructor. By default, an empty popup - * menu is shown. - * By default, {@code javafx.application.Platform.setImplicitExit(false)} - * will be called. This will allow the application to continue running - * and show the tray icon after no more JavaFX Stages are visible. If - * this is not the behavior that you intend, call {@code setImplicitExit} - * to true after calling {@code show()}. - */ public void show() { - SwingUtilities.invokeLater(() -> { + EventQueue.invokeLater(() -> { try { tray.add(this.trayIcon); shown = true; @@ -125,7 +98,7 @@ public class AppTrayIcon { private void fixBackground() { // Ugly fix to show a transparent background on Linux if (OsType.getLocal().equals(OsType.LINUX)) { - SwingUtilities.invokeLater(() -> { + EventQueue.invokeLater(() -> { try { Field peerField; peerField = TrayIcon.class.getDeclaredField("peer"); @@ -160,12 +133,6 @@ public class AppTrayIcon { }); } - /** - * Displays an info popup message near the tray icon. - *

NOTE: Some systems do not support this.

- * @param title The caption (header) text - * @param message The message content text - */ public void showInfoMessage(String title, String message) { if (OsType.getLocal().equals(OsType.MACOS)) { showMacAlert(title, message,"Information"); @@ -176,21 +143,10 @@ public class AppTrayIcon { } } - /** - * Displays an info popup message near the tray icon. - *

NOTE: Some systems do not support this.

- * @param message The message content text - */ public void showInfoMessage(String message) { this.showInfoMessage(null, message); } - /** - * Displays a warning popup message near the tray icon. - *

NOTE: Some systems do not support this.

- * @param title The caption (header) text - * @param message The message content text - */ public void showWarningMessage(String title, String message) { if (OsType.getLocal().equals(OsType.MACOS)) { showMacAlert(title, message,"Warning"); @@ -201,21 +157,10 @@ public class AppTrayIcon { } } - /** - * Displays a warning popup message near the tray icon. - *

NOTE: Some systems do not support this.

- * @param message The message content text - */ public void showWarningMessage(String message) { this.showWarningMessage(null, message); } - /** - * Displays an error popup message near the tray icon. - *

NOTE: Some systems do not support this.

- * @param title The caption (header) text - * @param message The message content text - */ public void showErrorMessage(String title, String message) { if (OsType.getLocal().equals(OsType.MACOS)) { showMacAlert(title, message,"Error"); @@ -226,22 +171,10 @@ public class AppTrayIcon { } } - /** - * Displays an error popup message near the tray icon. - *

NOTE: Some systems do not support this.

- * @param message The message content text - */ public void showErrorMessage(String message) { this.showErrorMessage(null, message); } - /** - * Displays a popup message near the tray icon. - * Some systems will display FXTrayIcon's image on this popup. - *

NOTE: Some systems do not support this.

- * @param title The caption (header) text - * @param message The message content text - */ public void showMessage(String title, String message) { if (OsType.getLocal().equals(OsType.MACOS)) { showMacAlert(title, message,"Message"); @@ -252,37 +185,14 @@ public class AppTrayIcon { } } - /** - * Displays a popup message near the tray icon. - * Some systems will display FXTrayIcon's image on this popup. - *

NOTE: Some systems do not support this.

- * @param message The message content text - */ public void showMessage(String message) { this.showMessage(null, message); } - /** - * Checks whether the system tray icon is supported on the - * current platform, or not. - * Just because the system tray is supported, does not mean that the - * current platform implements all system tray functionality. - * This will always return true on Windows or MacOS. Check the - * specific desktop environment for AppIndicator support when - * calling this on *nix platforms. - * @return false if the system tray is not supported, true if any - * part of the system tray functionality is supported. - */ public static boolean isSupported() { return Desktop.isDesktopSupported() && SystemTray.isSupported(); } - /** - * Displays a sliding info message. Behavior is similar to Windows, but without AWT - * @param subTitle The message caption - * @param message The message text - * @param title The message title - */ private void showMacAlert(String subTitle, String message, String title) { String execute = String.format( "display notification \"%s\"" diff --git a/dist/jpackage.gradle b/dist/jpackage.gradle index 94146d5a..028aa52f 100644 --- a/dist/jpackage.gradle +++ b/dist/jpackage.gradle @@ -26,6 +26,7 @@ application { } def appDependencies = project(':app').configurations.findByName('runtimeClasspath').getFiles().stream() + .filter(f -> !f.name.startsWith('javafx')) // Remove JavaFX dependencies .collect(Collectors.toMap(f -> f.toPath().getFileName().toString(), f -> f, (f1, f2) -> f1)) .values() def appModuleNames = ['app'] diff --git a/gradle/gradle_scripts/extension_test.gradle b/gradle/gradle_scripts/extension_test.gradle index cfcca34f..cc7abbec 100644 --- a/gradle/gradle_scripts/extension_test.gradle +++ b/gradle/gradle_scripts/extension_test.gradle @@ -7,9 +7,9 @@ dependencies { testImplementation project(':core') testImplementation project(':app') - testImplementation "org.openjfx:javafx-base:21:win" - testImplementation "org.openjfx:javafx-controls:21:win" - testImplementation "org.openjfx:javafx-graphics:21:win" + testImplementation "org.openjfx:javafx-base:${javafxVersion}:win" + testImplementation "org.openjfx:javafx-controls:${javafxVersion}:win" + testImplementation "org.openjfx:javafx-graphics:${javafxVersion}:win" } def attachDebugger = System.getProperty('idea.debugger.dispatch.addr') != null diff --git a/gradle/gradle_scripts/javafx.gradle b/gradle/gradle_scripts/javafx.gradle index ee105349..d302d9e9 100644 --- a/gradle/gradle_scripts/javafx.gradle +++ b/gradle/gradle_scripts/javafx.gradle @@ -15,11 +15,14 @@ if (arch == 'aarch64') { platform += '-aarch64' } -dependencies { - compileOnly "org.openjfx:javafx-base:${javafxVersion}:${platform}" - compileOnly "org.openjfx:javafx-controls:${javafxVersion}:${platform}" - compileOnly "org.openjfx:javafx-graphics:${javafxVersion}:${platform}" - compileOnly "org.openjfx:javafx-media:${javafxVersion}:${platform}" - compileOnly "org.openjfx:javafx-web:${javafxVersion}:${platform}" - compileOnly "org.openjfx:javafx-swing:${javafxVersion}:${platform}" +configurations { + dep +} + +dependencies { + dep "org.openjfx:javafx-base:${javafxVersion}:${platform}" + dep "org.openjfx:javafx-controls:${javafxVersion}:${platform}" + dep "org.openjfx:javafx-graphics:${javafxVersion}:${platform}" + dep "org.openjfx:javafx-media:${javafxVersion}:${platform}" + dep "org.openjfx:javafx-web:${javafxVersion}:${platform}" }