diff --git a/client/src/app/settings/settings.component.html b/client/src/app/settings/settings.component.html
index 287c23c..7b3c537 100644
--- a/client/src/app/settings/settings.component.html
+++ b/client/src/app/settings/settings.component.html
@@ -142,13 +142,25 @@
-
-
-
-
-
This will register the client as your browser's default handler for magnet links. Clicking a magnet link will automatically open it in the new torrent screen for downloading.
+
+
+
+
+
+ {{
+ canRegisterMagnetHandler
+ ? "This will attempt to register the client as your browser's default handler for magnet links and automatically open them in the new torrent screen for downloading."
+ : "Magnet link registration is unavailable because either your browser does not support it or the client is not being served to you in a secure context."
+ }}
+
diff --git a/client/src/app/settings/settings.component.ts b/client/src/app/settings/settings.component.ts
index 4f71f5e..1d8f946 100644
--- a/client/src/app/settings/settings.component.ts
+++ b/client/src/app/settings/settings.component.ts
@@ -28,10 +28,13 @@ export class SettingsComponent implements OnInit {
public testAria2cConnectionError: string = null;
public testAria2cConnectionSuccess: string = null;
+ public canRegisterMagnetHandler = false;
+
constructor(private settingsService: SettingsService) {}
ngOnInit(): void {
this.reset();
+ this.canRegisterMagnetHandler = !!(window.isSecureContext && 'registerProtocolHandler' in navigator);
}
public reset(): void {
@@ -139,20 +142,13 @@ export class SettingsComponent implements OnInit {
},
);
}
-
+
public registerMagnetHandler(): void {
- if (window.location.protocol !== "https:") {
- alert("Magnet link handler registration requires a secure connection. Please ensure the client is being served over HTTPS to enable this feature.");
- return;
- }
-
- const handlerUrl = `${window.location.origin}/add?magnet=%s`;
-
- if (navigator.registerProtocolHandler) {
- navigator.registerProtocolHandler("magnet", handlerUrl);
- alert("Your browser will display a prompt asking if you'd like to add the client as the default application for magnet links. Please confirm to complete the setup.");
- } else {
- alert("Magnet link registration failed. Your browser does not support registering custom protocol handlers.");
+ try {
+ navigator.registerProtocolHandler("magnet", `${window.location.origin}/add?magnet=%s`);
+ alert("Success! Your browser will now prompt you to confirm and add the client as the default handler for magnet links.");
+ } catch (error) {
+ alert("Magnet link registration failed.");
}
}
}