-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from JabRef/win-pintaskbar
Extracted native Windows logic and fixed #194
- Loading branch information
Showing
5 changed files
with
73 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/net/sf/jabref/gui/nativeext/WindowsExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.sf.jabref.gui.nativeext; | ||
|
||
import com.sun.jna.Native; | ||
import com.sun.jna.NativeLong; | ||
import com.sun.jna.Pointer; | ||
import com.sun.jna.WString; | ||
import com.sun.jna.ptr.PointerByReference; | ||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.logic.util.OS; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
/** | ||
* Native extensions for Windows. | ||
*/ | ||
public class WindowsExtensions { | ||
private static final Log LOGGER = LogFactory.getLog(WindowsExtensions.class); | ||
|
||
// Register native calls for pin to taskbar functionality | ||
static { | ||
if (OS.WINDOWS) { | ||
Native.register("shell32"); | ||
LOGGER.info("Registered Shell32 DLL"); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the application user model id so that JabRef can be pinned to the taskbar | ||
* Only supported by Windows 7 and up! | ||
* | ||
* AppUserModelId must also be set in NSIS setup.nsi | ||
* WinShell::SetLnkAUMI "$INSTDIR\$(^Name).lnk" "${AppUserModelId}" | ||
* Structure: JabRef.${VERSION} | ||
* | ||
* Based on http://stackoverflow.com/a/1928830 | ||
* http://stackoverflow.com/questions/5438651/launch4j-nsis-and-duplicate-pinned-windows-7-taskbar-icons | ||
*/ | ||
public static void enablePinToTaskbar() { | ||
if(supportsPinToTaskbar()) { | ||
setCurrentProcessExplicitAppUserModelID("JabRef." + Globals.BUILD_INFO.getVersion()); | ||
} else { | ||
LOGGER.info("Does not support pin to taskbar."); | ||
} | ||
} | ||
|
||
private static void setCurrentProcessExplicitAppUserModelID(final String appID) { | ||
if (SetCurrentProcessExplicitAppUserModelID(new WString(appID)).longValue() != 0) { | ||
throw new RuntimeException("unable to set current process explicit AppUserModelID to: " + appID); | ||
} | ||
} | ||
|
||
private static native NativeLong SetCurrentProcessExplicitAppUserModelID(WString appID); | ||
|
||
private static boolean supportsPinToTaskbar() { | ||
if (!OS.WINDOWS) { | ||
return false; | ||
} | ||
|
||
try { | ||
Float version = Float.parseFloat(System.getProperty("os.version")); | ||
// Windows 7 == 6.1 | ||
return version >= 6.1; | ||
} catch (NumberFormatException ex) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters