From a42508384143a806d2b579b2f563e02ea515fa18 Mon Sep 17 00:00:00 2001 From: Ralph Plawetzki Date: Thu, 29 Feb 2024 19:47:49 +0100 Subject: [PATCH] Update appindicator based on JDK 22 --- .github/workflows/build.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/dependency-check.yml | 2 +- .github/workflows/publish-central.yml | 2 +- .github/workflows/publish-github.yml | 2 +- pom.xml | 8 +- .../linux/tray/ActionItemCallback.java | 2 +- .../tray/AppindicatorTrayMenuController.java | 92 +++++++++---------- 8 files changed, 51 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2612eef..c81ae23 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 21 + java-version: 22 cache: 'maven' - name: Ensure to use tagged version if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e979d17..aeec068 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 21 + java-version: 22 cache: 'maven' - name: Initialize CodeQL uses: github/codeql-action/init@v3 diff --git a/.github/workflows/dependency-check.yml b/.github/workflows/dependency-check.yml index f7872aa..3ace46c 100644 --- a/.github/workflows/dependency-check.yml +++ b/.github/workflows/dependency-check.yml @@ -14,7 +14,7 @@ jobs: with: runner-os: 'ubuntu-latest' java-distribution: 'temurin' - java-version: 21 + java-version: 22 secrets: nvd-api-key: ${{ secrets.NVD_API_KEY }} slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/publish-central.yml b/.github/workflows/publish-central.yml index 7e8c25d..746b083 100644 --- a/.github/workflows/publish-central.yml +++ b/.github/workflows/publish-central.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 21 + java-version: 22 cache: 'maven' server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml server-username: MAVEN_USERNAME # env variable for username in deploy diff --git a/.github/workflows/publish-github.yml b/.github/workflows/publish-github.yml index 2caf761..56ef8f0 100644 --- a/.github/workflows/publish-github.yml +++ b/.github/workflows/publish-github.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 21 + java-version: 22 cache: 'maven' gpg-private-key: ${{ secrets.RELEASES_GPG_PRIVATE_KEY }} # Value of the GPG private key to import gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase diff --git a/pom.xml b/pom.xml index 6d000f3..d56da8b 100644 --- a/pom.xml +++ b/pom.xml @@ -36,15 +36,15 @@ UTF-8 - 21 + 22 1.3.1 2.0.1-alpha 1.4.0 - 1.3.6 2.0.12 + 1.4.0 5.10.2 @@ -97,9 +97,6 @@ 3.12.1 ${project.jdk.version} - - --enable-preview - @@ -194,7 +191,6 @@ see - --enable-preview diff --git a/src/main/java/org/cryptomator/linux/tray/ActionItemCallback.java b/src/main/java/org/cryptomator/linux/tray/ActionItemCallback.java index de1f525..d565237 100644 --- a/src/main/java/org/cryptomator/linux/tray/ActionItemCallback.java +++ b/src/main/java/org/cryptomator/linux/tray/ActionItemCallback.java @@ -5,7 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -record ActionItemCallback (ActionItem actionItem) implements GCallback { +record ActionItemCallback (ActionItem actionItem) implements GCallback.Function { private static final Logger LOG = LoggerFactory.getLogger(ActionItemCallback.class); @Override diff --git a/src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java b/src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java index 1147dc5..9b337fe 100644 --- a/src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java +++ b/src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java @@ -10,16 +10,18 @@ import org.cryptomator.integrations.tray.TrayMenuController; import org.cryptomator.integrations.tray.TrayMenuException; import org.cryptomator.integrations.tray.TrayMenuItem; +import org.purejava.appindicator.AppIndicator; import org.purejava.appindicator.GCallback; -import org.purejava.appindicator.NativeLibUtilities; +import org.purejava.appindicator.GObject; +import org.purejava.appindicator.Gtk; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import java.util.List; -import java.util.Optional; import java.util.function.Consumer; -import static org.purejava.appindicator.app_indicator_h.*; +import static org.purejava.appindicator.app_indicator_h.APP_INDICATOR_CATEGORY_APPLICATION_STATUS; +import static org.purejava.appindicator.app_indicator_h.APP_INDICATOR_STATUS_ACTIVE; @Priority(1000) @CheckAvailability @@ -30,37 +32,35 @@ public class AppindicatorTrayMenuController implements TrayMenuController { private static final Arena ARENA = Arena.global(); private MemorySegment indicator; - private MemorySegment menu = gtk_menu_new(); + private MemorySegment menu = Gtk.newMenu(); @CheckAvailability public static boolean isAvailable() { - return NativeLibUtilities.isLoadedNativeLib(); + return AppIndicator.isLoaded(); } @Override public void showTrayIcon(Consumer iconLoader, Runnable runnable, String s) throws TrayMenuException { TrayIconLoader.FreedesktopIconName callback = this::showTrayIconWithSVG; iconLoader.accept(callback); - gtk_widget_show_all(menu); - app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE()); + Gtk.widgetShowAll(menu); + AppIndicator.setStatus(indicator, APP_INDICATOR_STATUS_ACTIVE()); } - private void showTrayIconWithSVG(String s) { - try (var arena = Arena.ofConfined()) { - var svgSourcePath = System.getProperty(SVG_SOURCE_PROPERTY); - // flatpak - if (svgSourcePath == null) { - indicator = app_indicator_new(arena.allocateUtf8String(APP_INDICATOR_ID), - arena.allocateUtf8String(s), - APP_INDICATOR_CATEGORY_APPLICATION_STATUS()); - // AppImage and ppa - } else { - indicator = app_indicator_new_with_path(arena.allocateUtf8String(APP_INDICATOR_ID), - arena.allocateUtf8String(s), - APP_INDICATOR_CATEGORY_APPLICATION_STATUS(), - // find tray icons theme in mounted AppImage / installed on system by ppa - arena.allocateUtf8String(svgSourcePath)); - } + private void showTrayIconWithSVG(String iconName) { + var svgSourcePath = System.getProperty(SVG_SOURCE_PROPERTY); + // flatpak + if (svgSourcePath == null) { + indicator = AppIndicator.newIndicator(APP_INDICATOR_ID, + iconName, + APP_INDICATOR_CATEGORY_APPLICATION_STATUS()); + // AppImage and ppa + } else { + indicator = AppIndicator.newIndicatorWithPath(APP_INDICATOR_ID, + iconName, + APP_INDICATOR_CATEGORY_APPLICATION_STATUS(), + // find tray icons theme in mounted AppImage / installed on system by ppa + svgSourcePath); } } @@ -70,18 +70,16 @@ public void updateTrayIcon(Consumer iconLoader) { iconLoader.accept(callback); } - private void updateTrayIconWithSVG(String s) { - try (var arena = Arena.ofConfined()) { - app_indicator_set_icon(indicator, arena.allocateUtf8String(s)); - } + private void updateTrayIconWithSVG(String iconName) { + AppIndicator.setIcon(indicator, iconName); } @Override public void updateTrayMenu(List items) throws TrayMenuException { - menu = gtk_menu_new(); + menu = Gtk.newMenu(); addChildren(menu, items); - gtk_widget_show_all(menu); - app_indicator_set_menu(indicator, menu); + Gtk.widgetShowAll(menu); + AppIndicator.setMenu(indicator, menu); } @Override @@ -93,30 +91,26 @@ private void addChildren(MemorySegment menu, List items) { for (var item : items) { switch (item) { case ActionItem a -> { - var gtkMenuItem = gtk_menu_item_new(); - try (var arena = Arena.ofConfined()) { - gtk_menu_item_set_label(gtkMenuItem, arena.allocateUtf8String(a.title())); - g_signal_connect_object(gtkMenuItem, - arena.allocateUtf8String("activate"), - GCallback.allocate(new ActionItemCallback(a), ARENA), - menu, - 0); - } - gtk_menu_shell_append(menu, gtkMenuItem); + var gtkMenuItem = Gtk.newMenuItem(); + Gtk.menuItemSetLabel(gtkMenuItem, a.title()); + GObject.signalConnectObject(gtkMenuItem, + "activate", + GCallback.allocate(new ActionItemCallback(a), ARENA), + menu, + 0); + Gtk.menuShellAppend(menu, gtkMenuItem); } case SeparatorItem _ -> { - var gtkSeparator = gtk_menu_item_new(); - gtk_menu_shell_append(menu, gtkSeparator); + var gtkSeparator = Gtk.newMenuItem(); + Gtk.menuShellAppend(menu, gtkSeparator); } case SubMenuItem s -> { - var gtkMenuItem = gtk_menu_item_new(); - var gtkSubmenu = gtk_menu_new(); - try (var arena = Arena.ofConfined()) { - gtk_menu_item_set_label(gtkMenuItem, arena.allocateUtf8String(s.title())); - } + var gtkMenuItem = Gtk.newMenuItem(); + var gtkSubmenu = Gtk.newMenu(); + Gtk.menuItemSetLabel(gtkMenuItem, s.title()); addChildren(gtkSubmenu, s.items()); - gtk_menu_item_set_submenu(gtkMenuItem, gtkSubmenu); - gtk_menu_shell_append(menu, gtkMenuItem); + Gtk.menuItemSetSubmenu(gtkMenuItem, gtkSubmenu); + Gtk.menuShellAppend(menu, gtkMenuItem); } } }