Re: The best way to determine if my app is already running
Re: The best way to determine if my app is already running
- Subject: Re: The best way to determine if my app is already running
- From: John Stiles <email@hidden>
- Date: Tue, 8 Jun 2004 11:41:14 -0700
Just following up with the list on the solution for this (for
posterity, the archives, etc.)
I ended up using Distributed Objects, which was shockingly easy. Carbon
desperately needs something like this. Obviously it can't be exactly
the same; a lot of the slickness of it is incredibly clever leveraging
of the Objective-C runtime. But it would be cool just to have some sort
of global registration mechanism to let apps shoot messages back and
forth without having to iterate the list of PSNs on the system or look
for certain bundle identifiers or something. (Maybe AppleEvents can
already do this...?? It seems that nobody knows how, though.)
- (oneway void) wakeUp
{
[NSApp activateIgnoringOtherApps:YES];
}
bool SwitchToAlreadyRunningInstance()
{
NSString *name = [NSString
stringWithUTF8String:PersonalityName().c_str()];
NSDistantObject *otherInstance = [NSConnection
rootProxyForConnectionWithRegisteredName:name
host:NULL];
if( otherInstance != NULL )
{
[otherInstance wakeUp]; // a warning that NSDistantObject can't
respond to wakeUp, do I need to cast?
return true;
}
NSConnection *theConnection = [NSConnection defaultConnection];
[theConnection setRootObject:s_myApp];
[theConnection registerName:name];
return false;
}
On Jun 4, 2004, at 3:36 PM, John Stiles wrote:
I have an app where its personality is largely data-driven--it can be
totally different to the end user based on data within the bundle. But
the code is all the same. Several copies of this app can be running
simultaneously.
I want to be able to detect if a certain personality of the app is
active, and then switch to it if it is. I can't base it on something
like bundle identifier or application signature, since like I was
saying, the code is always identical.
So what's the easiest way to register some global system property that
would allow me to connect an identifier (i.e., a product name
specified in my data) with a running app? So I could say "Is there a
personality Foo active?" and it could say, "Yes, and here is its
ProcessSerialNumber." I am open to either Carbon or Cocoa concepts (my
app is mostly Cocoa based, but I come from a long Carbon background).
I thought about registering an NSPasteboard with a custom name, but
that might stick around if my app is forcibly quit, and then I'd have
stale information. That might be OK (I can check if the
ProcessSerialNumber is no good).
In OS 9, I could have made a global Gestalt entry, but that's history.
Any ideas? Thanks :)
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.