discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSWorkspace launchedApplications method


From: Matt Rice
Subject: NSWorkspace launchedApplications method
Date: Wed, 21 May 2003 03:01:29 -0700 (PDT)

here is a patch i figure we should probably discuss, 

it implements the launchedApplications method

Source/NSApplication.m: updated
NSWorkspaceDidTerminateApplicationNotification to have
the same userInfo as recently added to
NSWorkspaceDidLaunchApplicationNotification

Source/NSWorkspace.m: new method launchedApplications
returns an NSArray obtained from appinfod, new private
class _GWorkspaceAppInfo attempts to connect to
appinfod, if it cannot it looks in the defaults for
the key GSAutoLaunchAppinfod if this is set to YES it
attempts to launch appinfod, if this is set to NO it
creates an empty array which will be returned by
launchedApplications

Tools/GNUmakefile, Tools/GNUmakefile.preamble: added
appinfod

Tools/appinfod.m: collects NSWorkspace notifications
and adds/removes the userInfo to/from a NSMutableArray
which it regsters as a distributed object. the
userInfo contains a dictionary with the keys
NSApplicationName, NSApplicationPath,
NSApplicationProcessIdentifier

notes: it doesn't behave exactly like their's...
according to their release notes (1) they populate the
array with whatever userInfo dictionaries they get

they also handle WillLaunch..., which i'm imagining
would be missing ProcessIdentifier(s), haven't done
this yet..

http://developer.apple.com/techpubs/macosx/ReleaseNotes/AppKit.html

matt

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
? launchedApplications.diff
? ColorPickers/StandardPicker.bundle
? ColorPickers/WheelPicker.bundle
? ColorPickers/shared_obj
? Source/.NSPasteboard.m.swp
? Source/launchedApplications.diff
? Tools/appinfod.m
Index: Headers/gnustep/gui/NSWorkspace.h
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/gnustep/gui/NSWorkspace.h,v
retrieving revision 1.15
diff -u -r1.15 NSWorkspace.h
--- Headers/gnustep/gui/NSWorkspace.h   11 May 2003 18:22:54 -0000      1.15
+++ Headers/gnustep/gui/NSWorkspace.h   21 May 2003 08:16:57 -0000
@@ -47,6 +47,7 @@
   NSMutableDictionary  *_iconMap;
   NSMutableDictionary  *_launched;
   NSNotificationCenter *_workspaceCenter;
+  id                    _workspaceAppInfo;
   BOOL                 _fileSystemChanged;
   BOOL                 _userDefaultsChanged;
 }
@@ -127,6 +128,13 @@
 - (BOOL) launchApplication: (NSString*)appName
                  showIcon: (BOOL)showIcon
                autolaunch: (BOOL)autolaunch;
+
+//
+// Information about currently running Applications
+//
+#ifndef STRICT_OPENSTEP
+- (NSArray*) launchedApplications;
+#endif
 
 //
 // Unmounting a Device 
Index: Source/NSApplication.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSApplication.m,v
retrieving revision 1.241
diff -u -r1.241 NSApplication.m
--- Source/NSApplication.m      11 May 2003 14:49:11 -0000      1.241
+++ Source/NSApplication.m      21 May 2003 08:17:01 -0000
@@ -2377,9 +2377,13 @@
       [[NSUserDefaults standardUserDefaults] synchronize];
 
       /* Tell the Workspace that we really did terminate.  */
-      userInfo = [NSDictionary dictionaryWithObject:
-       [[NSProcessInfo processInfo] processName] forKey: 
-                                @"NSApplicationName"];
+      userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+       [[NSProcessInfo processInfo] processName], @"NSApplicationName",
+       [[NSBundle mainBundle] bundlePath],        @"NSApplicationPath",
+       [NSNumber numberWithInt: [[NSProcessInfo processInfo] 
processIdentifier]],
+                                              @"NSApplicationProcessIdentifier"
+       ,nil];
+
       [[workspace notificationCenter]
         postNotificationName: NSWorkspaceDidTerminateApplicationNotification
                      object: workspace
Index: Source/NSWorkspace.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWorkspace.m,v
retrieving revision 1.66
diff -u -r1.66 NSWorkspace.m
--- Source/NSWorkspace.m        11 May 2003 14:41:32 -0000      1.66
+++ Source/NSWorkspace.m        21 May 2003 08:17:02 -0000
@@ -66,6 +66,8 @@
 
 static NSString        *GSWorkspaceNotification = @"GSWorkspaceNotification";
 
+static NSString *launchCmd = nil;
+
 @interface     _GSWorkspaceCenter: NSNotificationCenter
 {
   NSDistributedNotificationCenter      *remote;
@@ -176,6 +178,62 @@
 
 
 
+@interface      _GWorkspaceAppInfo : NSObject
+{
+  id                                    _launchedApplications;
+}
+- (NSArray*) _launchedApplications;
+@end
+
+@implementation _GWorkspaceAppInfo
+
+-(id) init 
+{
+  if ((self = [super init]))
+  {
+      _launchedApplications = [NSConnection
+        rootProxyForConnectionWithRegisteredName: @"appinfod"
+                                           host: nil];
+  
+    if (!_launchedApplications)
+    {
+      NSUserDefaults         *defs = [NSUserDefaults standardUserDefaults];
+                           
+       if ([defs boolForKey: @"GSAutoLaunchAppinfod"])
+       {
+         launchCmd = [[NSSearchPathForDirectoriesInDomains(
+          GSToolsDirectory, NSSystemDomainMask, YES) objectAtIndex: 0]
+          stringByAppendingPathComponent: @"appinfod"];
+                                                                               
+         [NSTask launchedTaskWithLaunchPath: launchCmd arguments: nil];
+
+         _launchedApplications = [NSConnection
+           rootProxyForConnectionWithRegisteredName: @"appinfod"
+                                               host: nil];
+       }
+       else
+       {
+         _launchedApplications = [NSArray new]; // an empty array.
+       }
+    }
+    RETAIN(_launchedApplications);
+  }
+
+  return self;
+}
+
+- (NSArray*) _launchedApplications
+{
+  return _launchedApplications;
+} 
+
+- (void) dealloc
+{
+  RELEASE(_launchedApplications);
+}
+
+@end
+
 @interface NSWorkspace (Private)
 
 // Icon handling
@@ -429,6 +487,7 @@
     object: nil];
 
   _workspaceCenter = [_GSWorkspaceCenter new];
+  _workspaceAppInfo = [_GWorkspaceAppInfo new];
   _iconMap = [NSMutableDictionary new];
   _launched = [NSMutableDictionary new];
   if (applications == nil)
@@ -1117,6 +1176,16 @@
     }
 
   return YES;
+}
+
+/* 
+ * if the Defaults GSAutoLaunchAppinfod is YES or appinfod is running
+ * launchedApplications returns an array of dictionaries with information 
about currently running applications
+ * otherwise it returns an empty array
+ */
+-(NSArray *) launchedApplications
+{
+  return [_workspaceAppInfo _launchedApplications];
 }
 
 /*
Index: Tools/GNUmakefile
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Tools/GNUmakefile,v
retrieving revision 1.23
diff -u -r1.23 GNUmakefile
--- Tools/GNUmakefile   28 Apr 2003 02:33:10 -0000      1.23
+++ Tools/GNUmakefile   21 May 2003 08:17:03 -0000
@@ -29,7 +29,7 @@
 include ../Version
 
 SUBPROJECTS = $(BUILD_GSND)
-TOOL_NAME = make_services set_show_service gopen
+TOOL_NAME = make_services set_show_service gopen appinfod
 SERVICE_NAME = example GSspell
 
 # The source files to be compiled
@@ -42,6 +42,8 @@
 example_OBJC_FILES = example.m 
 
 GSspell_OBJC_FILES = GSspell.m
+
+appinfod_OBJC_FILES = appinfod.m
 
 include GNUmakefile.preamble
 
Index: Tools/GNUmakefile.preamble
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Tools/GNUmakefile.preamble,v
retrieving revision 1.3
diff -u -r1.3 GNUmakefile.preamble
--- Tools/GNUmakefile.preamble  18 Nov 2001 19:01:07 -0000      1.3
+++ Tools/GNUmakefile.preamble  21 May 2003 08:17:03 -0000
@@ -33,6 +33,7 @@
 gpbs_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
 set_show_service_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
 gopen_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
+appinfod_TOOL_LIBS += -lgnustep-gui $(SYSTEM_LIBS)
 
 # Additional libraries when linking applications
 # ADDITIONAL_GUI_LIBS +=

Attachment: appinfod.m
Description: appinfod.m


reply via email to

[Prev in Thread] Current Thread [Next in Thread]