44import org .slf4j .Logger ;
55import org .slf4j .LoggerFactory ;
66
7+ import java .io .File ;
8+ import java .io .IOException ;
79import java .lang .foreign .*;
810import java .lang .invoke .MethodHandle ;
911import java .lang .invoke .MethodHandles ;
1012import java .lang .invoke .MethodType ;
13+ import java .nio .file .Files ;
14+ import java .nio .file .Path ;
15+ import java .util .LinkedList ;
16+ import java .util .List ;
17+ import java .util .stream .Collectors ;
18+ import java .util .stream .Stream ;
1119
1220import static java .lang .foreign .ValueLayout .*;
1321
@@ -19,19 +27,37 @@ final class RuntimeHelper {
1927 private static final SymbolLookup SYMBOL_LOOKUP ;
2028 private static final SegmentAllocator THROWING_ALLOCATOR = (x , y ) -> { throw new AssertionError ("should not reach here" ); };
2129 private static boolean isLoaded = false ;
30+ private static final String LD_CONFIG = "/etc/ld.so.conf.d/" ;
31+ private static final String LIB_NAME_VERSION = "libappindicator3.so.1" ;
32+ private static List <String > allPath = new LinkedList <>();
2233 private static final Logger LOG = LoggerFactory .getLogger (RuntimeHelper .class );
2334
2435 final static SegmentAllocator CONSTANT_ALLOCATOR =
2536 (size , align ) -> MemorySegment .allocateNative (size , align , SegmentScope .auto ());
2637
2738 static {
28- try {
29- System .loadLibrary ("appindicator3" );
30- LOG .debug ("Native code library appindicator3 successfully loaded" );
31- isLoaded = true ;
32- } catch (UnsatisfiedLinkError e ) {
33- LOG .info ("Native code library appindicator3 failed to load" );
39+ try (Stream <Path > paths = Files .list (Path .of (LD_CONFIG ))) {
40+ paths .forEach ((file ) -> {
41+ try (Stream <String > lines = Files .lines (file )) {
42+ List <String > collection = lines .filter (line -> line .startsWith ("/" )).toList ();
43+ allPath .addAll (collection );
44+ } catch (IOException e ) {
45+ LOG .error ("File '{}' could not be loaded" , file );
46+ }
47+ });
48+ } catch (IOException e ) {
49+ LOG .error ("Directory '{}' does not exist" , LD_CONFIG );
50+ }
51+
52+ allPath .add ("/usr/lib" ); // for systems, that don't implement multiarch
53+ for (String path : allPath ) {
54+ try {
55+ System .load (path + File .separator + LIB_NAME_VERSION );
56+ isLoaded = true ;
57+ break ;
58+ } catch (UnsatisfiedLinkError ignored ) { }
3459 }
60+ LOG .info (isLoaded ? "Native code library " + LIB_NAME_VERSION + " successfully loaded" : "Native code library " + LIB_NAME_VERSION + " failed to load" );
3561 SymbolLookup loaderLookup = SymbolLookup .loaderLookup ();
3662 SYMBOL_LOOKUP = name -> loaderLookup .find (name ).or (() -> LINKER .defaultLookup ().find (name ));
3763 }
0 commit comments