mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
Quit all running instances of an application
This commit is contained in:
1 parent
af7952b773
commit
ad10096156
3 files changed
+15
-5
No files matched your search
Vendored
+2
@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
+ (NSImage *)bestIconForBundle:(NSBundle *)bundle;
|
||||
|
||||
+ (NSArray<NSRunningApplication *> *)runningApplicationsWithBundle:(NSBundle *)bundle;
|
||||
|
||||
+ (NSRunningApplication * _Nullable)runningApplicationWithBundle:(NSBundle *)bundle;
|
||||
|
||||
@end
|
||||
|
||||
Vendored
+11
-3
@@ -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
|
||||
Vendored
+2
-2
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user