javawindowsloadingtaskbarbridj

Bridj no longer working for Windows taskbar loading


I've been using code to make the taskbar icon of my Java application have a loading bar feature which is native to Windows 7+ applications. The code I use is the following:

import lombok.val;
import org.bridj.Pointer;
import org.bridj.cpp.com.COMRuntime;
import org.bridj.cpp.com.shell.ITaskbarList3;

import java.awt.*;

import static org.apache.commons.lang3.SystemUtils.*;
import static org.bridj.Pointer.pointerToAddress;
import static org.bridj.jawt.JAWTUtils.getNativePeerHandle;

public class WindowsTaskBarProgress
{
    private ITaskbarList3 taskBarList3;
    private Pointer<Integer> pointer;
    private long maximum;

    public WindowsTaskBarProgress(Component component) throws ClassNotFoundException
    {
        if (isSupportedPlatform())
        {
            taskBarList3 = COMRuntime.newInstance(ITaskbarList3.class);
            val nativePeerHandle = getNativePeerHandle(component); // <- The error arises here
            Pointer.Releaser release = pointer -> {
            };

            pointer = pointerToAddress(nativePeerHandle, Integer.class, release);
        }

        this.maximum = 100;
    }

    public void setProgressValue(long value)
    {
        if (isSupportedPlatform())
        {
            taskBarList3.SetProgressValue(pointer, value, maximum);
        }
    }

    public void resetProgress()
    {
        setProgressValue(0);
    }

    /*public void setProgressFlag(ITaskbarList3.TbpFlag flag)
    {
        if (isSupportedPlatform())
        {
            taskBarList3.SetProgressState(pointer, flag);
        }
    }*/

    private static boolean isSupportedPlatform()
    {
        return IS_OS_WINDOWS_7
                || IS_OS_WINDOWS_8
                || IS_OS_WINDOWS_10;
    }

    public void setMaximum(long maximum)
    {
        this.maximum = maximum;
    }
}

An SSCCE can be found here.

The maven dependencies I use are:

<!-- Windows 7+ task bar progress bar -->
<dependency>
    <groupId>com.nativelibs4java</groupId>
    <!-- https://github.com/nativelibs4java/BridJ -->
    <artifactId>bridj</artifactId>
    <version>0.7.0</version>
</dependency>
<dependency>
    <!-- https://github.com/java-native-access/jna -->
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>5.3.1</version>
</dependency>
<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna-platform</artifactId>
    <version>5.3.1</version>
</dependency>

However, I'm getting the following error:

java.lang.UnsatisfiedLinkError: org.bridj.jawt.JawtLibrary.JAWT_GetAWT(Lorg/bridj/Pointer;Lorg/bridj/Pointer;)Z
    at org.bridj.jawt.JawtLibrary.JAWT_GetAWT(Native Method)
    at org.bridj.jawt.JAWTUtils.getJAWT(JAWTUtils.java:66)
    at org.bridj.jawt.JAWTUtils.getNativePeerHandle(JAWTUtils.java:129)

Note that I tried an older JNA version like 4.1.0 as well and it yielded the same error. What exactly broke and how can it be fixed?


Solution

  • Somehow I missed the solution which was right in the example file via comment on this line: https://github.com/nativelibs4java/BridJ/blob/master/src/main/demos/TaskbarListDemo.java#L99

    Replacing the getNativePeerHandle() call with getComponentID() did the trick.