Skip to content

Commit

Permalink
Update appindicator based on JDK 22
Browse files Browse the repository at this point in the history
  • Loading branch information
purejava committed Mar 19, 2024
1 parent 0410613 commit a425083
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -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/')
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-check.yml
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-central.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-github.yml
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions pom.xml
Expand Up @@ -36,15 +36,15 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.jdk.version>21</project.jdk.version>
<project.jdk.version>22</project.jdk.version>

<!-- runtime dependencies -->

<api.version>1.3.1</api.version>
<secret-service.version>2.0.1-alpha</secret-service.version>
<kdewallet.version>1.4.0</kdewallet.version>
<appindicator.version>1.3.6</appindicator.version>
<slf4j.version>2.0.12</slf4j.version>
<appindicator.version>1.4.0</appindicator.version>

<!-- test dependencies -->
<junit.version>5.10.2</junit.version>
Expand Down Expand Up @@ -97,9 +97,6 @@
<version>3.12.1</version>
<configuration>
<release>${project.jdk.version}</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -194,7 +191,6 @@
<name>see</name>
</tag>
</tags>
<additionalOptions>--enable-preview</additionalOptions>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand All @@ -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<TrayIconLoader> 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);
}
}

Expand All @@ -70,18 +70,16 @@ public void updateTrayIcon(Consumer<TrayIconLoader> 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<TrayMenuItem> 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
Expand All @@ -93,30 +91,26 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> 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);
}
}
}
Expand Down

0 comments on commit a425083

Please sign in to comment.