-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathQSPasteboardMonitor.m
36 lines (25 loc) · 982 Bytes
/
QSPasteboardMonitor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "QSPasteboardMonitor.h"
@implementation QSPasteboardMonitor
+ (id)sharedInstance{
static QSPasteboardMonitor *_sharedInstance;
if (!_sharedInstance){
_sharedInstance = [[[self class] allocWithZone:nil] init];
}
return _sharedInstance;
}
- (id) init{
if (self=[super init]){
pollTimer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(checkPasteboard:) userInfo:nil repeats:YES];
lastChangeCount=0;
}
return self;
}
- (void)checkPasteboard:(NSTimer *)timer{
NSInteger changeCount = [[NSPasteboard generalPasteboard] changeCount];
if (changeCount==lastChangeCount) {
return;
}
lastChangeCount = changeCount;
[[NSNotificationCenter defaultCenter] postNotificationName:QSPasteboardDidChangeNotification object:@{@"Pasteboard" : [NSPasteboard generalPasteboard], @"ActiveApp" : [[NSWorkspace sharedWorkspace] frontmostApplication].bundleIdentifier}];
}
@end