[osx] Allow the user to configure a NSApplication subclass and use that instead.

Fixes http://hipbyte.myjetbrains.com/youtrack/issue/RM-539
This commit is contained in:
Eloy Durán
2014-08-05 14:39:15 +02:00
parent bd1e6196c9
commit 14fdc05f0e
2 changed files with 19 additions and 3 deletions

View File

@@ -230,20 +230,36 @@ EOS
end
main_txt << <<EOS
RubyMotionInit(argc, argv);
NSApplication *app = [NSApplication sharedApplication];
NSApplication *app = [NSClassFromString(@"#{info_plist['NSPrincipalClass']}") sharedApplication];
[app setDelegate:[NSClassFromString(@"#{delegate_class}") new]];
EOS
if spec_mode
main_txt << "SpecLauncher *specLauncher = [[SpecLauncher alloc] init];\n"
main_txt << "[[NSNotificationCenter defaultCenter] addObserver:specLauncher selector:@selector(appLaunched:) name:NSApplicationDidFinishLaunchingNotification object:nil];\n"
end
if use_application_main_function?
main_txt << "NSApplicationMain(argc, (const char **)argv);\n"
else
main_txt << "[app run];\n"
end
main_txt << <<EOS
NSApplicationMain(argc, (const char **)argv);
[pool release];
rb_exit(0);
return 0;
}
EOS
end
# If the user specifies a custom principal class the NSApplicationMain()
# function will only work if they have also specified a nib or storyboard.
def use_application_main_function?
info = info_plist
if info['NSPrincipalClass'] == 'NSApplication'
true
else
files = info.values_at('NSMainNibFile', 'NSMainStoryboardFile').compact
files.any? { |file| !file.strip.empty? }
end
end
end
end; end

View File

@@ -255,7 +255,7 @@ describe "NSNotFound" do
end
describe "Application singleton subclassing" do
xit "registers the principal class" do
it "registers the principal class" do
app = (ios? ? UIApplication : NSApplication).sharedApplication
app.class.should == ApplicationSubclass
end