Quit all running instances of an application

This commit is contained in:
Zorg committed 2016-08-13 15:02:24 -04:00
1 parent af7952b773
commit ad10096156
3 files changed
+15 -5

No files matched your search

+2
View File
@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSImage *)bestIconForBundle:(NSBundle *)bundle;
+ (NSArray<NSRunningApplication *> *)runningApplicationsWithBundle:(NSBundle *)bundle;
+ (NSRunningApplication * _Nullable)runningApplicationWithBundle:(NSBundle *)bundle;
@end
+11 -3
View File
@@ -33,12 +33,14 @@
return icon;
}
+ (NSRunningApplication *)runningApplicationWithBundle:(NSBundle *)bundle
+ (NSArray<NSRunningApplication *> *)runningApplicationsWithBundle:(NSBundle *)bundle
{
// Resolve symlinks otherwise when we compare file paths, we may not realize two paths that are represented differently are the same
NSArray<NSString *> *bundlePathComponents = bundle.bundlePath.stringByResolvingSymlinksInPath.pathComponents;
NSString *bundleIdentifier = bundle.bundleIdentifier;
NSMutableArray<NSRunningApplication *> *matchedRunningApplications = [[NSMutableArray alloc] init];
if (bundleIdentifier != nil && bundlePathComponents != nil) {
NSArray *runningApplications =
(bundleIdentifier != nil) ?
@@ -49,11 +51,17 @@
// Comparing the URLs hasn't worked well for me in practice, so I'm comparing the file paths instead
NSString *candidatePath = runningApplication.bundleURL.URLByResolvingSymlinksInPath.path;
if (candidatePath != nil && [candidatePath.pathComponents isEqualToArray:bundlePathComponents]) {
return runningApplication;
[matchedRunningApplications addObject:runningApplication];
}
}
}
return nil;
return [matchedRunningApplications copy];
}
+ (NSRunningApplication *)runningApplicationWithBundle:(NSBundle *)bundle
{
return [[self runningApplicationsWithBundle:bundle] firstObject];
}
@end
+2 -2
View File
@@ -21,8 +21,8 @@
- (void)terminateApplicationForBundle:(NSBundle *)bundle
{
NSRunningApplication *runningApplication = [SPUApplicationInfo runningApplicationWithBundle:bundle];
if (runningApplication != nil) {
NSArray<NSRunningApplication *> *runningApplications = [SPUApplicationInfo runningApplicationsWithBundle:bundle];
for (NSRunningApplication *runningApplication in runningApplications) {
[runningApplication terminate];
}
}