forked from overtake/telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
558 changed files
with
22,833 additions
and
16,551 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface SPInvocationGrabber : NSObject { | ||
id _object; | ||
NSInvocation *_invocation; | ||
int frameCount; | ||
char **frameStrings; | ||
BOOL backgroundAfterForward; | ||
BOOL onMainAfterForward; | ||
BOOL waitUntilDone; | ||
} | ||
-(id)initWithObject:(id)obj; | ||
-(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack; | ||
@property (readonly, retain, nonatomic) id object; | ||
@property (readonly, retain, nonatomic) NSInvocation *invocation; | ||
@property BOOL backgroundAfterForward; | ||
@property BOOL onMainAfterForward; | ||
@property BOOL waitUntilDone; | ||
-(void)invoke; // will release object and invocation | ||
-(void)printBacktrace; | ||
-(void)saveBacktrace; | ||
@end | ||
|
||
@interface NSObject (SPInvocationGrabbing) | ||
-(id)grab; | ||
-(id)invokeAfter:(NSTimeInterval)delta; | ||
-(id)nextRunloop; | ||
-(id)inBackground; | ||
-(id)onMainAsync:(BOOL)async; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#import "NSObject+SPInvocationGrabbing.h" | ||
#import <execinfo.h> | ||
|
||
#pragma mark Invocation grabbing | ||
@interface SPInvocationGrabber () | ||
@property (readwrite, retain, nonatomic) id object; | ||
@property (readwrite, retain, nonatomic) NSInvocation *invocation; | ||
|
||
@end | ||
|
||
@implementation SPInvocationGrabber | ||
- (id)initWithObject:(id)obj; | ||
{ | ||
return [self initWithObject:obj stacktraceSaving:YES]; | ||
} | ||
|
||
-(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack; | ||
{ | ||
self.object = obj; | ||
|
||
if(saveStack) | ||
[self saveBacktrace]; | ||
|
||
return self; | ||
} | ||
-(void)dealloc; | ||
{ | ||
free(frameStrings); | ||
self.object = nil; | ||
self.invocation = nil; | ||
[super dealloc]; | ||
} | ||
@synthesize invocation = _invocation, object = _object; | ||
|
||
@synthesize backgroundAfterForward, onMainAfterForward, waitUntilDone; | ||
- (void)runInBackground; | ||
{ | ||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||
@try { | ||
[self invoke]; | ||
} | ||
@finally { | ||
[pool drain]; | ||
} | ||
} | ||
|
||
|
||
- (void)forwardInvocation:(NSInvocation *)anInvocation { | ||
[anInvocation retainArguments]; | ||
anInvocation.target = _object; | ||
self.invocation = anInvocation; | ||
|
||
if(backgroundAfterForward) | ||
[NSThread detachNewThreadSelector:@selector(runInBackground) toTarget:self withObject:nil]; | ||
else if(onMainAfterForward) | ||
[self performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:waitUntilDone]; | ||
} | ||
- (NSMethodSignature *)methodSignatureForSelector:(SEL)inSelector { | ||
NSMethodSignature *signature = [super methodSignatureForSelector:inSelector]; | ||
if (signature == NULL) | ||
signature = [_object methodSignatureForSelector:inSelector]; | ||
|
||
return signature; | ||
} | ||
|
||
- (void)invoke; | ||
{ | ||
|
||
@try { | ||
[_invocation invoke]; | ||
} | ||
@catch (NSException * e) { | ||
NSLog(@"SPInvocationGrabber's target raised %@:\n\t%@\nInvocation was originally scheduled at:", e.name, e); | ||
[self printBacktrace]; | ||
printf("\n"); | ||
[e raise]; | ||
} | ||
|
||
self.invocation = nil; | ||
self.object = nil; | ||
} | ||
|
||
-(void)saveBacktrace; | ||
{ | ||
void *backtraceFrames[128]; | ||
frameCount = backtrace(&backtraceFrames[0], 128); | ||
frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount); | ||
} | ||
-(void)printBacktrace; | ||
{ | ||
for(int x = 3; x < frameCount; x++) { | ||
if(frameStrings[x] == NULL) { break; } | ||
printf("%s\n", frameStrings[x]); | ||
} | ||
} | ||
@end | ||
|
||
@implementation NSObject (SPInvocationGrabbing) | ||
-(id)grab; | ||
{ | ||
return [[[SPInvocationGrabber alloc] initWithObject:self] autorelease]; | ||
} | ||
-(id)invokeAfter:(NSTimeInterval)delta; | ||
{ | ||
id grabber = [self grab]; | ||
[NSTimer scheduledTimerWithTimeInterval:delta target:grabber selector:@selector(invoke) userInfo:nil repeats:NO]; | ||
return grabber; | ||
} | ||
- (id)nextRunloop; | ||
{ | ||
return [self invokeAfter:0]; | ||
} | ||
-(id)inBackground; | ||
{ | ||
SPInvocationGrabber *grabber = [self grab]; | ||
grabber.backgroundAfterForward = YES; | ||
return grabber; | ||
} | ||
-(id)onMainAsync:(BOOL)async; | ||
{ | ||
SPInvocationGrabber *grabber = [self grab]; | ||
grabber.onMainAfterForward = YES; | ||
grabber.waitUntilDone = !async; | ||
return grabber; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <Cocoa/Cocoa.h> | ||
#import <IOKit/hidsystem/ev_keymap.h> | ||
#import <Carbon/Carbon.h> | ||
|
||
// http://overooped.com/post/2593597587/mediakeys | ||
|
||
#define SPSystemDefinedEventMediaKeys 8 | ||
|
||
@interface SPMediaKeyTap : NSObject { | ||
EventHandlerRef _app_switching_ref; | ||
EventHandlerRef _app_terminating_ref; | ||
CFMachPortRef _eventPort; | ||
CFRunLoopSourceRef _eventPortSource; | ||
CFRunLoopRef _tapThreadRL; | ||
BOOL _shouldInterceptMediaKeyEvents; | ||
id _delegate; | ||
// The app that is frontmost in this list owns media keys | ||
NSMutableArray *_mediaKeyAppList; | ||
} | ||
+ (NSArray*)defaultMediaKeyUserBundleIdentifiers; | ||
|
||
-(id)initWithDelegate:(id)delegate; | ||
|
||
+(BOOL)usesGlobalMediaKeyTap; | ||
-(void)startWatchingMediaKeys; | ||
-(void)stopWatchingMediaKeys; | ||
-(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event; | ||
@end | ||
|
||
@interface NSObject (SPMediaKeyTapDelegate) | ||
-(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event; | ||
@end | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern NSString *kMediaKeyUsingBundleIdentifiersDefaultsKey; | ||
extern NSString *kIgnoreMediaKeysDefaultsKey; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.