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(currently hardcoded, should use platform plugin) - 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"To register custom URI schemes, create a LinkHandler plugin:
package com.example;
import org.scijava.desktop.links.AbstractLinkHandler;
import org.scijava.desktop.links.LinkHandler;
import org.scijava.desktop.links.Links;
import org.scijava.plugin.Plugin;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Plugin(type = LinkHandler.class)
public class MyAppLinkHandler extends AbstractLinkHandler {
@Override
public boolean supports(final URI uri) {
return "myapp".equals(uri.getScheme());
}
@Override
public void handle(final URI uri) {
// Parse the URI
String operation = Links.operation(uri);
Map<String, String> params = Links.query(uri);
// Your business logic here
System.out.println("Operation: " + operation);
System.out.println("Parameters: " + params);
}
@Override
public List<String> getSchemes() {
// This tells DefaultLinkService to register "myapp://" with Windows
return Arrays.asList("myapp");
}
}- 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().
Issue: WindowsPlatform (lines 86, 102) currently hardcodes the "fiji" scheme instead of querying registered LinkHandler plugins.
Impact: Only works for Fiji; breaks for other applications.
Workaround: None; requires code fix.
Fix: See NEXT.md Work Item #1 for the solution.
Issue: DefaultLinkService.createInstaller() (lines 119-132) hardcodes OS name checks instead of using PlatformService.
Impact: Violates plugin architecture.
Workaround: None; requires code fix.
Fix: See NEXT.md Work Items #2 and #3 for the solution.
| 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 | Planned (Registry) | Planned (.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 - Does not expose arbitrary command execution
The %1 parameter in the registry command is properly quoted:
"C:\Path\To\App.exe" "%1"
This prevents command-line injection attacks via malicious URIs.
- Start Menu Shortcut: Implement desktop icon creation
- File Extension Registration: Register file types in the registry
- 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 schemes and file types
- NEXT.md - Planned improvements
- spec/DESKTOP_INTEGRATION_PLAN.md - Architecture overview
- spec/IMPLEMENTATION_SUMMARY.md - Implementation details