forked from transmission-remote-gui/transgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urllistenerosx.pas
47 lines (36 loc) · 1.19 KB
/
urllistenerosx.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
unit URLListenerOSX;
{$mode objfpc}{$H+}
{$modeswitch objectivec2}
interface
uses
Classes, SysUtils, CocoaAll, InternetConfig, AppleEvents;
type
THandlerProc = procedure(const url: string);
{ TAppURLHandler }
TAppURLHandler = objcclass(NSObject)
public
procedure getUrlwithReplyEvent(event: NSAppleEventDescriptor; eventReply: NSAppleEventDescriptor); message 'getUrl:withReplyEvent:';
public
callBack: THandlerProc;
end;
procedure RegisterURLHandler(HandlerProc: THandlerProc);
var
handler : TAppURLHandler;
eventManager: NSAppleEventManager;
implementation
{ TAppURLHandler }
procedure TAppURLHandler.getUrlwithReplyEvent(event: NSAppleEventDescriptor; eventReply: NSAppleEventDescriptor);
var
url : NSString;
begin
url:=event.paramDescriptorForKeyword(keyDirectObject).stringValue;
callBack(url.UTF8String);
end;
procedure RegisterURLHandler(HandlerProc: THandlerProc);
begin
handler:=TAppURLHandler.alloc.init;
handler.callBack:=HandlerProc;
eventManager:=NSAppleEventManager.sharedAppleEventManager;
eventManager.setEventHandler_andSelector_forEventClass_andEventID(handler,ObjCSelector(handler.getUrlwithReplyEvent), kInternetEventClass,kAEGetURL);
end;
end.