fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 133 forks source link

could the icons of several running instances of the application be grouped on the deskbar? #320

Closed kia closed 1 year ago

kia commented 1 year ago

I'm submitting a… question

could the icons of several running instances of the application be grouped on the desk-bar?

Is it possible to group the icons created on desk when a javafx application is started several times? currently the icons are shown separately.

fvarrui commented 1 year ago

Hi @kia! Are you asking about Windows?

kia commented 1 year ago

Hi @fvarrui,

i see this behavior also on a linux machine but in the first place we would need it for windows.

fvarrui commented 1 year ago

Ok, I guess you are using winConfig.exeCreationTool=launch4j since it's the only option that doesn't group icons on the Windows task bar. You should know that winrun4j and why group app icons without any problem and no extra configuration.

But, if you want to keep using launch4j, I couldn't figure out how JP can help you, but you can use JNA (Java Native Interface) to do the trick (as is explained here):

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>5.13.0</version>
</dependency>
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.WString;

public class Main {

    private static native NativeLong SetCurrentProcessExplicitAppUserModelID(WString appID);

    static {
        Native.register("shell32");
    }

    public static void main(String[] args) throws IOException {
        String appID = Main.class.getName(); // here you can use whatever id you want, but it has to be unique
        if (SetCurrentProcessExplicitAppUserModelID(new WString(appID)).longValue() != 0) {
            throw new RuntimeException("Unable to set current process explicit AppUserModelID to: " + appID);
        }
        // start your app here
    }

}   

And that's all! This works for me.

I guess it goes without saying that if your app is cross-platform, this Main class only works on Windows, so you need a different one for Linux and/or Mac OS.

I hope it helps!

kia commented 1 year ago

Thank you very much @fvarrui . It works. I added some code to avoid conflicts related to our Linux build.


static {
    if (System.getProperty("os.name").startsWith("Windows")) {
         Native.register("shell32");
    }
}

public static void main(String[] args) throws IOException {
   if (System.getProperty("os.name").startsWith("Windows")) {
          String appID = "Unique-App-Name";
          if (SetCurrentProcessExplicitAppUserModelID(new WString(appID)).longValue() != 0) {
              throw new RuntimeException("Unable to set current process explicit AppUserModelID to: " + appID);
          }
   }