Skip to content

Commit

Permalink
Simplify HSapplication:isFrontmost. It worked before, but always fail…
Browse files Browse the repository at this point in the history
…ed in tests. This seems to improve that
  • Loading branch information
cmsj committed Mar 3, 2021
1 parent 972a516 commit 24e0b05
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 0 additions & 2 deletions Hammerspoon Tests/HSapplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ - (void)testBasicAttributes {
// }

- (void)testFrontmostApplication {
SKIP_IN_TRAVIS()
SKIP_IN_GITHUB_ACTIONS()
RUN_LUA_TEST()
}

Expand Down
16 changes: 3 additions & 13 deletions Hammerspoon/HSuicore.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,10 @@ -(BOOL)setFrontmost:(BOOL)allWindows {
}

-(BOOL)isFrontmost {
CFTypeRef _isFrontmost;
NSNumber* isFrontmost = @NO;
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSRunningApplication *frontmostApp = workspace.frontmostApplication;

if (kAXErrorSuccess == AXUIElementCopyAttributeValue(self.elementRef,
(CFStringRef)NSAccessibilityFrontmostAttribute,
&_isFrontmost)) {
isFrontmost = (__bridge_transfer NSNumber *)_isFrontmost;
// } else {
// [LuaSkin logError:[NSString stringWithFormat:@"Unable to fetch element attribute NSAccessibilityFrontmostAttribute for: %@", [self.runningApp localizedName]]];
}

[LuaSkin logBreadcrumb:[NSString stringWithFormat:@"FRONTMOST: %@:%@:%@", self.title, isFrontmost, AXIsProcessTrusted() ? @"YES" : @"NO"]];

return isFrontmost.boolValue;
return frontmostApp == self.runningApp;
}

-(NSString *)title {
Expand Down

0 comments on commit 24e0b05

Please sign in to comment.