|
1
|
1 #include "shared.h"
|
|
|
2 #include "shared-apple.h"
|
|
|
3
|
|
|
4 #import <Cocoa/Cocoa.h>
|
|
|
5
|
|
|
6 bool uSetClipboardString(const char * str) {
|
|
|
7 @autoreleasepool {
|
|
|
8 @try {
|
|
|
9 NSPasteboard * pb = [NSPasteboard generalPasteboard];
|
|
|
10 [pb clearContents];
|
|
|
11 [pb setString: [NSString stringWithUTF8String: str] forType:NSPasteboardTypeString];
|
|
|
12 return true;
|
|
|
13 } @catch (NSException *) {
|
|
|
14
|
|
|
15 }
|
|
|
16 }
|
|
|
17 return false;
|
|
|
18 }
|
|
|
19
|
|
|
20 bool uGetClipboardString(pfc::string_base & out) {
|
|
|
21 bool rv = false;
|
|
|
22 @autoreleasepool {
|
|
|
23 NSPasteboard * pb = [NSPasteboard generalPasteboard];
|
|
|
24 NSString * str = [pb stringForType: NSPasteboardTypeString];
|
|
|
25 if ( str != nil ) {
|
|
|
26 out = str.UTF8String;
|
|
|
27 rv = true;
|
|
|
28 }
|
|
|
29 }
|
|
|
30 return rv;
|
|
|
31 }
|
|
|
32
|
|
|
33 static void wrapNoExcept(std::function<void()> f) noexcept {f();}
|
|
|
34
|
|
|
35 void fb2k::crashOnException(std::function<void()> f, const char * context) {
|
|
|
36 #if 0
|
|
|
37 auto fail = [context] ( const char * msg ) {
|
|
|
38 if (context) {
|
|
|
39 fb2k::crashWithMessage(pfc::format(context, ": ", msg));
|
|
|
40 } else {
|
|
|
41 fb2k::crashWithMessage(msg);
|
|
|
42 }
|
|
|
43 };
|
|
|
44 try {
|
|
|
45 @autoreleasepool {
|
|
|
46 @try {
|
|
|
47 f();
|
|
|
48 } @catch(NSException * e) {
|
|
|
49 auto header = pfc::format("NSException: ", e.name.UTF8String, " reason: ", e.reason.UTF8String );
|
|
|
50 uAddDebugEvent( header );
|
|
|
51 uAddDebugEvent("Stack:");
|
|
|
52 for(NSString * str in e.callStackSymbols ) {
|
|
|
53 uAddDebugEvent(str.UTF8String);
|
|
|
54 }
|
|
|
55 fail(header);
|
|
|
56 }
|
|
|
57 }
|
|
|
58 } catch(std::exception const & e) {
|
|
|
59 fail(pfc::format("C++ exception: ", e.what()));
|
|
|
60 } catch(...) {
|
|
|
61 fail("Invalid exception");
|
|
|
62 }
|
|
|
63 #else
|
|
|
64 wrapNoExcept(f);
|
|
|
65 #endif
|
|
|
66 }
|