This document describes how desktop integration works on Windows in scijava-desktop.
The scijava-desktop component automatically registers URI schemes with Windows when a SciJava application starts. The registration is done via the Windows Registry and requires no administrator privileges.
When the application starts:
DefaultLinkServiceinitializes and listens forContextCreatedEvent- Collects all URI schemes from registered
LinkHandlerplugins viagetSchemes() - Reads the executable path from the
scijava.app.executablesystem property - Creates a
WindowsSchemeInstaller - Registers each scheme in the Windows Registry
For a scheme named myapp, the following registry structure is created under HKEY_CURRENT_USER:
HKEY_CURRENT_USER\Software\Classes\myapp
(Default) = "URL:myapp"
URL Protocol = ""
shell\
open\
command\
(Default) = "C:\Path\To\App.exe" "%1"
Key: HKEY_CURRENT_USER\Software\Classes\<scheme>
Reason: Using HKEY_CURRENT_USER (HKCU) instead of HKEY_LOCAL_MACHINE (HKLM) means:
- No administrator rights required
- Registration is per-user (not system-wide)
- Safe for non-privileged users
The WindowsSchemeInstaller class provides the platform-specific implementation:
Methods:
isSupported()- Returns true on Windows platformsinstall(scheme, executablePath)- Registers a URI schemeisInstalled(scheme)- Checks if a scheme is already registeredgetInstalledPath(scheme)- Gets the executable path for a registered schemeuninstall(scheme)- Removes a URI scheme registration
Implementation Approach:
- Uses the
regcommand-line tool (built into Windows) - No JNA dependency required
- Executed via
ProcessBuilderwith proper timeout (10 seconds) - Robust error handling and validation
Add a scheme:
reg add "HKCU\Software\Classes\myapp" /ve /d "URL:myapp" /f
reg add "HKCU\Software\Classes\myapp" /v "URL Protocol" /d "" /f
reg add "HKCU\Software\Classes\myapp\shell\open\command" /ve /d "\"C:\Path\To\App.exe\" \"%1\"" /fCheck if a scheme exists:
reg query "HKCU\Software\Classes\myapp\shell\open\command" /veDelete a scheme:
reg delete "HKCU\Software\Classes\myapp" /fApplications must set the scijava.app.executable system property for URI scheme registration to work:
java -Dscijava.app.executable="C:\Program Files\MyApp\MyApp.exe" -jar myapp.jarImportant: The path should point to the actual executable (.exe file) that Windows should launch when a URI is clicked.
For Windows applications with a native launcher:
@echo off
set JAVA_HOME=C:\Program Files\Java\jdk-11
set APP_HOME=%~dp0
"%JAVA_HOME%\bin\java.exe" ^
-Dscijava.app.executable="%APP_HOME%\MyApp.exe" ^
-jar "%APP_HOME%\lib\myapp.jar"- User installs and launches the application
- Application automatically registers URI schemes with Windows
- User clicks a
myapp://action?param=valuelink in their browser - Windows launches the application with the URI as a command-line argument
LinkArgumentplugin parses the URI and passes it toLinkServiceLinkServiceroutes the URI to the appropriateLinkHandler- Handler processes the request
Users can manage URI scheme registration via Edit > Options > Desktop...:
- Enable web links: Toggleable checkbox to register/unregister URI schemes
- State is queried from the actual Windows Registry (not saved to preferences)
- Changes apply immediately to the registry
Status: Not yet implemented
Planned Implementation:
- Create Start Menu shortcut (.lnk file)
- Location:
%APPDATA%\Microsoft\Windows\Start Menu\Programs\<AppName>.lnk - Use JNA or native executable for .lnk creation
- Toggle via OptionsDesktop UI
Check Registry:
- Launch your application
- Open
regedit - Navigate to
HKEY_CURRENT_USER\Software\Classes\myapp - Verify the structure matches the expected format
Test URI Handling:
- Create an HTML file with a link:
<a href="myapp://test">Test Link</a> - Open the HTML file in a browser
- Click the link
- Verify your application launches and handles the URI
Test from Command Line:
start myapp://test?param=valueRun Windows-specific tests:
mvn test -Dtest=WindowsSchemeInstallerTestTests automatically skip on non-Windows platforms using JUnit's Assume.assumeTrue().
| Feature | Windows | Linux | macOS |
|---|---|---|---|
| URI Scheme Registration | Runtime (Registry) | Runtime (.desktop file) | Build-time (Info.plist) |
| Admin Rights Required | No (HKCU) | No (user .desktop file) | N/A (bundle) |
| Toggleable at Runtime | Yes | Yes | No (read-only) |
| Desktop Icon | Planned (Start Menu) | Yes (.desktop file) | No (user pins to Dock) |
| File Extensions | Yes (Registry) | Yes (.desktop MIME types) | Build-time (Info.plist) |
Unlike macOS (where the .app bundle is code-signed and immutable), Windows allows runtime modification of the registry without special privileges. This makes it practical to register URI schemes when the application first runs, similar to how many Windows applications work.
- Only writes to
HKEY_CURRENT_USER(per-user settings) - Does not modify system-wide settings in
HKEY_LOCAL_MACHINE - Only registers URI schemes declared by
LinkHandlerplugins - Uses proper quoting to avoid exposing arbitrary command execution
- Start Menu Shortcut: Implement desktop icon creation
- Scheme Validation: Validate scheme names against RFC 3986
- User Prompts: Optional confirmation before registering schemes
- Uninstallation: Automatic cleanup on application uninstall
- Icon Support: Associate icons with file type registrations