2
2
#import < Cocoa/Cocoa.h>
3
3
4
4
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 ];
6
6
[NSApplication sharedApplication ];
7
-
7
+ bool appIsRunning = [ NSApp isRunning ];
8
8
NSRect mainScreenFrameRect = [[NSScreen mainScreen ] frame ];
9
9
CGFloat screenHeight = mainScreenFrameRect.size .height ;
10
10
NSRect frame = NSMakeRect (x, screenHeight - y - height, width, height);
11
11
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 ];
13
13
[window setBackgroundColor: [NSColor redColor ]];
14
14
[window setAlphaValue: opacity];
15
15
[window orderFrontRegardless ];
16
16
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
+ }
26
30
[pool release ];
27
- }
31
+ }
0 commit comments