Added AppIndicator.IS_VERSION_3, so we can tell if version 3 is loaded or not (it's a piece of shit, so we want to show an warning about this to the user)

This commit is contained in:
nathan 2016-02-12 14:25:06 +01:00
parent ebc849f9d0
commit 9081643963
2 changed files with 27 additions and 36 deletions

View File

@ -29,8 +29,13 @@ public
interface AppIndicator extends Library {
// effing retarded. There are DIFFERENT versions, of which they all share the same basic compatibility (of the methods that
// we use), however -- we cannot just LOAD via the 'base-name', we actually have to try each one. There are bash commands that
// will tell us the linked library name, however - I'd rather not run bash commands to determine this.
AppIndicator INSTANCE = (AppIndicator) AppIndicatorQuery.get();
// will tell us the linked library name, however - I'd rather not run bash commands to determine this. This is so hacky it makes me
// sick.
AppIndicator INSTANCE = AppIndicatorQuery.get();
/** Necessary to provide warnings, because libappindicator3 is a piece of shit. */
boolean IS_VERSION_3 = AppIndicatorQuery.isVersion3;
int CATEGORY_APPLICATION_STATUS = 0;
int CATEGORY_COMMUNICATIONS = 1;

View File

@ -16,45 +16,29 @@
package dorkbox.util.jna.linux;
import com.sun.jna.Library;
import com.sun.jna.Native;
/**
* Helper for AppIndicator, because it is absolutely mindboggling how those whom maintain the standard, can't agree to what that standard
* library naming convention or features set is. We just try until we find one that work, and are able to map the symbols we need.
*/
public
class AppIndicatorQuery {
public static
Object get_v1() {
// version 1 is better than version 3, because of dumb shit redhat did.
// to wit, installing the google chrome browser, will ALSO install the correct appindicator library.
try {
Object appindicator = Native.loadLibrary("appindicator", Library.class);
if (appindicator != null) {
String s = appindicator.toString();
// make sure it's actually v1. If it's NOT v1 (ie: v3) then fallback to GTK version
if (s.indexOf(".so.1") < 1) {
return null;
}
}
return appindicator;
} catch (Throwable ignored) {
ignored.printStackTrace();
}
return null;
}
/**
* must call get() before accessing this! Only "AppIndicator" interface should access this!
*/
static volatile boolean isVersion3 = false;
public static
Object get() {
AppIndicator get() {
Object library;
// start with base version
try {
library = Native.loadLibrary("appindicator", AppIndicator.class);
if (library != null) {
return library;
return (AppIndicator) library;
}
} catch (Throwable ignored) {
}
@ -65,7 +49,7 @@ class AppIndicatorQuery {
try {
library = Native.loadLibrary("appindicator1", AppIndicator.class);
if (library != null) {
return library;
return (AppIndicator) library;
}
} catch (Throwable ignored) {
}
@ -74,15 +58,17 @@ class AppIndicatorQuery {
for (int i = 10; i >= 0; i--) {
try {
library = Native.loadLibrary("appindicator" + i, AppIndicator.class);
if (library != null) {
if (i == 3) {
System.err.println("AppIndicator3 detected. This version is SEVERELY limited, and menu icons WILL NOT be visible. " +
"Please install a better version of libappindicator. One such command to do so is: " +
"sudo apt-get install libappindicator1");
}
return library;
}
} catch (Throwable ignored) {
library = null;
}
if (library != null) {
String s = library.toString();
// version 3 WILL NOT work with icons in the menu. This allows us to show a warning (in the System tray initialization)
if (i == 3 || s.indexOf("appindicator3") > 0) {
isVersion3 = true;
}
return (AppIndicator) library;
}
}
@ -90,7 +76,7 @@ class AppIndicatorQuery {
try {
library = Native.loadLibrary("appindicator-gtk", AppIndicator.class);
if (library != null) {
return library;
return (AppIndicator) library;
}
} catch (Throwable ignored) {
}
@ -99,7 +85,7 @@ class AppIndicatorQuery {
try {
library = Native.loadLibrary("appindicator-gtk3", AppIndicator.class);
if (library != null) {
return library;
return (AppIndicator) library;
}
} catch (Throwable ignored) {
}