Skip to content

Commit 26ef091

Browse files
committed
(nut-tree/nut.js#505) Adapt changes from bolt to libnut screengrab implementation
1 parent 907f028 commit 26ef091

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/macos/highlightwindow.m

+17-13
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
#import <Cocoa/Cocoa.h>
33

44
void showHighlightWindow(int32_t x, int32_t y, int32_t width, int32_t height, long duration, float opacity) {
5-
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
5+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
66
[NSApplication sharedApplication];
7-
7+
bool appIsRunning = [NSApp isRunning];
88
NSRect mainScreenFrameRect = [[NSScreen mainScreen] frame];
99
CGFloat screenHeight = mainScreenFrameRect.size.height;
1010
NSRect frame = NSMakeRect(x, screenHeight - y - height, width, height);
1111
NSUInteger styleMask = NSWindowStyleMaskBorderless;
12-
NSWindow * window = [[[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease];
12+
NSWindow *window = [[[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease];
1313
[window setBackgroundColor:[NSColor redColor]];
1414
[window setAlphaValue:opacity];
1515
[window orderFrontRegardless];
1616

17-
[NSTimer scheduledTimerWithTimeInterval: duration / 1000.0
18-
repeats: NO
19-
block: ^(NSTimer * timer){
20-
[NSApp stop:0];
21-
NSRect f = [window frame];
22-
f.size = CGSizeMake(0, 0);
23-
[window setFrame: f display: YES animate: NO];
24-
}];
25-
[NSApp run];
17+
[NSTimer scheduledTimerWithTimeInterval:duration / 1000.0
18+
repeats:NO
19+
block:^(NSTimer *timer) {
20+
if (!appIsRunning) {
21+
[NSApp stop:nil];
22+
}
23+
NSRect f = [window frame];
24+
f.size = CGSizeMake(0, 0);
25+
[window setFrame:f display:YES animate:NO];
26+
}];
27+
if (!appIsRunning) {
28+
[NSApp run];
29+
}
2630
[pool release];
27-
}
31+
}

0 commit comments

Comments
 (0)