From 860ce153227e18c51a1950525793b8e63a48fe3d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 13 Jul 2016 22:02:33 +0800 Subject: [PATCH] Play with System.AppUserModel.ID (Windows 7 integration) --- installer/msi/filebot-wix.xml | 10 +++--- source/net/filebot/Main.java | 9 ++++-- source/net/filebot/Settings.java | 4 +++ source/net/filebot/win/Shell32.java | 17 +++++++++++ source/net/filebot/win/WinAppUtilities.java | 34 +++++++++++++++++++++ 5 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 source/net/filebot/win/Shell32.java create mode 100644 source/net/filebot/win/WinAppUtilities.java diff --git a/installer/msi/filebot-wix.xml b/installer/msi/filebot-wix.xml index 74ba9324..78a5f0d7 100644 --- a/installer/msi/filebot-wix.xml +++ b/installer/msi/filebot-wix.xml @@ -32,11 +32,13 @@ - - - - + + + + + + diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index ee5f0175..e5dd774b 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -56,6 +56,7 @@ import net.filebot.ui.transfer.FileTransferable; import net.filebot.util.PreferencesMap.PreferencesEntry; import net.filebot.util.TeePrintStream; import net.filebot.util.ui.SwingEventBus; +import net.filebot.win.WinAppUtilities; import net.miginfocom.swing.MigLayout; public class Main { @@ -229,7 +230,7 @@ public class Main { // configure main window if (isMacApp()) { - // Mac OS X specific configuration + // Mac specific configuration MacAppUtilities.initializeApplication(); MacAppUtilities.setWindowCanFullScreen(frame); MacAppUtilities.setDefaultMenuBar(FileBotMenuBar.createHelp()); @@ -242,8 +243,12 @@ public class Main { frame.setJMenuBar(FileBotMenuBar.createHelp()); } frame.setIconImages(ResourceManager.getApplicationIcons()); + } else if (isWindowsApp()) { + // Windows specific configuration + WinAppUtilities.setAppUserModelID("net.filebot.FileBot"); // support Windows 7 taskbar behaviours + frame.setIconImages(ResourceManager.getApplicationIcons()); } else { - // Windows / Linux specific configuration + // generic Linux/FreeBSD/Solaris configuration frame.setIconImages(ResourceManager.getApplicationIcons()); } diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index 3188b2b8..5b2ecdc5 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -90,6 +90,10 @@ public final class Settings { return isApplicationDeployment("mas", "usc"); } + public static boolean isWindowsApp() { + return isApplicationDeployment("msi"); + } + public static boolean isUbuntuApp() { return isApplicationDeployment("usc"); } diff --git a/source/net/filebot/win/Shell32.java b/source/net/filebot/win/Shell32.java new file mode 100644 index 00000000..c9809aad --- /dev/null +++ b/source/net/filebot/win/Shell32.java @@ -0,0 +1,17 @@ +package net.filebot.win; + +import com.sun.jna.Native; +import com.sun.jna.NativeLong; +import com.sun.jna.WString; +import com.sun.jna.ptr.PointerByReference; +import com.sun.jna.win32.StdCallLibrary; +import com.sun.jna.win32.W32APIOptions; + +interface Shell32 extends StdCallLibrary { + + Shell32 INSTANCE = (Shell32) Native.loadLibrary("shell32", Shell32.class, W32APIOptions.DEFAULT_OPTIONS); + + NativeLong SetCurrentProcessExplicitAppUserModelID(WString appID); + + NativeLong GetCurrentProcessExplicitAppUserModelID(PointerByReference appID); +} diff --git a/source/net/filebot/win/WinAppUtilities.java b/source/net/filebot/win/WinAppUtilities.java new file mode 100644 index 00000000..fca6b157 --- /dev/null +++ b/source/net/filebot/win/WinAppUtilities.java @@ -0,0 +1,34 @@ +package net.filebot.win; + +import static net.filebot.Logging.*; + +import java.util.logging.Level; + +import com.sun.jna.Pointer; +import com.sun.jna.WString; +import com.sun.jna.ptr.PointerByReference; + +public class WinAppUtilities { + + public static void setAppUserModelID(String appID) { + try { + Shell32.INSTANCE.SetCurrentProcessExplicitAppUserModelID(new WString(appID)); + } catch (Throwable t) { + debug.log(Level.WARNING, t.getMessage(), t); + } + } + + public static String getAppUserModelID() { + try { + PointerByReference r = new PointerByReference(); + if (Shell32.INSTANCE.GetCurrentProcessExplicitAppUserModelID(r).longValue() != 0) { + Pointer p = r.getPointer(); + return p.getWideString(0); // LEAK NATIVE MEMORY + } + } catch (Throwable t) { + debug.log(Level.WARNING, t.getMessage(), t); + } + return null; + } + +}