Skip to content

Commit cfa3c3c

Browse files
committed
Update to JDK 22
1 parent 834a0db commit cfa3c3c

File tree

6,940 files changed

+903251
-470740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,940 files changed

+903251
-470740
lines changed

.github/workflows/publish-maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/setup-java@v4
1919
with:
2020
distribution: 'zulu'
21-
java-version: 21
21+
java-version: 22
2222
cache: 'maven'
2323
server-id: ossrh
2424
server-username: MAVEN_USERNAME

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
</scm>
3737

3838
<properties>
39-
<maven.compiler.source>21</maven.compiler.source>
40-
<maven.compiler.target>21</maven.compiler.target>
39+
<maven.compiler.source>22</maven.compiler.source>
40+
<maven.compiler.target>22</maven.compiler.target>
4141
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4242

4343
<junit.version>5.10.2</junit.version>
@@ -132,11 +132,8 @@
132132
<artifactId>maven-compiler-plugin</artifactId>
133133
<version>3.12.1</version>
134134
<configuration>
135-
<source>21</source>
136-
<target>21</target>
137-
<compilerArgs>
138-
--enable-preview
139-
</compilerArgs>
135+
<source>22</source>
136+
<target>22</target>
140137
</configuration>
141138
</plugin>
142139
<plugin>
@@ -164,7 +161,6 @@
164161
</goals>
165162
<configuration>
166163
<failOnError>false</failOnError>
167-
<additionalOptions>--enable-preview</additionalOptions>
168164
</configuration>
169165
</execution>
170166
</executions>

src/main/java/org/purejava/appindicator/AppIndicator.java

Lines changed: 291 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,300 @@
22

33
package org.purejava.appindicator;
44

5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.lang.foreign.Arena;
11+
import java.lang.foreign.MemorySegment;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.util.LinkedList;
15+
import java.util.List;
16+
import java.util.stream.Stream;
17+
18+
import static org.purejava.appindicator.app_indicator_h_1.*;
19+
520
/**
6-
* {@snippet :
7-
* typedef struct _AppIndicator AppIndicator;
21+
* {@snippet lang=c :
22+
* typedef struct _AppIndicator AppIndicator
823
* }
924
*/
10-
public final class AppIndicator extends _AppIndicator {
25+
public class AppIndicator extends _AppIndicator {
1126

12-
// Suppresses default constructor, ensuring non-instantiability.
13-
private AppIndicator() {}
14-
}
27+
private static final Logger LOG = LoggerFactory.getLogger(AppIndicator.class);
28+
private static boolean isLoaded = false;
29+
private static final String LD_CONFIG = "/etc/ld.so.conf.d/";
30+
private static final String LIB_NAME_VERSION = "libappindicator3.so.1";
31+
private static final String FLATPAK_LIB_NAME_VERSION = "libappindicator3.so";
32+
private static final String LIBNAME_WITH_VERSION = "appindicator3";
33+
private static List<String> allPath = new LinkedList<>();
34+
35+
static {
36+
try (Stream<Path> paths = Files.list(Path.of(LD_CONFIG))) {
37+
paths.forEach((file) -> {
38+
try (Stream<String> lines = Files.lines(file)) {
39+
List<String> collection = lines.filter(line -> line.startsWith("/")).toList();
40+
allPath.addAll(collection);
41+
} catch (IOException e) {
42+
LOG.error("File '{}' could not be loaded", file);
43+
}
44+
});
45+
} catch (IOException e) {
46+
LOG.error("Directory '{}' does not exist", LD_CONFIG);
47+
}
48+
49+
allPath.add("/usr/lib"); // for systems, that don't implement multiarch
50+
allPath.add("/app/lib"); // for flatpak and libraries in the flatpak sandbox
51+
for (String path : allPath) {
52+
try {
53+
if (!path.equals("/app/lib")) {
54+
System.load(path + File.separator + LIB_NAME_VERSION);
55+
} else {
56+
// flatpak has an own, self-compiled version
57+
System.load(path + File.separator + FLATPAK_LIB_NAME_VERSION);
58+
}
59+
isLoaded = true;
60+
break;
61+
} catch (UnsatisfiedLinkError ignored) { }
62+
}
63+
64+
// When loading via System.load wasn't successful, try to load via System.loadLibrary
65+
if (!isLoaded) {
66+
try {
67+
System.loadLibrary(LIBNAME_WITH_VERSION);
68+
isLoaded = true;
69+
} catch (UnsatisfiedLinkError ignored) { }
70+
}
71+
LOG.info(isLoaded ? "Native code library libappindicator3 successfully loaded" : "Native code library libappindicator3 failed to load");
72+
}
73+
74+
AppIndicator() {
75+
// Should not be called directly
76+
}
77+
78+
/**
79+
* Creates a new AppIndicator setting the properties: “id” with id , “category” with category and “icon-name” with iconName.
80+
* @param id The unique id of the indicator to create.
81+
* @param iconName The icon name for this indicator.
82+
* @param category The category of indicator.
83+
* @return A pointer to a new AppIndicator object.
84+
*/
85+
public static MemorySegment newIndicator(String id, String iconName, int category) {
86+
if (null != id && null != iconName) {
87+
try (var arena = Arena.ofConfined()) {
88+
return app_indicator_new(arena.allocateFrom(id), arena.allocateFrom(iconName), category);
89+
}
90+
} else {
91+
return MemorySegment.NULL;
92+
}
93+
}
94+
95+
/**
96+
* Creates a new AppIndicator setting the properties: “id” with id , “category” with category , “icon-name” with iconName and “icon-theme-path” with iconThemePath.
97+
* @param id The unique id of the indicator to create.
98+
* @param iconName The icon name for this indicator.
99+
* @param category The category of indicator.
100+
* @param iconThemePath A custom path for finding icons.
101+
* @return A pointer to a new AppIndicator object.
102+
*/
103+
public static MemorySegment newIndicatorWithPath(String id, String iconName, int category, String iconThemePath) {
104+
if (null != id && null != iconName && null != iconThemePath) {
105+
try (var arena = Arena.ofConfined()) {
106+
return app_indicator_new_with_path(arena.allocateFrom(id), arena.allocateFrom(iconName), category, arena.allocateFrom(iconThemePath));
107+
}
108+
} else {
109+
return MemorySegment.NULL;
110+
}
111+
}
112+
113+
/**
114+
* This function allows for building the Application Indicator menu from a static desktop file.
115+
* @param self The AppIndicator object to use.
116+
* @param desktopFile A path to the desktop file to build the menu from.
117+
* @param desktopProfile Which entries should be used from the desktop file.
118+
*/
119+
public static void buildMenuFromDesktop(MemorySegment self, String desktopFile, String desktopProfile) {
120+
if (null != self && null != desktopFile && null != desktopProfile) {
121+
try (var arena = Arena.ofConfined()) {
122+
app_indicator_build_menu_from_desktop(self, arena.allocateFrom(desktopFile), arena.allocateFrom(desktopProfile));
123+
}
124+
}
125+
}
126+
127+
/**
128+
* Wrapper function for property “category”.
129+
* @param self The AppIndicator object to use.
130+
* @return The current category.
131+
*/
132+
public static int getCategory(MemorySegment self) {
133+
return null != self ? app_indicator_get_category(self) : -1;
134+
}
135+
136+
/**
137+
* Wrapper function for property “attention-icon-name”.
138+
* @param self The AppIndicator object to use.
139+
* @return The current attention icon name.
140+
*/
141+
public static String getAttentionIcon(MemorySegment self) {
142+
return null != self ? app_indicator_get_attention_icon(self).getString(0) : "";
143+
}
144+
145+
/**
146+
* Wrapper function for property “id”.
147+
* @param self The AppIndicator object to use.
148+
* @return The current ID.
149+
*/
150+
public static String getID(MemorySegment self) {
151+
return null != self ? app_indicator_get_id(self).getString(0) : "";
152+
}
15153

154+
/**
155+
* Wrapper function for property “icon-name”.
156+
* @param self The AppIndicator object to use.
157+
* @return The current icon name.
158+
*/
159+
public static String getIcon(MemorySegment self) {
160+
return null != self ? app_indicator_get_icon(self).getString(0) : "";
161+
}
162+
163+
/**
164+
* Wrapper function for property “label”.
165+
* @param self The AppIndicator object to use.
166+
* @return The current label.
167+
*/
168+
public static String getLabel(MemorySegment self) {
169+
return null != self ? app_indicator_get_label(self).getString(0) : "";
170+
}
171+
172+
/**
173+
* Gets the menu being used for this application indicator. Wrapper function for property “menu”.
174+
* @param self The AppIndicator object to use.
175+
* @return A GtkMenu object or NULL if one hasn't been set.
176+
*/
177+
public static MemorySegment getMenu(MemorySegment self) {
178+
return null != self ? app_indicator_get_menu(self) : MemorySegment.NULL;
179+
}
180+
181+
/**
182+
* Wrapper function for property “ordering-index”.
183+
* @param self The AppIndicator object to use.
184+
* @return The current ordering index.
185+
*/
186+
public static int getOrderingIndex(MemorySegment self) {
187+
return null != self ? app_indicator_get_ordering_index(self) : 0;
188+
}
189+
190+
/**
191+
* Wrapper function for property “status”.
192+
* @param self The AppIndicator object to use.
193+
* @return The current status.
194+
*/
195+
public static int getStatus(MemorySegment self) {
196+
return null != self ? app_indicator_get_status(self) : -1;
197+
}
198+
199+
/**
200+
* Gets the title of the application indicator. See the function app_indicator_set_title() for information on the title.
201+
* @param self The AppIndicator object to use.
202+
* @return The current title.
203+
*/
204+
public static String getTitle(MemorySegment self) {
205+
return null != self ? app_indicator_get_title(self).getString(0) : "";
206+
}
207+
208+
/**
209+
* Wrapper for app_indicator_set_attention_icon_full() with a NULL description.
210+
* @param self The AppIndicator object to use.
211+
* @param iconName The name of the attention icon to set for this indicator.
212+
*/
213+
public static void setAttentionIcon(MemorySegment self, String iconName) {
214+
if (null != self && null != iconName) {
215+
try (var arena = Arena.ofConfined()) {
216+
app_indicator_set_attention_icon(self, arena.allocateFrom(iconName));
217+
}
218+
}
219+
}
220+
221+
/**
222+
* Wrapper function for app_indicator_set_icon_full() with a NULL description.
223+
* @param self The AppIndicator object to use.
224+
* @param iconName The icon name to set.
225+
*/
226+
public static void setIcon(MemorySegment self, String iconName) {
227+
if (null != self && null != iconName) {
228+
try (var arena = Arena.ofConfined()) {
229+
app_indicator_set_icon(self, arena.allocateFrom(iconName));
230+
}
231+
}
232+
}
233+
234+
/**
235+
* This is a wrapper function for the “label” and “guide” properties. This function can take NULL as either label or guide and will clear the entries.
236+
* @param self The AppIndicator object to use.
237+
* @param label The label to show next to the icon.
238+
* @param guide A guide to size the label correctly.
239+
*/
240+
public static void setLabel(MemorySegment self, String label, String guide) {
241+
if (null != self && null != label && null != guide) {
242+
try (var arena = Arena.ofConfined()) {
243+
app_indicator_set_label(self, arena.allocateFrom(label), arena.allocateFrom(guide));
244+
}
245+
}
246+
}
247+
248+
/**
249+
* Sets the menu that should be shown when the Application Indicator is clicked on in the panel. An application indicator will not be rendered unless it has a menu.
250+
* Wrapper function for property “menu”.
251+
* @param self The AppIndicator object to use.
252+
* @param menu A GtkMenu to set.
253+
*/
254+
public static void setMenu(MemorySegment self, MemorySegment menu) {
255+
if (null != self && null != menu) {
256+
app_indicator_set_menu(self, menu);
257+
}
258+
}
259+
260+
/**
261+
* Sets the ordering index for the app indicator which effects the placement of it on the panel. For almost all app indicator this is not the function you're looking for.
262+
* Wrapper function for property “ordering-index”.
263+
* @param self The AppIndicator object to use.
264+
* @param orderingIndex A value for the ordering of this app indicator.
265+
*/
266+
public static void setOrderingIndex(MemorySegment self, int orderingIndex) {
267+
if (null != self) {
268+
app_indicator_set_ordering_index(self, orderingIndex);
269+
}
270+
}
271+
272+
/**
273+
* Wrapper function for property “status”.
274+
* @param self The AppIndicator object to use.
275+
* @param status The status to set for this indicator.
276+
*/
277+
public static void setStatus(MemorySegment self, int status) {
278+
if (null != self) {
279+
app_indicator_set_status(self, status);
280+
}
281+
}
282+
283+
/**
284+
* Sets the title of the application indicator, or how it should be referred in a human readable form. This string should be UTF-8 and localized as it expected that users will set it.
285+
* In the Unity desktop the most prominent place that this is show will be in the HUD. HUD listings for this application indicator will start with the title as the first part of the line for the menu items.
286+
* @param self The AppIndicator object to use.
287+
* @param title Title of the app indicator. Setting title to NULL removes the title.
288+
*/
289+
public static void setTitle(MemorySegment self, String title) {
290+
if (null != self) {
291+
try (var arena = Arena.ofConfined()) {
292+
app_indicator_set_title(self, arena.allocateFrom(title));
293+
}
294+
}
295+
}
296+
297+
public static boolean isLoaded() {
298+
return isLoaded;
299+
}
300+
}
16301

src/main/java/org/purejava/appindicator/AppIndicatorClass.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
package org.purejava.appindicator;
44

5+
import java.lang.invoke.*;
6+
import java.lang.foreign.*;
7+
import java.nio.ByteOrder;
8+
import java.util.*;
9+
import java.util.function.*;
10+
import java.util.stream.*;
11+
12+
import static java.lang.foreign.ValueLayout.*;
13+
import static java.lang.foreign.MemoryLayout.PathElement.*;
14+
515
/**
6-
* {@snippet :
7-
* typedef struct _AppIndicatorClass AppIndicatorClass;
16+
* {@snippet lang=c :
17+
* typedef struct _AppIndicatorClass AppIndicatorClass
818
* }
919
*/
10-
public final class AppIndicatorClass extends _AppIndicatorClass {
20+
public class AppIndicatorClass extends _AppIndicatorClass {
1121

12-
// Suppresses default constructor, ensuring non-instantiability.
13-
private AppIndicatorClass() {}
22+
AppIndicatorClass() {
23+
// Should not be called directly
24+
}
1425
}
1526

16-

0 commit comments

Comments
 (0)