Cleaned up debug, comments

This commit is contained in:
Robinson 2021-04-07 14:53:27 +02:00
parent f5f4bca004
commit 9c69080bd3

View File

@ -17,15 +17,12 @@ package dorkbox.jna.linux;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import dorkbox.jna.JnaHelper; import dorkbox.jna.JnaHelper;
import dorkbox.jna.linux.structs.AppIndicatorInstanceStruct; import dorkbox.jna.linux.structs.AppIndicatorInstanceStruct;
import dorkbox.os.OS; import dorkbox.os.OS;
import dorkbox.os.OSUtil; import dorkbox.os.OSUtil;
import dorkbox.os.OSUtil.Linux.PackageManager;
import dorkbox.os.OSUtil.Linux.PackageManager.Type;
/** /**
* bindings for libappindicator * bindings for libappindicator
@ -76,18 +73,18 @@ class AppIndicator {
// NOTE: appindicator1 -> GTk2, appindicator3 -> GTK3. // NOTE: appindicator1 -> GTk2, appindicator3 -> GTK3.
// Note: appindicator-gtk3 is Fedora... // Note: appindicator-gtk3 is Fedora...
if (Gtk.isGtk2) { if (Gtk.isGtk2) {
for (String libraryName : GTK2) { for (String libraryName : GTK2) {
if (!_isLoaded) { if (!_isLoaded) {
try { try {
final NativeLibrary library = JnaHelper.register(libraryName, AppIndicator.class); JnaHelper.register(libraryName, AppIndicator.class);
if (library != null) { _isLoaded = true;
_isLoaded = true; if (GtkEventDispatch.DEBUG) {
LoggerFactory.getLogger(AppIndicator.class).debug("Loaded GTK2 library name '{}'.", libraryName);
} }
} catch (Throwable e) { } catch (Throwable e) {
if (GtkEventDispatch.DEBUG) { if (GtkEventDispatch.DEBUG) {
LoggerFactory.getLogger(AppIndicator.class).debug("Error loading GTK2 library name '{}'. {}", libraryName, e.getMessage()); LoggerFactory.getLogger(AppIndicator.class).debug("Error loading GTK2 library name '{}'.", libraryName, e);
} }
} }
} }
@ -98,13 +95,14 @@ class AppIndicator {
for (String libraryName : GTK3) { for (String libraryName : GTK3) {
if (!_isLoaded) { if (!_isLoaded) {
try { try {
final NativeLibrary library = JnaHelper.register(libraryName, AppIndicator.class); JnaHelper.register(libraryName, AppIndicator.class);
if (library != null) { _isLoaded = true;
_isLoaded = true; if (GtkEventDispatch.DEBUG) {
LoggerFactory.getLogger(AppIndicator.class).debug("Loaded GTK3 library name '{}'.", libraryName);
} }
} catch (Throwable e) { } catch (Throwable e) {
if (GtkEventDispatch.DEBUG) { if (GtkEventDispatch.DEBUG) {
LoggerFactory.getLogger(AppIndicator.class).debug("Error loading GTK3 library name '{}'. {}", libraryName, e.getMessage()); LoggerFactory.getLogger(AppIndicator.class).debug("Error loading GTK3 library name '{}'.", libraryName, e);
} }
} }
} }
@ -112,12 +110,7 @@ class AppIndicator {
} }
// We can fall back to GtkStatusIndicator or Swing if this cannot load // We can fall back to GtkStatusIndicator or Swing if this cannot load
if (shouldLoadAppIndicator && _isLoaded) { isLoaded = shouldLoadAppIndicator && _isLoaded;
isLoaded = true;
}
else {
isLoaded = false;
}
} }
// Note: AppIndicators DO NOT support tooltips, as per mark shuttleworth. Rather stupid IMHO. // Note: AppIndicators DO NOT support tooltips, as per mark shuttleworth. Rather stupid IMHO.
@ -126,52 +119,54 @@ class AppIndicator {
public static public static
String getInstallString(boolean isGtk2) { String getInstallString(boolean isGtk2) {
Type packageManager = PackageManager.get();
// ARCH // ARCH
// requires the install of libappindicator which is GTK2 (as of 25DEC2016) // requires the install of libappindicator which is GTK2 (as of 25DEC2016)
// requires the install of libappindicator3 which is GTK3 (as of 25DEC2016) // requires the install of libappindicator3 which is GTK3 (as of 25DEC2016)
// FEDORA // FEDORA
// appindicator-gtk // libappindicator-gtk
// appindicator-gtk3 // libappindicator-gtk3
// ARCH
// libappindicator-gtk2
// libappindicator-gtk3
// Debian based // Debian based
// libappindicator // libappindicator
// libappindicator3 (or 3-1) // libappindicator3 (or 3-1)
String packageName;
if (isGtk2) { if (isGtk2) {
if (OSUtil.Linux.isDebian()) { if (OSUtil.Linux.isDebian()) {
// debian is slightly different // debian is slightly different
packageName = "libappindicator1"; return "libappindicator1";
} }
else if (OSUtil.Linux.isFedora()) { else if (OSUtil.Linux.isFedora()) {
packageName = "libappindicator-gtk"; return "libappindicator-gtk";
}
else if (OSUtil.Linux.isArch()) {
return "libappindicator-gtk2";
} }
else { else {
packageName = "libappindicator"; return "libappindicator";
} }
} else { } else {
if (OSUtil.Linux.isDebian()) { if (OSUtil.Linux.isDebian()) {
// debian is slightly different // debian is slightly different
packageName = "libappindicator3-1"; return "libappindicator3-1";
} }
else if (OSUtil.Linux.isFedora()) { else if (OSUtil.Linux.isFedora()) {
packageName = "libappindicator-gtk3"; return "libappindicator-gtk3";
}
else if (OSUtil.Linux.isArch()) {
return "libappindicator-gtk3";
} }
else { else {
packageName = "libappindicator3"; return "libappindicator3";
} }
} }
return "Please install " + packageName + ", for example: '" + packageManager.installString() + " " + packageName + "'.";
} }
public static final int CATEGORY_APPLICATION_STATUS = 0; public static final int CATEGORY_APPLICATION_STATUS = 0;
// public static final int CATEGORY_COMMUNICATIONS = 1; // public static final int CATEGORY_COMMUNICATIONS = 1;
// public static final int CATEGORY_SYSTEM_SERVICES = 2; // public static final int CATEGORY_SYSTEM_SERVICES = 2;