Play with System.AppUserModel.ID (Windows 7 integration)

This commit is contained in:
Reinhard Pointner 2016-07-13 22:02:33 +08:00
parent 400166132f
commit 860ce15322
5 changed files with 68 additions and 6 deletions

View File

@ -32,11 +32,13 @@
<File Id='filebot.launcher.exe' Name='filebot.launcher.exe' Source='filebot.launcher.exe' KeyPath='yes'> <File Id='filebot.launcher.exe' Name='filebot.launcher.exe' Source='filebot.launcher.exe' KeyPath='yes'>
<Shortcut Id="shortcut.menu.filebot" Directory="ProgramMenuDir" Name="FileBot" Description="The ultimate TV Renamer and Subtitle Downloader" WorkingDirectory='INSTALLDIR' Icon="icon.ico" Advertise="no"> <Shortcut Id="shortcut.menu.filebot" Directory="ProgramMenuDir" Name="FileBot" Description="The ultimate TV Renamer and Subtitle Downloader" WorkingDirectory='INSTALLDIR' Icon="icon.ico" Advertise="no">
<ShortcutProperty Key="System.AppUserModel.ID" Value="net.filebot.FileBot" /> <ShortcutProperty Key="System.AppUserModel.ID" Value="net.filebot.FileBot" />
<ShortcutProperty Key="System.AppUserModel.RelaunchCommand" Value="[INSTALLDIR]filebot.launcher.exe" />
<ShortcutProperty Key="System.AppUserModel.RelaunchDisplayNameResource" Value="FileBot" />
</Shortcut> </Shortcut>
<Shortcut Id="shortcut.desktop" Directory="DesktopFolder" Name="FileBot" Description="The ultimate TV Renamer and Subtitle Downloader" WorkingDirectory='INSTALLDIR' Icon="icon.ico" Advertise="no" /> <Shortcut Id="shortcut.desktop" Directory="DesktopFolder" Name="FileBot" Description="The ultimate TV Renamer and Subtitle Downloader" WorkingDirectory='INSTALLDIR' Icon="icon.ico" Advertise="no">
<Shortcut Id="shortcut.sendto" Directory="SendToFolder" Name="FileBot" Description="The ultimate TV Renamer and Subtitle Downloader" WorkingDirectory='INSTALLDIR' Icon="icon.ico" Advertise="no" /> <ShortcutProperty Key="System.AppUserModel.ID" Value="net.filebot.FileBot" />
</Shortcut>
<Shortcut Id="shortcut.sendto" Directory="SendToFolder" Name="FileBot" Description="The ultimate TV Renamer and Subtitle Downloader" WorkingDirectory='INSTALLDIR' Icon="icon.ico" Advertise="no">
<ShortcutProperty Key="System.AppUserModel.ID" Value="net.filebot.FileBot" />
</Shortcut>
</File> </File>
<File Id='filebot.platform.launcher.exe' Name='filebot.platform.launcher.exe' Source='filebot.platform.launcher.exe'> <File Id='filebot.platform.launcher.exe' Name='filebot.platform.launcher.exe' Source='filebot.platform.launcher.exe'>
<Shortcut Id="shortcut.menu.filebot.platform" Directory="ProgramMenuDir" Name="FileBot (platform)" Description="Launch FileBot with platform-independent configuration" WorkingDirectory='INSTALLDIR' Icon="icon.ico" IconIndex="0" Advertise="no" /> <Shortcut Id="shortcut.menu.filebot.platform" Directory="ProgramMenuDir" Name="FileBot (platform)" Description="Launch FileBot with platform-independent configuration" WorkingDirectory='INSTALLDIR' Icon="icon.ico" IconIndex="0" Advertise="no" />

View File

@ -56,6 +56,7 @@ import net.filebot.ui.transfer.FileTransferable;
import net.filebot.util.PreferencesMap.PreferencesEntry; import net.filebot.util.PreferencesMap.PreferencesEntry;
import net.filebot.util.TeePrintStream; import net.filebot.util.TeePrintStream;
import net.filebot.util.ui.SwingEventBus; import net.filebot.util.ui.SwingEventBus;
import net.filebot.win.WinAppUtilities;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
public class Main { public class Main {
@ -229,7 +230,7 @@ public class Main {
// configure main window // configure main window
if (isMacApp()) { if (isMacApp()) {
// Mac OS X specific configuration // Mac specific configuration
MacAppUtilities.initializeApplication(); MacAppUtilities.initializeApplication();
MacAppUtilities.setWindowCanFullScreen(frame); MacAppUtilities.setWindowCanFullScreen(frame);
MacAppUtilities.setDefaultMenuBar(FileBotMenuBar.createHelp()); MacAppUtilities.setDefaultMenuBar(FileBotMenuBar.createHelp());
@ -242,8 +243,12 @@ public class Main {
frame.setJMenuBar(FileBotMenuBar.createHelp()); frame.setJMenuBar(FileBotMenuBar.createHelp());
} }
frame.setIconImages(ResourceManager.getApplicationIcons()); 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 { } else {
// Windows / Linux specific configuration // generic Linux/FreeBSD/Solaris configuration
frame.setIconImages(ResourceManager.getApplicationIcons()); frame.setIconImages(ResourceManager.getApplicationIcons());
} }

View File

@ -90,6 +90,10 @@ public final class Settings {
return isApplicationDeployment("mas", "usc"); return isApplicationDeployment("mas", "usc");
} }
public static boolean isWindowsApp() {
return isApplicationDeployment("msi");
}
public static boolean isUbuntuApp() { public static boolean isUbuntuApp() {
return isApplicationDeployment("usc"); return isApplicationDeployment("usc");
} }

View File

@ -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);
}

View File

@ -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;
}
}