Skip to content

Commit 0a673f1

Browse files
committed
Include swift code.
1 parent f7f42f1 commit 0a673f1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/swift
2+
3+
import Foundation
4+
import Cocoa
5+
6+
func getArgument() -> String? {
7+
if (2 > CommandLine.arguments.count) {
8+
return nil;
9+
}
10+
else {
11+
return CommandLine.arguments[1];
12+
}
13+
}
14+
15+
let command = getArgument() ?? "null";
16+
17+
switch command {
18+
19+
case "-register":
20+
let currentHandler = LSCopyDefaultHandlerForURLScheme("magnet" as CFString)!.takeUnretainedValue() as String;
21+
22+
if ("org.deluge.magneturihandler" != currentHandler) {
23+
LSSetDefaultHandlerForURLScheme("magnet" as CFString, "org.deluge.magneturihandler" as CFString);
24+
}
25+
else {
26+
print("MagnetURIHandler is already registered to handle magnets.");
27+
}
28+
29+
case "-check":
30+
31+
let currentHandler = LSCopyDefaultHandlerForURLScheme("magnet" as CFString)!.takeUnretainedValue() as String;
32+
print(currentHandler);
33+
34+
default:
35+
print ("Usage: magnetHandler <command>, where <command> is one of:\n\n\t-register\t\t\t (Register MagnetURIHandler as the default handler for magnet:// URIs.)\n\t-check\t\t\t\t (Prints the bundle id for the application currently registered to handle magnet URIs)\n\nmagnetHandler with ether an invalid <command> or without arguments will print this message.");
36+
37+
}

0 commit comments

Comments
 (0)