@@ -20,48 +20,54 @@ @implementation Config
2020
2121@implementation NativeScript
2222
23- static std::shared_ptr<Runtime> runtime_;
24-
25- + (void )start : (Config*)config {
26- RuntimeConfig.BaseDir = [config.BaseDir UTF8String ];
27- if (config.ApplicationPath != nil ) {
28- RuntimeConfig.ApplicationPath = [[config.BaseDir stringByAppendingPathComponent: config.ApplicationPath] UTF8String ];
29- } else {
30- RuntimeConfig.ApplicationPath = [[config.BaseDir stringByAppendingPathComponent: @" app" ] UTF8String ];
23+ std::unique_ptr<Runtime> runtime_;
24+
25+ - (instancetype )initWithConfig : (Config*)config {
26+
27+ if (self = [super init ]) {
28+ RuntimeConfig.BaseDir = [config.BaseDir UTF8String ];
29+ if (config.ApplicationPath != nil ) {
30+ RuntimeConfig.ApplicationPath = [[config.BaseDir stringByAppendingPathComponent: config.ApplicationPath] UTF8String ];
31+ } else {
32+ RuntimeConfig.ApplicationPath = [[config.BaseDir stringByAppendingPathComponent: @" app" ] UTF8String ];
33+ }
34+ RuntimeConfig.MetadataPtr = [config MetadataPtr ];
35+ RuntimeConfig.IsDebug = [config IsDebug ];
36+ RuntimeConfig.LogToSystemConsole = [config LogToSystemConsole ];
37+
38+ Runtime::Initialize ();
39+ runtime_ = std::make_unique<Runtime>();
40+
41+ std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now ();
42+ Isolate* isolate = runtime_->CreateIsolate ();
43+ runtime_->Init (isolate);
44+ std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now ();
45+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count ();
46+ printf (" Runtime initialization took %llims\n " , duration);
47+
48+ if (config.IsDebug ) {
49+ Isolate::Scope isolate_scope (isolate);
50+ HandleScope handle_scope (isolate);
51+ v8_inspector::JsV8InspectorClient* inspectorClient = new v8_inspector::JsV8InspectorClient (runtime_.get ());
52+ inspectorClient->init ();
53+ inspectorClient->registerModules ();
54+ inspectorClient->connect ([config ArgumentsCount ], [config Arguments ]);
55+ }
56+
57+ runtime_->RunMainScript ();
58+
59+ CFRunLoopRunInMode (kCFRunLoopDefaultMode , 0 , true );
60+
61+ tns::Tasks::Drain ();
62+
63+ runtime_.reset ();
3164 }
32- RuntimeConfig.MetadataPtr = [config MetadataPtr ];
33- RuntimeConfig.IsDebug = [config IsDebug ];
34- RuntimeConfig.LogToSystemConsole = [config LogToSystemConsole ];
35-
36- Runtime::Initialize ();
37- runtime_ = std::make_shared<Runtime>();
38-
39- std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now ();
40- Isolate* isolate = runtime_->CreateIsolate ();
41- runtime_->Init (isolate);
42- std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now ();
43- auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count ();
44- printf (" Runtime initialization took %llims\n " , duration);
45-
46- if (config.IsDebug ) {
47- Isolate::Scope isolate_scope (isolate);
48- HandleScope handle_scope (isolate);
49- v8_inspector::JsV8InspectorClient* inspectorClient = new v8_inspector::JsV8InspectorClient (runtime_.get ());
50- inspectorClient->init ();
51- inspectorClient->registerModules ();
52- inspectorClient->connect ([config ArgumentsCount ], [config Arguments ]);
53- }
54-
55- runtime_->RunMainScript ();
56-
57- CFRunLoopRunInMode (kCFRunLoopDefaultMode , 0 , true );
58-
59- tns::Tasks::Drain ();
60-
61- runtime_.reset ();
65+
66+ return self;
67+
6268}
6369
64- + (bool )liveSync {
70+ - (bool )liveSync {
6571 if (runtime_ == nullptr ) {
6672 return false ;
6773 }
0 commit comments