@@ -16,28 +16,54 @@ @implementation Prisma
16
16
if (cxxBridge == nil ) {
17
17
return @false ;
18
18
}
19
-
19
+
20
20
auto jsiRuntime = (facebook::jsi::Runtime *)cxxBridge.runtime ;
21
21
if (jsiRuntime == nil ) {
22
22
return @false ;
23
23
}
24
24
auto &runtime = *jsiRuntime;
25
25
auto callInvoker = _bridge.jsCallInvoker ;
26
-
26
+
27
27
// get migrations folder
28
- auto bundleURL = NSBundle .mainBundle .bundleURL ;
29
- auto migrations_path_absolute = [NSString stringWithFormat: @" %@%@ " , bundleURL.absoluteString, @" migrations" ];
28
+ NSURL *bundleURL = NSBundle .mainBundle .bundleURL ;
29
+ #if TARGET_OS_MACCATALYST
30
+ NSString *migrations_path_absolute = [bundleURL.path stringByAppendingPathComponent: @" Contents/Resources/migrations" ];
31
+ NSString *identifier = [[NSBundle mainBundle ] bundleIdentifier ];
32
+
33
+ // @TODO Add better error handling and reporting
34
+ NSURL *applicationSupport = [[NSFileManager defaultManager ] URLForDirectory: NSApplicationSupportDirectory
35
+ inDomain: NSUserDomainMask
36
+ appropriateForURL: nil
37
+ create: YES
38
+ error: nil ];
39
+
40
+ NSString *libraryPathAbsolute = [applicationSupport.path stringByAppendingPathComponent: identifier];
41
+ NSString *libraryPath = [libraryPathAbsolute stringByReplacingOccurrencesOfString: @" file://" withString: @" " ];
42
+ // @TODO Add better error handling and reporting
43
+ BOOL success = [[NSFileManager defaultManager ] createDirectoryAtPath: libraryPath
44
+ withIntermediateDirectories: YES
45
+ attributes: nil
46
+ error: nil ];
47
+
48
+ if (!success) {
49
+ NSLog (@" Failed to create folder at %@ " , libraryPath);
50
+ }
51
+ #else
52
+ NSString *migrations_path_absolute = [bundleURL.path stringByAppendingPathComponent: @" migrations" ];
53
+ NSArray *paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSUserDomainMask, true );
54
+ NSString *libraryPath = [paths objectAtIndex: 0 ];
55
+ #endif
30
56
auto migrations_path = [migrations_path_absolute stringByReplacingOccurrencesOfString: @" file://" withString: @" " ];
31
-
57
+
32
58
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSUserDomainMask, true );
33
59
NSString *libraryPath = [paths objectAtIndex: 0 ];
34
-
60
+
35
61
#if DEBUG
36
62
std::cout << " ▲ NSHomeDirectory:\n " << [NSHomeDirectory () UTF8String ] << std::endl;
37
63
std::cout << " ▲ Library Path:\n " << [libraryPath UTF8String ] << std::endl;
38
64
std::cout << " ▲ Migrations Path:\n " << [migrations_path UTF8String ] << std::endl;
39
65
#endif
40
-
66
+
41
67
prisma::install_cxx (runtime, callInvoker, [libraryPath UTF8String ], [migrations_path UTF8String ]);
42
68
return nil ;
43
69
}
0 commit comments