AEInstallEventHandler handler not being called on startup
Asked Answered
W

1

1

I've installed a Apple Event handler for URL's in my app:

OSStatus e = AEInstallEventHandler( kInternetEventClass,
                            kAEGetURL,
                            NewAEEventHandlerUPP(AppleEventProc),
                            (SRefCon)this,
                            false);

And that works if my application is running. However if my app is NOT running, clicking a URL in a browser starts the application but no Apple Event is received on my handler. My call to AEInstallEventHandler is during my app's startup phase, before it reaches the message loop. It's not the very first thing I do, but not too far off it. (Obviously I've setup the plist correctly, as I'm getting events while running)

Any ideas on how to get this working?

Interestingly when Chrome starts my to handle a mailto URL it passes "-psn_0_5100765" on the command line. Which doesn't mean anything to me, does anyone know what it's trying to tell me?

Note: I've setup Apple Event debugging and run it again. I'm definitely getting sent a GURL event on startup, after I have installed the callback handler. However I still can't work out why my callback is not called with that Event.

Wrongheaded answered 25/11, 2011 at 6:29 Comment(4)
are you writing a new Carbon app? Why??!? Anyways... is there any way you can put your AEInstallEventHandler in the functions that get called as the app starts up? (the idea being that the handler is in place before Carbon events get processed and the Apple Event gets popped away without a handler)Headroom
The handler is installed during the creation of my first object, and definitely before the message loop. I'm working on an existing application that I don't have time to port to cocoa.Wrongheaded
-psn_0_5100765 looks like a ProcessSerialNumber, which is an older (pre-Carbon era) Mac equivalent of a process ID (with caveats.) I suspect 0 is the high long of the PSN, and 5100765 is the low long. It's presumably the PSN of the calling Chrome tab.Vistula
That appears to be it, though it's present in the Mozilla source, not the Chromium source.Vistula
W
0

So I have some code using ReceiveNextEvent:

    while
    (
        ReceiveNextEvent
        (
            0,
            NULL,
            0.001, // kEventDurationForever,
            kEventRemoveFromQueue,
            &theEvent
        )
        ==
        noErr
    )
    {
        SendEventToEventTarget(theEvent, theTarget);
        ReleaseEvent(theEvent);
    }   

That is called a number of times during application startup. What is happening is the processing of these events is not taking into account the need to call AEProcessEvent for kEventAppleEvent events. This is done automatically inside RunApplicationEventLoop, but you have to do it manually if you use a ReceiveNextEvent loop. So I've added that to my loop like this:

    while
    (
        ReceiveNextEvent
        (
            0,
            NULL,
            0.001, // kEventDurationForever,
            kEventRemoveFromQueue,
            &theEvent
        )
        ==
        noErr
    )
    {
        if (GetEventKind(theEvent) == kEventAppleEvent)
            AEProcessEvent(theEvent);

        SendEventToEventTarget(theEvent, theTarget);
        ReleaseEvent(theEvent);
    }   

And now it works at start up AND during run time.

Uli Kusterer was responsible for pointing me in the right direction. So many thanks to him.

Wrongheaded answered 8/7, 2016 at 2:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.