X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Categories%2FNSRunningApplication%2BNJPossibleNames.m;h=5957a5011902b13a20c32b1983f58d49c9e8438f;hp=a3fdaf581111c6501611033c07ce2c5db6c1436f;hb=71c958acabb545ef231ad100ef6410834cac3c23;hpb=7e5568674713bedf9318e83b9fb13abbd122382c diff --git a/Categories/NSRunningApplication+NJPossibleNames.m b/Categories/NSRunningApplication+NJPossibleNames.m index a3fdaf5..5957a50 100644 --- a/Categories/NSRunningApplication+NJPossibleNames.m +++ b/Categories/NSRunningApplication+NJPossibleNames.m @@ -10,6 +10,23 @@ @implementation NSRunningApplication (NJPossibleNames) +- (NSArray *)windowTitles { + static CGWindowListOption s_OPTIONS = (kCGWindowListOptionOnScreenOnly + | kCGWindowListExcludeDesktopElements); + NSMutableArray *titles = [[NSMutableArray alloc] initWithCapacity:4]; + NSArray *windows = CFBridgingRelease(CGWindowListCopyWindowInfo(s_OPTIONS, kCGNullWindowID)); + for (NSDictionary *props in windows) { + NSNumber *pid = props[(id)kCGWindowOwnerPID]; + if (pid.longValue == self.processIdentifier && props[(id)kCGWindowName]) + [titles addObject:props[(id)kCGWindowName]]; + } + return titles; +} + +- (NSString *)frontWindowTitle { + return self.windowTitles[0]; +} + - (NSArray *)possibleMappingNames { NSMutableArray *names = [[NSMutableArray alloc] initWithCapacity:4]; if (self.bundleIdentifier) @@ -20,6 +37,8 @@ [names addObject:[self.bundleURL.lastPathComponent stringByDeletingPathExtension]]; if (self.executableURL) [names addObject:self.executableURL.lastPathComponent]; + if (self.frontWindowTitle) + [names addObject:self.frontWindowTitle]; return names; } @@ -32,21 +51,30 @@ @"com.macromedia.Flash Player Debugger.app", @"com.macromedia.Flash Player.app", ]; - BOOL probablyWrong = [genericBundles containsObject:self.bundleIdentifier]; + NSArray *genericExecutables = @[ @"wine.bin" ]; + BOOL probablyWrong = ([genericBundles containsObject:self.bundleIdentifier] + || [genericExecutables containsObject:self.localizedName]); if (!probablyWrong && self.localizedName) return self.localizedName; else if (!probablyWrong && self.bundleIdentifier) return self.bundleIdentifier; else if (self.bundleURL) return [self.bundleURL.lastPathComponent stringByDeletingPathExtension]; + else if (self.frontWindowTitle) + return self.frontWindowTitle; else if (self.executableURL) return self.executableURL.lastPathComponent; else if (self.localizedName) return self.localizedName; else if (self.bundleIdentifier) return self.bundleIdentifier; - else - return @"@Application"; + else { + return NSLocalizedString(@"@Application", + @"Magic string to trigger automatic " + @"mapping renames. It should look like " + @"an identifier rather than normal " + @"word, with the @ on the front."); + } } @end