java.lang.Object
org.klomp.snark.web.BrowserApiInstaller
Registers the browser protocol/file handler that forwards magnet links and torrent files to the I2PSnark browser API (POST /i2psnark/_add).
No shell script is involved: the registered command is the router's own JVM running MagnetHandler with the console URL baked in, so it keeps working across console port or HTTPS changes made before installation.
Linux: writes a .desktop file and registers it in mimeapps.list, which xdg-open, Firefox, and Chromium-based browsers honor.
Windows: writes per-user HKCU\Software\Classes registry entries for the magnet: scheme and the .torrent file type (no admin rights needed).
macOS: not supported (LaunchServices has no CLI scheme registration).
Field Summary
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNot called, the installer class is never instantiated.Method Summary
Modifier and TypeMethodDescriptionprivate static StringbuildCommand(String consoleBaseUrl, boolean uriPlaceholder) The command template used by the OS registration, e.g.private static StringThe jar (or classes dir) that contains MagnetHandler, resolved from its code source so no shell quoting or path guessing is needed.static StringRegister the browser handler pointing at the given console base URL, e.g.static StringinstallLinux(String consoleBaseUrl, File home) Linux registration with an explicit home directory (testable).private static StringinstallWindows(String consoleBaseUrl) Builds the Windows registry script for the handlers.private static StringThe java binary that launched this router, or javaw on Windows.private static StringJoins the lines with newlines.private static voidupdateMimeapps(File file, String... mimes) Add or update the two MIME registrations in the [Default Applications] section of mimeapps.list, preserving everything else.private static voidWrites the text to the file.
Field Details
DESKTOP_ID
Base name of the generated XDG .desktop file, also the MIME cache entry key.- See Also:
MAGNET_MIME
Mime type of the magnet scheme handler.- See Also:
TORRENT_MIME
Mime type of the torrent files.- See Also:
Constructor Details
BrowserApiInstaller
private BrowserApiInstaller()Not called, the installer class is never instantiated.
Method Details
install
Register the browser handler pointing at the given console base URL, e.g. http://127.0.0.1:7657/i2psnark (no trailing slash).- Parameters:
consoleBaseUrl- base URL of the I2PSnark webapp- Returns:
- a human-readable result message
- Throws:
IOException- on any failure
installLinux
Linux registration with an explicit home directory (testable).- Parameters:
consoleBaseUrl- base URL of the I2PSnark webapphome- the user home dir, e.g.System.getProperty(String)"user.home")- Returns:
- a human-readable result message
- Throws:
IOException- on any failure
javaBinary
The java binary that launched this router, or javaw on Windows.- Returns:
- the absolute path to the java executable for this OS
handlerClasspath
The jar (or classes dir) that contains MagnetHandler, resolved from its code source so no shell quoting or path guessing is needed.- Returns:
- the absolute path of that jar or classes directory
- Throws:
IOException- if the code source location is missing or is not a usable URI
buildCommand
private static String buildCommand(String consoleBaseUrl, boolean uriPlaceholder) throws IOException The command template used by the OS registration, e.g. "java" -cp "i2psnark.jar" org.klomp.snark.MagnetHandler --url "base" %u.- Parameters:
consoleBaseUrl- the console URL passed to the handler as --urluriPlaceholder- true to append the %u desktop placeholder, false for the "%1" shell argument- Returns:
- the command template string for the desktop entry
- Throws:
IOException- if the MagnetHandler classpath cannot be located
writeFile
Writes the text to the file.- Parameters:
f- the file to writecontent- the text to write- Throws:
IOException- if the writing fails
updateMimeapps
Add or update the two MIME registrations in the [Default Applications] section of mimeapps.list, preserving everything else.- Parameters:
file- the mimeapps.list to update, created with its parents if absentmimes- the MIME types to point at the desktop entry- Throws:
IOException- if the parent directories cannot be created or the file cannot be read
join
installWindows
Builds the Windows registry script for the handlers.- Parameters:
consoleBaseUrl- the URL of the console- Returns:
- the script text
- Throws:
IOException- if the files cannot be written