Skip to content

Commit

Permalink
fix: don't run main method on init (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored Apr 21, 2022
1 parent ecbcaff commit 88cc3b7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion AppWithModules/Source Files/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ int main(int argc, char *argv[]) {
config.ArgumentsCount = argc;
config.Arguments = argv;

nativescript = [NativeScript alloc] initWithConfig: config];
nativescript = [[NativeScript alloc] initWithConfig: config];
[nativescript runMainApplication];

return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions NativeScript/NativeScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
@interface NativeScript : NSObject

- (instancetype)initWithConfig:(Config*)config;
/**
WARNING: this method does not return in most applications. (UIApplicationMain)
*/
- (void)runMainApplication;
- (bool)liveSync;

@end
14 changes: 8 additions & 6 deletions NativeScript/NativeScript.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ - (instancetype)initWithConfig:(Config*)config {
inspectorClient->registerModules();
inspectorClient->connect([config ArgumentsCount], [config Arguments]);
}

runtime_->RunMainScript();

CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);

tns::Tasks::Drain();
}

return self;

}

- (void)runMainApplication {
runtime_->RunMainScript();

CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);

tns::Tasks::Drain();
}

- (bool)liveSync {
if (runtime_ == nullptr) {
return false;
Expand Down
1 change: 1 addition & 0 deletions TestRunner/Source Files/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int main(int argc, char *argv[]) {
config.Arguments = argv;

nativescript = [[NativeScript alloc] initWithConfig:config];
[nativescript runMainApplication];

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions project-template/internal/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int main(int argc, char *argv[]) {
config.Arguments = argv;

nativescript = [[NativeScript alloc] initWithConfig:config];
[nativescript runMainApplication];

return 0;
}
Expand Down

0 comments on commit 88cc3b7

Please sign in to comment.