discuss-gnustep
[Top][All Lists]
Advanced

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

NSWorkspace fix


From: Andreas Höschler
Subject: NSWorkspace fix
Date: Fri, 3 Aug 2007 01:50:48 +0200

Hi all,

a fix for NSWorkspace (one reason why Etoile did not work for me):

- (NSArray *)launchedApplications
{
  NSArray *apps = nil;

   NS_DURING
     {
        id app;
        if ((app = [self _workspaceApplication]) != nil)
          {
           apps = [app launchedApplications];
          }
     }
  NS_HANDLER
    {
      // workspace manager problem ... fall through to default code
    }
  NS_ENDHANDLER
  if (apps == nil)
    {
      static NSDate *lastCheck = nil;
      unsigned      count;

      apps = GSLaunched(nil, NO);


if ([NSProcessInfo respondsToSelector: @selector(_exists:)] == YES)
        {
         /* Check and remove apps whose pid no loinger exists
         */
         count = [apps count]; // <------
         while (count-- > 0)
           {
            int       pid;
            NSString  *name;

            name = [[apps objectAtIndex:count]
                objectForKey: @"NSApplicationName"];
            pid = [[[apps objectAtIndex: count]
objectForKey: @"NSApplicationProcessIdentifier"] intValue];
            if (pid > 0 && [name length] > 0)
              {
               if ([NSProcessInfo _exists: pid] == NO)
                 {
                  NSMutableArray    *m = [apps mutableCopy];

                  GSLaunched([NSNotification notificationWithName:
                     NSWorkspaceDidTerminateApplicationNotification
                                                           object: self
userInfo: [NSDictionary dictionaryWithObject: name forKey: @"NSApplicationName"]], NO);

                  [m removeObjectAtIndex: count];
                  apps = AUTORELEASE(m);
                 }
              }
           }
        }

      /* If it's over 30 seconds since the last check ... try to contact
       * all launched applications to ensure that none have crashed.
       */
      if (lastCheck == nil || [lastCheck timeIntervalSinceNow] < -30.0)
        {
         ASSIGN(lastCheck, [NSDate date]);

         count = [apps count]; // <-------
         while (count-- > 0)
           {
            NSString  *name;

            name = [[apps objectAtIndex: count]
                objectForKey: @"NSApplicationName"];
            if (name != nil)
              {
               CREATE_AUTORELEASE_POOL(arp);
               BOOL  found = NO;

               if ([self _connectApplication: name alert: NO] != nil)
                 {
                  found = YES;
                 }
               RELEASE(arp);
               if (found == NO)
                 {
                  NSMutableArray    *m = [apps mutableCopy];

                  [m removeObjectAtIndex: count];
                  apps = AUTORELEASE(m);
                 }
              }
           }
        }
    }
  return apps;
}


Regards,

 Andreas





reply via email to

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