Re: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
Re: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
- Subject: Re: [SOLVED] How to identify the host app is Carbon or Cocoa in a context menu plugin.
- From: Rosyna <email@hidden>
- Date: Fri, 7 Jul 2006 09:23:44 -0700
This will not work. Some carbon apps have inserted these keys into
their info.plist because they thought it was necessary.
You should never actually have to do this unless you have a really,
really, really, really, really good reason. I *have* to do it due to
the way utility windows differ in behaviour between carbon and cocoa
apps. Their cocoa behaviour is screwy as hell and I have to work
around the screwiness. I am talking carbon in cocoa here, not the
cocoa utility windows.
If you *actually* have a legit reason, you can, however, call
ProcessInformationCopyDictionary to get the flavor. However, the
documentation in Processes.h has the values mislabeled (it says 4 is
cocoa, but 3 is). Note that the carbon runtime can be started in a
cocoa app and vice versa at any time. The code below only
identificates the runloop as it was first started in the application.
enum {
kProcessCarbon=2,
kProcessCocoa=3,
};
SInt32 Li_GetApplicationFlavor(void)
{
static SInt32 processFlavor=0;
if (!processFlavor)
{
OSStatus err=noErr;
ProcessSerialNumber psn;
err=GetCurrentProcess(&psn);
if (!err)
{
CFDictionaryRef
processInfo=ProcessInformationCopyDictionary(&psn,
kProcessDictionaryIncludeAllInformationMask);
if (processInfo)
{
CFNumberRef
flavaFlav=CFDictionaryGetValue(processInfo, CFSTR("Flavor"));
if (flavaFlav)
CFNumberGetValue(flavaFlav, kCFNumberSInt32Type,
&processFlavor);
CFRelease(processInfo);
}
}
}
return processFlavor;
}
Ack, at 7/7/06, Satoshi Matsumoto said:
I have noticed the only Cocoa apps have "NSPrincipalClass" and
"NSMainNibFile" in its info-plist file.
This is my answer how to identifies the host app is Cocoa or not.
BOOL isHostACocoaApp()
{
NSAutoreleasePool *localPool;
BOOL ret = NO;
localPool = [[NSAutoreleasePool alloc] init];
if( NSApp == nil ) ret = NO;
else
{
NSBundle *bundle = [NSBundle mainBundle];
if( bundle )
{
NSDictionary *plist = [bundle infoDictionary];
NSString* primaryClass = [plist
objectForKey:@"NSPrincipalClass"];
NSString* mainNibFile = [plist objectForKey:@"NSMainNibFile"];
if (primaryClass && [primaryClass length] > 0 && mainNibFile &&
[mainNibFile length] > 0) ret =YES;
}
}
[localPool release];
return ret;
}
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden